Skip to content

Instantly share code, notes, and snippets.

@niku
Created February 28, 2011 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niku/846724 to your computer and use it in GitHub Desktop.
Save niku/846724 to your computer and use it in GitHub Desktop.
How to mocking 'fork' method twice.
require 'rspec'
class Foo
def my_fork
fork do
p 'forked once'
end
end
def my_fork_double
fork do
p 'forked once'
fork do
p 'forked twice'
end
end
end
end
describe Foo do
subject{ Foo.new }
describe '#my_fork' do
it 'should call fork' do
# Foo.should_receive(:fork) # incorrect
subject.should_receive(:fork)
subject.my_fork
end
end
describe '#my_fork_double' do
subject{ Foo.new }
it 'should call fork twice' do
pending
subject.should_receive(:fork).twice # fail
subject.my_fork_double
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment