Skip to content

Commit

Permalink
Don't override let definitions with argument matchers
Browse files Browse the repository at this point in the history
see #102

ArgumentMatchers (together with ExampleMethods) were
included into the ExampleGroup instance's metaclass.
This caused argument matcher methods such as boolean()
or hash_containing() to override let definitions with
the same name.

This commit fixes this bug by including
ArgumentMatchers into the example group's class and
not into the metaclass.
  • Loading branch information
Michi Huber authored and JonRowe committed Jul 26, 2013
1 parent 35cc006 commit 38377ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Enhancement:
* Allow the `have_received` matcher to use a block to set further expectations
on arguments. (Tim Cowlishaw)

Bug Fixes:

* ArgumentMatcher methods (e.g. `hash_containing`) no longer overwrite
`let`-definitions of the same name. (Michi Huber)

### 2.14.1 / 2013-07-07
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.0...v2.14.1)

Expand Down
4 changes: 1 addition & 3 deletions lib/rspec/mocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class << self
attr_accessor :space

def setup(host)
(class << host; self; end).class_exec do
include RSpec::Mocks::ExampleMethods
end
host.class.class_exec { include RSpec::Mocks::ExampleMethods }
self.space ||= RSpec::Mocks::Space.new
end

Expand Down
13 changes: 13 additions & 0 deletions spec/rspec/mocks/mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,19 @@ def add_call
end
end

describe "ArgumentMatchers not overriding let definitions" do
WithMatchers = Class.new { include RSpec::Mocks::ArgumentMatchers }
methods = WithMatchers.new.methods - Object.new.methods

methods.each do |method|
let(method) { :a_thing }

it "doesn't override a let named #{ method }" do
expect(send(method)).to be(:a_thing)
end
end
end

describe 'string representation generated by #to_s' do
it 'does not contain < because that might lead to invalid HTML in some situations' do
double = double("Dog")
Expand Down

0 comments on commit 38377ef

Please sign in to comment.