我想測試一個Rails 3.1引擎與RSpec 2.經過大量的試驗和錯誤(和文檔和堆棧溢出搜索)該應用程序正在工作,我已經獲得最多的規格通過。問題是我的路線規格仍然失敗。測試Rails 3.1與RSpec 2引擎路由
對於發動機 「富」 與分離的命名空間和控制器的Foo :: BarsController,我有這樣的:
require "spec_helper"
describe Foo::BarsController do
describe "routing" do
it "routes to #index" do
get("/foo/bars").should route_to("bars#index")
end
it "routes to #new" do
get("/foo/bars/new").should route_to("bars#new")
end
end
end
這導致:
1) Foo::BarsController routing routes to #index
Failure/Error: get("/foo/bars").should route_to("bars#index")
ActionController::RoutingError:
No route matches "/foo/bars"
# ./spec/routing/foo/bars_routing_spec.rb:6:in `block (3 levels) in <top (required)>'
2) Foo::BarsController routing routes to #new
Failure/Error: get("/foo/bars/new").should route_to("bars#new")
ActionController::RoutingError:
No route matches "/foo/bars/new"
# ./spec/routing/foo/bars_routing_spec.rb:10:in `block (3 levels) in <top (required)>'
我的規格虛擬應用似乎設置正確:
Rails.application.routes.draw do
mount Foo::Engine => "/foo"
end
如果有助於回答這個問題,我的查看規格也是不工作。這裏是一個典型的錯誤:
9) foo/bars/index.html.erb renders a list of bars
Failure/Error: render
ActionView::Template::Error:
undefined local variable or method `new_bar_path' for #<#<Class:0x00000100c14958>:0x0000010464ceb8>
# ./app/views/foo/bars/index.html.erb:3:in `___sers_matt__ites_foo_app_views_foo_bars_index_html_erb___1743631507081160226_2184232780'
# ./spec/views/foo/bars/index.html.erb_spec.rb:12:in `block (2 levels) in <top (required)>'
任何想法?
似乎並沒有得以順利。 'ArgumentError:錯誤的參數個數(2代表1)' –
我認爲混淆來自這樣一個事實:在這個上下文中'get'是RSpec的'get'方法,而上面是Rails方法。 –