Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #718 from rspec/fix-verified-double-expiration
Verifying doubles should expire just like normal doubles.
- Loading branch information
Showing
7 changed files
with
108 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
module RSpec | ||
module Mocks | ||
RSpec.describe "After a test double has been torn down" do | ||
shared_examples_for "expiration" do | ||
before do | ||
expect(dbl).to receive(:foo).at_least(:once) | ||
allow(dbl).to receive(:bar) | ||
dbl.foo | ||
|
||
RSpec::Mocks.verify | ||
RSpec::Mocks.teardown | ||
RSpec::Mocks.setup | ||
end | ||
|
||
it 'disallows previously mocked methods' do | ||
expect { dbl.foo }.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
it 'disallows previously stubbed methods' do | ||
expect { dbl.bar }.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
it 'disallows stubbing new methods (with receive)' do | ||
expect { | ||
allow(dbl).to receive(:bazz) | ||
}.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
it 'disallows stubbing new methods (with receive_messages)' do | ||
expect { | ||
allow(dbl).to receive_messages(:bazz => 3) | ||
}.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
it 'disallows stubbing new message chains' do | ||
expect { | ||
allow(dbl).to receive_message_chain(:bazz, :bam, :goo) | ||
}.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
it 'disallows mocking new methods' do | ||
expect { | ||
expect(dbl).to receive(:bazz) | ||
}.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
it 'disallows being turned into a null object' do | ||
expect { dbl.as_null_object }.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
it 'disallows being checked for nullness' do | ||
expect { dbl.null_object? }.to raise_error(ExpiredTestDoubleError) | ||
end | ||
|
||
end | ||
|
||
context "for a plain double" do | ||
let(:dbl) { double } | ||
include_examples "expiration" | ||
end | ||
|
||
class ExpiredInstanceInterface | ||
def foo; end | ||
def bar; end | ||
def bazz; end | ||
end | ||
|
||
class ExpiredClassInterface | ||
def self.foo; end | ||
def self.bar; end | ||
def self.bazz; end | ||
end | ||
|
||
context "for an instance_double" do | ||
let(:dbl) { instance_double(ExpiredInstanceInterface) } | ||
include_examples "expiration" | ||
end | ||
|
||
context "for a class_double" do | ||
let(:dbl) { class_double(ExpiredClassInterface) } | ||
include_examples "expiration" | ||
end | ||
|
||
context "for an object_double" do | ||
let(:dbl) { object_double(ExpiredInstanceInterface.new) } | ||
include_examples "expiration" | ||
end | ||
end | ||
end | ||
end |