我是新的Rspec,刚开始在Rails 3上生成一个新的控制器。它默认生成一些Rspec测试。我有一个关于如何使它们通过的问题。按照目前的情况,我在终端“
中看到了这个测试1)BuildingsController GET'show' 应该是成功的
Failure/Error: get 'show' No route matches {:controller=>"buildings", :action=>"show"} # ./spec/controllers/buildings_controller_spec.rb:17:in `block (3 levels) in <top (required)>'
然而,我不明白它为什么会出现,因为我已经创建了这条路线(“资源:建筑物”),我跑了rake routes
并确保它在那里。
建立GET / buildings /:id(。:format){:action =&gt;“show”,:controller =&gt;“buildings”}
通过什么是必要的?这是顺便进行的测试:
describe "GET 'show'" do
it "should be successful" do
get 'show'
response.should be_success
end
end
答案 0 :(得分:38)
您需要传递现有建筑物的ID:get :show, :id => @building.id
路由抱怨它,因为:id
不是可选的。