Ruby:直接运行时规格通过,在 Guard 中运行时出现 TypeError

发布于 2024-12-25 14:59:58 字数 1672 浏览 3 评论 0原文

我正在更新一个 gem,以确保它可以与新版本的 bitly 和 rspec gem 一起使用,但我遇到了一个奇怪的问题。

当我运行 guard 以确保新 gem 通过所有测试时,我收到 TypeError;但是,如果我直接使用 rspec 运行测试套件,它们都会通过并且不会抛出错误。

如果您想查看整个 shebang,我的代码可以在 GitHub 上找到。

通过深入研究,我看到有人建议将类包装在其自己的模块中,以防止类名发生冲突,但由于它仅适用于 rspec,所以我希望我不会需要添加另一层。

这是类型错误:

/Users/jstim/Documents/Programming/Ruby/uncoil/lib/uncoil.rb:6:in '': Uncoil 不是一个类 (TypeError)
来自 /Users/jstim/Documents/Programming/Ruby/uncoil/spec/uncoil_spec.rb:1:in 'require_relative'
来自 /Users/jstim/Documents/Programming/Ruby/uncoil/spec/uncoil_spec.rb:1:in ''
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'load'
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'load_spec_files 中的块'
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'map'
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'load_spec_files'
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in 'run'
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in 'run_in_process'
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in 'run'
来自 /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in '自动运行中的块'

让我知道如果我可以添加额外的代码来提供帮助。谢谢!

I am updating a gem to make sure it works with the new versions of the bitly and rspec gems, and I have run into an odd issue.

When I run guard to make sure all the tests pass with the new gem, I get a TypeError; however, if I run my test suite directly with just rspec they all pass and do not throw the error.

My code is available on GitHub if you want to see the whole shebang.

From digging around, I've seen people suggesting to wrap the class inside of its own module to keep the class names from conflicting, but since it works fine with just rspec, I am hoping I don't need to add another layer.

Here's the TypeError:

/Users/jstim/Documents/Programming/Ruby/uncoil/lib/uncoil.rb:6:in '': Uncoil is not a class (TypeError)
from /Users/jstim/Documents/Programming/Ruby/uncoil/spec/uncoil_spec.rb:1:in 'require_relative'
from /Users/jstim/Documents/Programming/Ruby/uncoil/spec/uncoil_spec.rb:1:in ''
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'load'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'block in load_spec_files'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'map'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'load_spec_files'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in 'run'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in 'run_in_process'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in 'run'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in 'block in autorun'

Let me know if I can include additional code to help out. thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独陪着我 2025-01-01 14:59:58

问题是在“lib/uncoil”中,您定义了class Uncoil,但在“lib/uncoil/version”中您定义了module Uncoil。如果版本被加载,将会出现冲突,因为您试图重新打开一个实际上是模块的类(反之亦然,取决于首先加载哪个)。

我假设当你运行 rspec spec 时它根本不使用bundler(潜在的问题,顺便说一句,因为你的依赖项没有被管理,所以你应该始终执行bundle exec rspec spec),因此它永远不会加载 .gemspec,这是您需要版本文件的唯一位置。据推测,Bundler 加载了 gemspec,而 gemspec 又加载了版本文件,从而导致了冲突。
如果您以前没有遇到过这种情况,我猜您的依赖项之一(可能是guard-rspec)已更改为在新版本中加载Bundler。

您可以考虑在 gemspec 中指定依赖项的版本。

The problem is that in "lib/uncoil", you define class Uncoil but in "lib/uncoil/version" you define module Uncoil. If the version gets loaded, there will be a conflict in that you're trying to reopen a class that is actually a module (or vice versa, depending on which gets loaded first).

I assume that when you run rspec spec that it doesn't use bundler at all (potential problem, btw, as your dependencies aren't being managed, so you should always do bundle exec rspec spec), so it never loads the .gemspec, which is the only place you require the version file. Presumably Bundler loads the gemspecs, which in turn loads version file, causing the conflict.
If you didn't experience this before, I would guess that one of your dependencies (probably guard-rspec) was changed to load Bundler in the newer version.

You might consider specifying versions on the dependencies in the gemspec.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文