0

Currently a I am build has the following two lines which I want to create a unit test for:

system @command.join(' ')
exit $?.exitstatus

Now I know I can do something like this:

Kernel.should_receive(:system).with()
Kernel.should_receive(:exit).with(0)

However when gem calls $?.exitstatus I've been unable to mock/stub this.

Does anyone know how to do this??

1 Answer 1

1

based on this

You should stub not Kernel, you should stub system from the current class.

for example

#user.rb
def self.my_test
  system('ls')
end

#test
User.should_receive(:system).and_return('aaa')
User.my_test # => 'aaa'

Do not forget to use stub for any_instance if it is called not in class scope

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Gave this ago and now it works as intended with the following, in my case anyhow: Cukesparse.should_receive(:system).with('test') Cukesparse.should_receive(:exit) Cheers, Jon

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.