Skip to content

Commit

Permalink
Bugfix: make possible to use RSpec::Matchers#include inside a custom …
Browse files Browse the repository at this point in the history
…matcher

That bug was happening because RSpec::Matchers::DSL::Matcher has a
`include` private method that was overriding the `include` method
include from RSpec::Matchers.
  • Loading branch information
hugobarauna committed Jun 16, 2013
1 parent 54ef232 commit 4d78b97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rspec/matchers/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,15 @@ def method_missing(method, *args, &block)
end

def include(*args)
singleton_class.__send__(:include, *args)
if trying_to_include_a_module?(*args)
singleton_class.__send__(:include, *args)
else
BuiltIn::Include.new(*args)
end
end

def trying_to_include_a_module?(*args)
args.first.is_a?(Module)
end

def define_method(name, &block)
Expand Down
11 changes: 11 additions & 0 deletions spec/rspec/matchers/matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ def second_word
expect(matcher.matches?(8)).to be_true
end

it "has access to the built in include matcher" do
matcher = RSpec::Matchers::DSL::Matcher.new(:ignore) do |expected|
match do |actual|
extend RSpec::Matchers
expect(actual).to include(expected)
end
end.for_expected(3)

expect(matcher.matches?([1, 2, 3])).to be_true
end

context 'when multiple instances of the same matcher are used in the same example' do
RSpec::Matchers.define(:be_like_a) do |expected|
match { |actual| actual == expected }
Expand Down

0 comments on commit 4d78b97

Please sign in to comment.