由于某些原因,我的测试中没有RSpec存根,也无法弄清楚原因。
这是一个示例测试:
RSpec.describe User, type: :model do
it "Should allow me to stub a model" do
u = User.new
u.stub(:test)
u.test
end
end
这是测试结果:
Failures:
1) Subscription Should allow me to stub a model
Failure/Error: u.stub(:test)
NoMethodError:
undefined method `stub' for #<User:0x007fa5cfea20c8>
# ./spec/models/user_spec.rb:6:in `block (2 levels)
in <top (required)>'
FWIW我的规范帮助文件的模拟配置部分如下:
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
可使用访问mocks.syntax = :should
旧语法。但是,您可以使用new:allow(u).to receive(:test)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句