我正在尝试使用 RSpec 2 测试 Rails 3.1 引擎。经过大量试验和错误(以及文档和堆栈溢出搜索)后,该应用程序正在运行,并且我已经通过了大部分规范。问题是我的路线规格仍然失败。
对于具有隔离命名空间和控制器 Foo::BarsController 的引擎“foo”,我有这个:
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)>'
有任何想法吗?