Ruby on rails RSpec包括所需的帮助
我试着模仿类似的东西 我通过了单元测试:Ruby on rails RSpec包括所需的帮助,ruby-on-rails,include,rspec,require,Ruby On Rails,Include,Rspec,Require,我试着模仿类似的东西 我通过了单元测试: 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 =>
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
但这导致:
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)>'
故障:
1) 图书特定路线应识别路径中的标题
失败/错误:{:get=>“book/mytitle”}。应将_路由到(:controller=>“book”,:action=>“index”,:title=>“mytitle”)
nil:NilClass的未定义方法'recognize_path'
#./spec/route_spec.rb:9:in'block(2层)in'
知道这个班是从哪里来的吗?任何帮助都将不胜感激。我猜匹配器需要在控制器规范中使用。它们应该已经存在,因此不需要手动包含它们。只要确保你描述的是一个控制器
describe BooksController do
it "should recognize title in path" do
# ...
end
end
导致失败的原因是
ActionDispatch::Assertions::RoutingAssertions
的双重包含——不确定原因。删除两个include
语句,所有语句都应该正常。spec文件应位于/spec/routing
中。对于样式点,您可以使用descripe BooksController
来包装示例,但如果没有它,它也可以工作
describe BooksController do
it "should recognize title in path" do
# ...
end
end