使用RSpec测试导轨金属/机架?
假设我有一个名为Preview的Metal类。 如何使用RSpec进行测试?
当我尝试:
require 'spec_helper' describe Preview do it "should return the posted content" do post "/preview", :content => "*title*" response.body.should == "*title*" end end
我明白了:
undefined method `post' for #
似乎RSpec没有加载:post
方法,如果测试没有显式为Controller。 我试过指定:type => :controller
无济于事。
rspec具有包含rails集成测试(通过机架)的集成规范。 只需将该规范放在./spec/integration/preview_spec.rb
中./spec/integration/preview_spec.rb
。
我认为最好用机架/测试进行测试
现在(rspec-rails 2.2.0和rails 3)你可以使用Request Specs来实现:
根据自述文件 :
请求规格/请求中的规格
[…]
请求规范混合了Rails集成测试的行为。 有关更多信息,请参阅ActionDispatch :: Integration :: Runner的文档。