I am trying to write an Rspec test for my script that will pass if my script fails gracefully.
if options[:file] == false
abort 'Missing an argument'
end
Rspec:
it 'if the file argument is not given, it provides a helpful message' do
expect(`ruby example_file.rb`).to eq('Missing an argument')
end
My test continues to fail and says
expected: 'Missing an argument'
got: ''
I am not sure why it returns an empty string. I have looked at these posts with no luck:
- How can I validate exit value in rspec?
- How can I validate exits and aborts in RSpec?
- How to spec methods that exit or abort
If you need any more information about my script let me know. Thank you.