Permalink
Browse files

Fix method_missing so that we don't get StackOverflow error when RSpe…

…c::Matchers is included via config.include.
  • Loading branch information...
1 parent 80e5300 commit cedf51d344be6e72daf31403f3d0480a60bb37f5 @myronmarston myronmarston committed Mar 4, 2011
Showing with 19 additions and 6 deletions.
  1. +11 −6 lib/rspec/matchers/method_missing.rb
  2. +8 −0 spec/rspec/matchers/method_missing_spec.rb
@@ -21,15 +21,20 @@ module Matchers
# elegant, but it fixes the issue.
def self.included(base)
base.class_eval do
- alias_method :method_missing_without_rspec_matchers, :method_missing
- alias_method :method_missing, :method_missing_with_rspec_matchers
+ unless instance_methods.map { |m| m.to_s }.include?("method_missing_with_rspec_matchers")
+ include MethodMissing
+ alias_method :method_missing_without_rspec_matchers, :method_missing
+ alias_method :method_missing, :method_missing_with_rspec_matchers
+ end
end
end
- def method_missing_with_rspec_matchers(method, *args, &block) # :nodoc:
- return Matchers::BePredicate.new(method, *args, &block) if method.to_s =~ /^be_/
- return Matchers::Has.new(method, *args, &block) if method.to_s =~ /^have_/
- method_missing_without_rspec_matchers(method, *args, &block)
+ module MethodMissing
+ def method_missing_with_rspec_matchers(method, *args, &block) # :nodoc:
+ return Matchers::BePredicate.new(method, *args, &block) if method.to_s =~ /^be_/
+ return Matchers::Has.new(method, *args, &block) if method.to_s =~ /^have_/
+ method_missing_without_rspec_matchers(method, *args, &block)
+ end
end
end
end
@@ -1,5 +1,9 @@
require 'spec_helper'
+RSpec.configure do |c|
+ c.include RSpec::Matchers, :include_rspec_matchers_an_extra_time => true
+end
+
describe "method_missing" do
shared_examples_for "a well-behaved method_missing hook" do
it "allows undefined methods to raise errors as normal" do
@@ -18,4 +22,8 @@
include Module.new { include RSpec::Matchers }
it_behaves_like "a well-behaved method_missing hook"
end
+
+ context "when a group is configured to include RSpec::Matchers an extra time", :include_rspec_matchers_an_extra_time => true do
+ it_behaves_like "a well-behaved method_missing hook"
+ end
end

0 comments on commit cedf51d

Please sign in to comment.