在将项目更新到Rspec 3之后,我在测试中得到了以下无法修复的奇怪错误:
 undefined method `empty?' for 2:Fixnum
 # /opt/local/lib/ruby2.1/gems/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:251:in `block in missing_keys'
 # /opt/local/lib/ruby2.1/gems/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:251:in `select'
 # /opt/local/lib/ruby2.1/gems/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:251:in `missing_keys'
 # /opt/local/lib/ruby2.1/gems/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:231:in `optimized_helper'
 # /opt/local/lib/ruby2.1/gems/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:220:in `call'
 # /opt/local/lib/ruby2.1/gems/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/routing/route_set.rb:345:in `block (2 levels) in define_url_helper'
 # ./app/controllers/users_controller.rb:10:in `block in <class:UsersController>'users_controller第10行包含重定向:
  redirect_to(user_path(current_user))在这些情况下,current_user都是使用mock_model(User, login: User.make_token)创建的模拟用户对象,其ID值引用在错误消息中(在“:Fixnum”之前)。
这发生在每个包含对象的重定向中。示例:
redirect_to current_user
redirect_to user_path(current_user)
redirect_to url_for([:admin, current_user, :edit])如果像在redirect_to user_path(current_user.id))中一样使用对象的ID,则不会发生错误。但是,例如url_for也会中断,因为我不能使用url_for([@parent.id, @object.id, :edit]) (对象不能仅从它们的I派生,而是路径所需)。
只有在使用带有RSpec 3和Rails 4.2.1的模拟对象时才会发生这种情况。任何帮助都将是非常感谢的,因为这使得许多测试现在失败。
发布于 2015-04-05 22:29:32
Rspec 3提取模拟支持进入gem,因此您可能需要将Gemfile添加到Gemfile中,以便路由帮助程序能够按照您的规范中所期望的那样运行。
https://stackoverflow.com/questions/29450980
复制相似问题