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:
require "dummy"
describe Dummy do
it "command_line should call ls" do
d = Dummy.new
expect(d).to receive(:system).with("ls")
d.command_line
end
end
class Dummy
def command_line
system("ls")
end
end
Here is a quick example I made. I call ls from my dummy class. Tested with rspec
require "rubygems"
require "spec"
class Dummy
def command_line
system("ls")
end
end
describe Dummy do
it "command_line should call ls" do
d = Dummy.new
d.should_receive("system").with("ls")
d.command_line
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