I have a RSpec test like this:
context 'test #EnvironmentFile= method' do
it 'compares the command generated with the expected command' do
knife = EnvironmentFromFile.new(@knife_cfg_file)
knife.environment_file=(@environment_file)
expect(knife.chef_cmd_to_s).to eql("C:/blah/blah/bin/knife environment from file MySampleEnvironment.json --config 'knife.rb'")
end
end
Now, to avoid platform dependency, the expected message within the eql() should be a substring without the initial C:/blah/blah/bin/ part.
My expected message should be "knife environment from file MySampleEnvironment.json --config 'knife.rb'"
Which should match with the actual message returned from knife.chef_cmd_to_s method: "C:/blah/blah/bin/knife environment from file MySampleEnvironment.json --config 'knife.rb'"
How do I do that? What Rspec matcher is used for this?
This is where you would use the include
matcher (documentation).
context 'test #EnvironmentFile= method' do
it 'compares the command generated with the expected command' do
knife = EnvironmentFromFile.new(@knife_cfg_file)
knife.environment_file=(@environment_file)
expect(knife.chef_cmd_to_s).to include("knife environment from file MySampleEnvironment.json --config 'knife.rb'")
end
end
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