Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-expectations
...
head fork: rspec/rspec-expectations
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 04, 2011
@myronmarston myronmarston Fix method_missing so that we don't get StackOverflow error when RSpe…
…c::Matchers is included via config.include.
cedf51d
View
17 lib/rspec/matchers/method_missing.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
View
8 spec/rspec/matchers/method_missing_spec.rb
@@ -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

No commit comments for this range

Something went wrong with that request. Please try again.