【发布时间】:2019-04-17 22:32:49
【问题描述】:
我的规范运行没有问题,除非我尝试运行单个 it 块。在这种情况下,我会得到一个 Failure/Error: before(:context) 的解释:
在 rspec-mocks 之外使用双打或部分双打 不支持每个测试生命周期。使用来自 rspec-mocks 的
stub没有显式启用语法的旧:should语法是 已弃用。使用新的:expect语法或显式启用:should代替。
问题是我不使用rspec-mocks stub 方法,而是使用dry-container 定义的方法:
- https://dry-rb.org/gems/dry-container/testing/
- https://github.com/dry-rb/dry-container/blob/8fc95d0fe3a2f2c779bc4c3238265cb45353d245/lib/dry/container/stub.rb#L12
像这样:
require 'dry/container/stub'
before { FooContainer.enable_stubs! }
before(:context) { FooContainer.stub 'foo.key', stubbed_operation }
after(:context) { FooContainer.unstub 'foo.key' }
有没有办法在不启用旧的rspec-mocks 语法的情况下禁用此 RSpec 行为?
rspec --version
RSpec 3.8
- rspec-core 3.8.0
- rspec-expectations 3.8.2
- rspec-mocks 3.8.0
- rspec-rails 3.8.2
- rspec-support 3.8.0
rails -v
Rails 5.2.2.1
ruby -v
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
dry-container (0.6.0)
【问题讨论】:
-
这是最近开始的吗?你的 Gemfile.lock 改变了吗?
-
@lacostenycoder 我今天添加了有问题的代码,所以是的,它最近开始了,但与此同时我没有更改我的
Gemfile.lock。我用相关的 gem 版本编辑了我的问题。 -
这里有什么有用的吗? github.com/rspec/rspec-mocks/blob/…
-
@lacostenycoder 基本上是我不想更改的配置选项,因为我想在其他地方得到警告。我发现一种解决方法很困难,只需要一点性能。谢谢你的帮助!!
标签: ruby-on-rails ruby unit-testing rspec