[rspec-users] mocking the shell command (Kernel module)

Joaquin Rivera Padron joahking at gmail.com
Sat Sep 13 08:41:10 EDT 2008


hi,
this did the trick:

  class Shell
    def self.sh command
      %{ command }
    end
  end

then I am able to:

it "should be mock alright" do

end

2008/9/13 Scott Taylor <mailing_lists at railsnewbie.com>

>
> On Sep 12, 2008, at 9:29 AM, Matt Wynne wrote:
>
>  On 12 Sep 2008, at 14:12, Joaquin Rivera Padron wrote:
>>
>>  what is the best (or any) way of mocking the running of shell commands?
>>>
>>> e.g.
>>> code like the following:
>>>
>>> def method
>>>  %{ ls }
>>> end
>>>
>>> spec:
>>>
>>> it "should list the directory contents"
>>>  shell = mock(Object) # %{} lives in Kernel module and its sugar for `
>>>  shell.should_receive(:`).with(:ls)
>>> end
>>>
>>> sorry about latter one, thanks in advance
>>> joaquin
>>>
>>
>> I suggest you put a 'seam' between your code and the call the Kernel.
>>
>
> That sounds like a good idea.  You can also Kernel#` directly (instead of
> `foo` call Kernel.send(:`, "foo").  This allows you to stub out Kernel#`.
>
> Scott
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080913/9f3b1c20/attachment.html>


More information about the rspec-users mailing list