首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更新到rspec3后测试中的奇怪错误

更新到rspec3后测试中的奇怪错误
EN

Stack Overflow用户
提问于 2015-04-04 20:14:20
回答 1查看 36关注 0票数 0

在将项目更新到Rspec 3之后,我在测试中得到了以下无法修复的奇怪错误:

代码语言:javascript
运行
复制
 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行包含重定向:

代码语言:javascript
运行
复制
  redirect_to(user_path(current_user))

在这些情况下,current_user都是使用mock_model(User, login: User.make_token)创建的模拟用户对象,其ID值引用在错误消息中(在“:Fixnum”之前)。

这发生在每个包含对象的重定向中。示例:

代码语言:javascript
运行
复制
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的模拟对象时才会发生这种情况。任何帮助都将是非常感谢的,因为这使得许多测试现在失败。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-05 22:29:32

Rspec 3提取模拟支持进入gem,因此您可能需要将Gemfile添加到Gemfile中,以便路由帮助程序能够按照您的规范中所期望的那样运行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29450980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档