如何解决测试人偶自定义函数 NoMethodError: 未定义方法 'check_file'
我有一个自定义的 Puppet 函数,它接受一个文件,检查文件的内容并根据内容返回一个哈希值:
Puppet::Functions.create_function(:check_file) do
dispatch :check_file do
param 'String',:file_path
end
def check_file(file_path)
data = Hash.new
...
...
return data
end
end
describe 'check_file' do
tempfile = Tempfile.new('dummy_file_name.txt')
tempfile.write('dummy_file_content')
expected_hash = {'abc' => 'def','ghi' => 'jkl'}
result = check_file('dummy_file_name.txt')
expect(result).to eq(expected_hash)
end
但我收到以下错误:
An error occurred while loading ./spec/functions/check_file_spec.rb.
Failure/Error: result = check_file('dummy_file_name.txt')
NoMethodError:
undefined method `check_file' for RSpec::ExampleGroups::CheckFile:Class
# ./spec/functions/check_file.rb:81:in `block in <top (required)>'
# ./spec/functions/check_file_spec.rb:74:in `<top (required)>'
No examples found.
Finished in 0.00002 seconds (files took 1.94 seconds to load)
0 examples,0 failures,1 error occurred outside of examples
知道为什么 rspec 无法找到我的方法吗?
目录结构为:
module/lib/puppet/functions/check_file.rb
module/spec/functions/check_file_spec.rb
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。