Permalink
Browse files

Revert "Prevent SystemStackError on 1.9 when users include RSpec::Mat…

…chers in an example group."

This reverts commit 80e5300.

This hack didn't work as well as I thought it would, and I have fixed
the underlying issue in rspec-core by including RSpec::Matchers before
the first example group is created.
  • Loading branch information...
1 parent 80e5300 commit 268f8c066c2aed25c0a3bba18066538f56e2299d @myronmarston myronmarston committed Mar 7, 2011
@@ -1,35 +1,12 @@
module RSpec
module Matchers
- private
- # Ruby 1.9 has a weird bug where you can get infinite recursion and a SystemStackError
- # under the following conditions:
- # * You have a module that defines a method that uses super
- # * You include that module in a subclass
- # * You include that module in the subclass's superclass _after_ it has already
- # been included in the subclass.
- # See https://gist.github.com/845896 for a demonstration of this bug.
- #
- # This manifested itself in RSpec with the method_missing hook below, because
- # rspec-core includes RSpec::Matchers in RSpec::Core::ExampleGroup right before
- # running all the examples (but after all the examples have been defined), so that
- # users can configure RSpec to use a different expectation/assertion framework if
- # they wish. If users included RSpec::Matchers in an example group, undefined method
- # calls would trigger this bug.
- #
- # Our work around is to use alias_method_chain rather than super. It's not as
- # 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
- end
- end
+ private
- def method_missing_with_rspec_matchers(method, *args, &block) # :nodoc:
+ def method_missing(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)
+ super
end
end
end
@@ -1,6 +1,10 @@
require 'spec_helper'
describe "should be_predicate" do
+ it "allows other undefined methods to raise errors as normal" do
+ expect { some_undefined_method }.to raise_error(NameError)
+ end
+
it "passes when actual returns true for :predicate?" do
actual = stub("actual", :happy? => true)
actual.should be_happy
@@ -1,21 +0,0 @@
-require 'spec_helper'
-
-describe "method_missing" do
- shared_examples_for "a well-behaved method_missing hook" do
- it "allows undefined methods to raise errors as normal" do
- expect { some_undefined_method }.to raise_error(NameError)
- end
- end
-
- it_behaves_like "a well-behaved method_missing hook"
-
- context "when RSpec::Matchers has been included in an example group" do
- include RSpec::Matchers
- it_behaves_like "a well-behaved method_missing hook"
- end
-
- context "when a module that includes RSpec::Matchers has been included in an example group" do
- include Module.new { include RSpec::Matchers }
- it_behaves_like "a well-behaved method_missing hook"
- end
-end

0 comments on commit 268f8c0

Please sign in to comment.