Skip to content

Instantly share code, notes, and snippets.

@gilles-leblanc
Last active December 20, 2015 22:09
Show Gist options
  • Save gilles-leblanc/6202940 to your computer and use it in GitHub Desktop.
Save gilles-leblanc/6202940 to your computer and use it in GitHub Desktop.
Simple test to check behaviour of stubs defined with allow.
require_relative 'test_bidon'
describe TestBidon do
context 'when using stubs' do
before :each do
@exp = double('exp')
allow(@exp).to receive(:name).and_return('Gilles')
end
it 'is actually called' do
@exp.name.should == 'Gilles'
end
it 'should not return something else' do
@exp.name.should_not == 'Bob'
end
it 'is not called' do
puts '' # doing something else
end
end
context 'when using message expectations' do
before :each do
@exp = double('exp')
expect(@exp).to receive(:name).and_return('Gilles')
end
it 'is actually called' do
@exp.name.should == 'Gilles'
end
it 'should not return something else' do
@exp.name.should_not == 'Bob'
end
it 'is not called' do
puts '' # doing something else
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment