Skip to content

Commit

Permalink
it { should matcher } delegates directly to ExpectationHandler.
Browse files Browse the repository at this point in the history
Not only is this cleaner, but it also makes it feasible to turn of the
global 'should' (see #119).
  • Loading branch information
dchelimsky committed Mar 16, 2012
1 parent 1e8c6e0 commit b93433d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/rspec/core/subject.rb
Expand Up @@ -36,9 +36,7 @@ def subject
end

begin
require 'rspec/expectations/extensions/kernel'
alias_method :__should_for_example_group__, :should
alias_method :__should_not_for_example_group__, :should_not
require 'rspec/expectations/handler'

# When +should+ is called with no explicit receiver, the call is
# delegated to the object returned by +subject+. Combined with
Expand All @@ -51,7 +49,7 @@ def subject
# it { should be_eligible_to_vote }
# end
def should(matcher=nil, message=nil)
self == subject ? self.__should_for_example_group__(matcher) : subject.should(matcher,message)
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(subject, matcher, message)
end

# Just like +should+, +should_not+ delegates to the subject (implicit or
Expand All @@ -63,7 +61,7 @@ def should(matcher=nil, message=nil)
# it { should_not be_eligible_to_vote }
# end
def should_not(matcher=nil, message=nil)
self == subject ? self.__should_not_for_example_group__(matcher) : subject.should_not(matcher,message)
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(subject, matcher, message)
end
rescue LoadError
end
Expand Down

1 comment on commit b93433d

@dchelimsky
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit comment is in reference to rspec/rspec-expectations#119 (not in rspec-core).

Please sign in to comment.