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

Matt Wynne matt at mattwynne.net
Fri Sep 12 09:29:05 EDT 2008


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.

See Pat's excellent answer to a similar question in this thread:
http://www.ruby-forum.com/topic/164893#new

cheers,
Matt
----
http://blog.mattwynne.net
http://songkick.com

In case you wondered: The opinions expressed in this email are my own  
and do not necessarily reflect the views of any former, current or  
future employers of mine.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080912/8f958aee/attachment.html>


More information about the rspec-users mailing list