标签:ndis 模块 success 状态 gen view ica includes 异常
第 5 章 控制器测试
5.1基础
rails generate rspec:controller home
# be_success 检查响应的状态是成 功(200 响应)还是失败(例如 500 异常)。
expect(response).to have_http_status "200"
be_success匹配器 ,have_http_status()匹配器
5.2要验证身份的controller test
如果程序有Devise。测试的时候,需要身份验证,则使用Devise Test helpers
Devise includes some test helpers for controller and integration tests. In order to use them, you need to include the repective module in you test cases/specs.
包含一个测试模块.
class PostsControllerTest < ActionController::TestCase include Devise::Test::ControllerHelpers end
class PostsTests < ActionDispatch::IntegrationTest include Devise::Test::IntegrationHelpers end
RSpec.configure do |config| config.include Devise::Test::IntegrationHelpers, type: :feature
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
end
然后就可以使用sign_in, sign_out方法了
redirect_to 匹配器
以下测试都是get的测试。
redirects to the sign_in page
5.3 测试用户输入。
HTTP GET外,还有POST, PATCH, DELETE与controller交互。
Rspec: everyday-rspec实操。5:controller test(了解基础)
标签:ndis 模块 success 状态 gen view ica includes 异常
原文地址:https://www.cnblogs.com/chentianwei/p/9055336.html