【发布时间】:2011-05-17 23:40:41
【问题描述】:
我有一个单元测试通过了:
require 'test_helper'
class RoutesTest < ActionController::TestCase
test "book name is sent to store#index' do
assert_routing 'book/mytitle', {:controller => 'book', :action => 'index', :title => 'mytitle'}
end
end
我正在尝试将此转换为 RSpec 测试(在 Rails3.0.3 下运行 Rspec 2.2)
这是测试:
require 'spec_helper'
include RSpec::Rails::Matchers::RoutingMatchers
include ActionDispatch::Assertions::RoutingAssertions
describe "book specific routes" do
it "should recognize title in path" do
{:get => "book/mytitle"}.should route_to(:controller => "book", :action => "index", :title => "mytitle")
end
end
但这会导致:
Failures:
1) book specific routes should recognize title in path
Failure/Error: {:get => "book/mytitle"}.should route_to(:controller => "book", :action => "index", :title => "mytitle")
undefined method `recognize_path' for nil:NilClass
# ./spec/route_spec.rb:9:in `block (2 levels) in <top (required)>'
知道 nilClass 是从哪里来的吗?任何帮助将不胜感激。
【问题讨论】:
标签: ruby-on-rails include rspec require