Mocha 的 regexp_matches 有时会丢失
我很难从 Mocha 和 regexp_matches 方法。如果自动测试运行我的整个测试套件,则一切正常。如果我故意导致包含 regexp_matches
调用的测试失败,然后修复它,我会在 regexp_matches
上收到 method_missing
错误。如果我再次运行整个测试套件,一切都会很好。更大的问题来自 Hudson(持续集成)。它运行整个测试套件,但总是说 regexp_matches
丢失,我不知道如何修复它。
我的测试:
test "if token is set during Account creation the long url should be created correctly" do
Account.any_instance.expects(:http_get).with("api.server.com", regexp_matches(%r(^http://.*/accounts/\d+/jobs$)))
account = Account.create name: "New Account", token: "NewToken"
end
错误:
test_if_token_is_set_during_Account_creation_the_long_url_should_be_created_correctly(AccountTest):
NoMethodError: undefined method `regexp_matches' for #<AccountTest:0x0000010162d0c0>
test/unit/account_test.rb:158:in `block in <class:AccountTest>'
我什至不知道要在此处添加哪些其他代码,因为我无法想象原因是什么。为了咯咯笑,我在测试文件的顶部粘贴了 require 'mocha'
但这并没有改变任何东西。
I'm having a hard time getting any consistant behavior from Mocha and the regexp_matches method. If autotest runs my entire test suite everything works fine. If I purposely cause the test containing the regexp_matches
call to fail and then fix it I get a method_missing
error on regexp_matches
. If I then run the entire test suite again, everything is fine. The bigger problem is coming from Hudson (continuous integration). It runs the entire test suite but always says regexp_matches
is missing and I don't know how to fix it.
My test:
test "if token is set during Account creation the long url should be created correctly" do
Account.any_instance.expects(:http_get).with("api.server.com", regexp_matches(%r(^http://.*/accounts/\d+/jobs$)))
account = Account.create name: "New Account", token: "NewToken"
end
The error:
test_if_token_is_set_during_Account_creation_the_long_url_should_be_created_correctly(AccountTest):
NoMethodError: undefined method `regexp_matches' for #<AccountTest:0x0000010162d0c0>
test/unit/account_test.rb:158:in `block in <class:AccountTest>'
I don't even know what other code to add here as I can't imagine what the cause is. For giggles I pasted require 'mocha'
at the top of the test file but that didn't change anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在删除 Rails 项目时遇到了这个问题,
我这样做是为了运行规范不会加载整个 Rails 环境。这意味着必须需要或模拟外部依赖项。显然需要摩卡。
但即使在指定之后
我也遇到了相同的方法丢失问题。
最终,我通过直接包含参数匹配器模块解决了这个问题:
I ran into this problem on a rails project when removing
I did this so that running the spec would not load the whole rails environment. This means that external dependencies have to be required or mocked. Mocha obviously needs to be required.
But even after specifying
I ran into the same method missing issue.
Ultimately, I solved it by including the parameter matchers module directly: