如何发布到与测试脚本当前指向的控制器不同的控制器?
例子:
在 user_controller_spec.rb 中
it "should just post to users" do
post :create, @params # this goes to the users controller
end
我想做类似的事情:
it "should post to user and people to do some integration testing" do
post :create, @params # this goes to the users controller still
post 'people', :create, @params # this goes to the people controller
end
PS:我不想设置黄瓜
控制器规范是 Rails 功能测试的包装器,不支持多个请求或控制器。您想要的是 RSpec 请求规范 (rails 3) 或集成规范 (rails 2)。这些包装 Rails 集成测试,确实支持多个控制器的多个请求(甚至多个会话),但它们的工作方式与控制器规范略有不同。您必须使用完整路径(因此获取 new_thing_path),并且不能在控制器上存根任何内容(因为在发出请求之前没有控制器)。
See http://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec http://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec and http://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html http://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html了解更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)