CopyAndPaste

random programming notes

Mocking Backtick in RSpec

`cmd` is a method in Kernel.

However, simply mocking the Kernel object does not work. This is because Kernel is a module included by class Object, its methods are available in every Ruby object.

Instead of doing this:

1
2
3
Kernel.expects(:`).with(
  'unzip -d /tmp test.zip'
)

We should be doing this:

1
2
3
instance_of_current_object.expects(:`).with(
  'unzip -d /tmp test.zip'
)