I'm trying to test output from a command line tool. How do I 'fake' a command line call with rspec? Doing the following doesn't work:
it "should call the command line and return 'text'" do
@p = Pig.new
@p.should_receive(:run).with('my_command_line_tool_call').and_return('result text')
end
How do I create that stub?
Using the new message expectation syntax:
spec/dummy_spec.rb
lib/dummy.rb
Alternative, you could just redefine the Kernel system method:
And the credit goes to this question: Mock system call in ruby
Here is a quick example I made. I call ls from my dummy class. Tested with rspec