-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
render_file match failures should show diff #869
Comments
Would be a nice feature, but not super high on my list. If someone wants to figure out how to hook in to the diff generators in RSpec itself, that would be cool though :) |
@atheiman looking into this a bit (though not enough to solve it properly) I discovered that the implementation of the If you look closely at the code sample in that link you'll see that the first line starts with With a little help from @coderanger yesterday I was able to find the implementation of It seems that the diff output is generated by I can put those two facts together however and do this in my spec: it 'renders the test.txt with the expected content' do
approved_file = 'test/fixtures/approved.txt'
expected_content = File.read(approved_file)
verifier = Proc.new do |rendered_content|
::RSpec::Expectations.fail_with "does not match approved #{approved_file}", expected_content, rendered_content unless false # content == expected_content
end
expect(chef_run).to render_file('/etc/test.txt').with_content(verifier)
end In my code I have extracted that into a helper modelled after @isidore's http://approvaltests.com/ framework so that my spec can look like this: it 'renders the test.txt with the expected content' do
verifier = Approvals.verifier_for('/etc/test.txt', 'test/fixtures/approved.txt')
expect(chef_run).to render_file('/etc/test.txt').with_content(verifier)
end |
is there a way to get diffs running on the render_file matcher in chefspec? Im having a hard time mapping what is described here https://relishapp.com/rspec/rspec-expectations/docs/custom-matchers/define-diffable-matcher to how render_file is defined here https://github.com/chefspec/chefspec/blob/master/lib/chefspec/matchers/render_file_matcher.rb
The text was updated successfully, but these errors were encountered: