Method: Micronaut::Expectations::ObjectExpectations#should
- Defined in:
- lib/micronaut/expectations/extensions/object.rb
#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 Micronaut::Matchers for more information about matchers
Warning
NOTE that this does NOT support receiver.should != expected. Instead, use receiver.should_not == expected
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/micronaut/expectations/extensions/object.rb', line 29 def should(matcher=nil, &block) ::Micronaut::Matchers.last_should = "should" return ::Micronaut::Matchers::PositiveOperatorMatcher.new(self) if matcher.nil? unless matcher.respond_to?(:matches?) raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}." end match_found = matcher.matches?(self, &block) ::Micronaut::Matchers.last_matcher = matcher ::Micronaut::Expectations.fail_with(matcher.) unless match_found match_found end |