我正在尝试list
为类创建一个方法存根,Chef::DataBag
如下所示:
$ cat spec/spec_helper.rb
require "rspec"
RSpec.configure { |config|
config.mock_framework = :rspec
config.mock_with :rspec
}
$ cat spec/test_spec.rb
require "spec_helper"
require "chef"
RSpec.describe "test" do
describe "simple test" do
it "mocks chef databag" do
allow(Chef::DataBag).to recieve(:list).and_return {}
end
end
end
$ grep "rspec \|chef " Gemfile.lock | head -n 2
gem "chef", "11.16.4"
gem "rspec", "3.1.0"
执行时rspec
出现以下错误。
$ bundle exec rspec spec/test_spec.rb
F
Failures:
1) test simple test mocks chef databag
Failure/Error: allow(Chef::DataBag).to recieve(:list).and_return {}
NoMethodError:
undefined method `recieve' for #<RSpec::ExampleGroups::Test::SimpleTest:0x000000049964f8>
# ./spec/test_spec.rb:7:in `block (3 levels) in <top (required)>'
Finished in 0.00048 seconds (files took 0.53998 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/test_spec.rb:6 # test simple test mocks chef databag
这就是我验证Chef::DataBag
具有该list
方法的方式:
$ bundle exec ruby -e "require 'chef'; puts Chef::DataBag.methods" | grep list
list
你能指出什么是错的吗?