Module: Spec::Expectations::ObjectExpectations
- Included in:
- Object
- Defined in:
- lib/spec/expectations/extensions/object.rb
Overview
rspec adds #should and #should_not to every Object (and, implicitly, every Class).
Instance Method Summary collapse
-
#should(matcher = nil, &block) ⇒ Object
:call-seq: should(matcher) should == expected should === expected should =~ expected.
-
#should_not(matcher = nil, &block) ⇒ Object
:call-seq: should_not(matcher) should_not == expected should_not === expected should_not =~ expected.
Instance Method Details
#should(matcher = nil, &block) ⇒ Object
:call-seq:
should(matcher)
should == expected
should === expected
should =~ expected
receiver.should(matcher)
=> Passes if matcher.matches?(receiver)
receiver.should == expected #any value
=> Passes if (receiver == expected)
receiver.should === expected #any value
=> Passes if (receiver === expected)
receiver.should =~ regexp
=> Passes if (receiver =~ regexp)
See Spec::Matchers for more information about matchers
Warning
NOTE that this does NOT support receiver.should != expected. Instead, use receiver.should_not == expected
31 32 33 34 |
# File 'lib/spec/expectations/extensions/object.rb', line 31 def should(matcher=nil, &block) return ExpectationMatcherHandler.handle_matcher(self, matcher, &block) if matcher Spec::Matchers::PositiveOperatorMatcher.new(self) end |
#should_not(matcher = nil, &block) ⇒ Object
:call-seq:
should_not(matcher)
should_not == expected
should_not === expected
should_not =~ expected
receiver.should_not(matcher)
=> Passes unless matcher.matches?(receiver)
receiver.should_not == expected
=> Passes unless (receiver == expected)
receiver.should_not === expected
=> Passes unless (receiver === expected)
receiver.should_not =~ regexp
=> Passes unless (receiver =~ regexp)
See Spec::Matchers for more information about matchers
55 56 57 58 |
# File 'lib/spec/expectations/extensions/object.rb', line 55 def should_not(matcher=nil, &block) return NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block) if matcher Spec::Matchers::NegativeOperatorMatcher.new(self) end |