`dirname':无法将 nil 转换为字符串(类型错误)
我不确定这是否真的是黄瓜,但以防万一你们中的一些人知道如何解决这个问题。基本上,我的测试突然停止工作,当我检查时,它显示了这个错误:
C:/Vendor/Ruby187/lib/ruby/gems/1.8/gems/cucumber-rails-1.0.0/lib/cucumber/rails3.rb:3 in 'dirname': can't convert nil into String (TypeError)
是的,我首先翻了个白眼,只是咒骂 Windows,但我在 Mac 上尝试了它,得到了相同的结果:
/Users/eumir/.rvm/gems/ruby-1.8.7-p174@mygemset/gems/cucumber-rails-0.5.2/lib/cucumber/rails3.rb:3:in `dirname': can't convert nil into String (TypeError)
不过很奇怪,它有不同的 Cucumber Rails 版本,我用谷歌搜索,第一个结果显示这是bunder的错(虽然我无法破译要点是什么......也许只是复制粘贴的东西?)最奇怪的是,Cucumber正在运行,我在运行时遇到了这个问题rspec 规范
。
下面的3条线索指出这不是黄瓜的错,但它为什么要怪黄瓜呢?如果你们中的任何一个人能提供有关为什么会发生这种情况的线索,那么您将让我免于再遭受几个小时的痛苦。
I'm not sure if this is in cucumber really, but just in case some of you guys have a clue on how to fix this. Basically, my tests suddenly stopped working and when I checked, it showed this error:
C:/Vendor/Ruby187/lib/ruby/gems/1.8/gems/cucumber-rails-1.0.0/lib/cucumber/rails3.rb:3 in 'dirname': can't convert nil into String (TypeError)
Yes, I first rolled my eyes and just cursed Windows but I tried it on my Mac and I got the same:
/Users/eumir/.rvm/gems/ruby-1.8.7-p174@mygemset/gems/cucumber-rails-0.5.2/lib/cucumber/rails3.rb:3:in `dirname': can't convert nil into String (TypeError)
Weird though, its in different cucumber rails versions, I googled and the first result shows it is bunder's fault(although I can't decipher what the gist is about...maybe just copy pasted stuff?) and weirdest of all, Cucumber IS running and I run into this problem while running rspec spec
.
The 3 clues below point out that it's not cucumber's fault, but why does it blame cucumber? IF any of you can shed a clue as to why this is happening, you'll be saving me from a few more hours of pain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是由捆绑程序尝试“自动需要”gem 造成的。在 1.0 中,bundler 会尝试 gem 名称(在本例中为“cucumber-rails”),如果找不到文件(实际上没有找到),则会消除错误。
在捆绑器 1.1.1 中,捆绑器将“-”实例替换为“/”,导致它自动需要“cucumber/rails”,从而导致 Ewout 描述的“意外”加载。
要解决此问题,请设置
:require =>; false
在你的 gemfile 中。(注意:
:require => false
并不意味着 gem 是可选的,只是 Bundler 不应该自动需要它)This was caused by how bundler attempts to "autorequire" gems. In 1.0, bundler tries the gem name (in this case "cucumber-rails") and smothers the error if the file isn't found (it isn't).
In bundler 1.1.1, bundler replaces instances of "-" with "/", resulting in it autorequiring "cucumber/rails" which results in the "accidental" loading described by Ewout.
To resolve, set
:require => false
in your gemfile.(Note:
:require => false
doesn't mean that the gem is optional, just that Bundler shouldn't auto-require it)新的 Cucumber-rails 版本会警告您此问题。 Cucumber-rails 应该从 env.rb 文件中获取,而不是在之前由捆绑程序获取。为此,请将
gem cucumber-rails
行放入 Gemfile 中的 :test 组中。New cucumber-rails versions warn you about this problem. Cucumber-rails should be required from the env.rb file, and not before by bundler. To achieve that, put the
gem cucumber-rails
line in the group :test within your Gemfile.正如阿斯拉克在他的回复中所说:
http://groups.google.com/group/cukes/ msg/803836e9f6e7f1be
我只需要升级 cucumber-rails。 @Ewout 也给我指出了正确的方向,所以他也应该得到 +1 :)
As aslak says in his reply:
http://groups.google.com/group/cukes/msg/803836e9f6e7f1be
I just needed to upgrade cucumber-rails. @Ewout did point me in the right direction too so he also deserves a +1 :)