When learning chefspec I have found the below code:
describe 'example::default' do
let(:chef_run) do
ChefSpec::SoloRunner.new do |node|
node.set['cookbook']['attribute'] = 'hello'
end.converge(described_recipe)
end
end
The end invoke the method converge, I am some new to ruby and chefspec, and I have googled it much time and got no answer, can someone help to explain the syntax?
It's the same as:
x = ChefSpec::SoloRunner.new do |node|
node.set['cookbook']['attribute'] = 'hello'
end
x.converge(described_recipe)
The method converge
is called on the new ChefSpec::SoloRunner
object.
Have a look at the below example, of initializing an object with a block.
Array.new(4) { 5 }.length
# => 4
Array.new(4) do
5
end.length
# => 4
Array.new(4) do
5
end.class
# => Array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With