With a unit test like this:
let!(:vault_lookup) do
MockFunction.new('vault_lookup') do |f|
f.stubbed.returns('pwhash' => 'TEST_PASSWORD')
end
end
it { is_expected.to compile }
Using PDK to call Rspec, like so:
♠ pdk test unit
pdk (INFO): Using Ruby 2.7.8
pdk (INFO): Using Puppet 7.34.0
[✔] Preparing to run the unit tests.
/opt/puppetlabs/pdk/private/ruby/2.7.8/bin/ruby -I/Users/rbyrnes/.pdk/cache/ruby/2.7.0/gems/rspec-core-3.13.3/lib:/Users/rbyrnes/.pdk/cache/ruby/2.7.0/gems/rspec-support-3.13.2/lib /Users/rbyrnes/.pdk/cache/ruby/2.7.0/gems/rspec-core-3.13.3/exe/rspec --pattern spec/\{aliases,classes,defines,functions,hosts,integration,plans,tasks,type_aliases,types,unit\}/\*\*/\*_spec.rb --format progress
# snip
Results in errors like this one:
18) corebasic on oraclelinux-8-x86_64
Failure/Error: f.stubbed.returns('pwhash' => 'TEST_PASSWORD')
NoMethodError:
undefined method `stubs' for #<RSpecPuppetUtils::MockFunction:0x000000013fe9d500>
Did you mean? stub
# ./spec/classes/corebasic_spec.rb:15:in `block (5 levels) in <top (required)>'
# ./spec/classes/corebasic_spec.rb:14:in `new'
# ./spec/classes/corebasic_spec.rb:14:in `block (4 levels) in <top (required)>'
If we adjust the mock per the docs:
let!(:vault_lookup) do
MockFunction.new('vault_lookup') do |f|
f.stubbed('ansible').returns('pwhash' => 'TEST_PASSWORD')
end
end
it { is_expected.to compile }
We get this error:
18) corebasic on oraclelinux-8-x86_64
Failure/Error: f.stubbed('ansible').returns('pwhash' => 'TEST_PASSWORD')
ArgumentError:
wrong number of arguments (given 1, expected 0)
# ./spec/classes/corebasic_spec.rb:15:in `block (5 levels) in <top (required)>'
# ./spec/classes/corebasic_spec.rb:14:in `new'
# ./spec/classes/corebasic_spec.rb:14:in `block (4 levels) in <top (required)>'
With a unit test like this:
Using PDK to call Rspec, like so:
Results in errors like this one:
If we adjust the mock per the docs:
We get this error: