Module: Micronaut::Expectations
- Defined in:
- lib/micronaut/expectations.rb,
lib/micronaut/expectations/handler.rb,
lib/micronaut/expectations/extensions/object.rb
Overview
Micronaut::Expectations lets you set expectations on your objects.
result.should == 37
team.should have(11).players_on_the_field
How Expectations work.
Micronaut::Expectations adds two methods to Object:
should(matcher=nil)
should_not(matcher=nil)
Both methods take an optional Expression Matcher (See Micronaut::Matchers).
When should
receives an Expression Matcher, it calls matches?(self)
. If it returns true
, the spec passes and execution continues. If it returns false
, then the spec fails with the message returned by matcher.failure_message
.
Similarly, when should_not
receives a matcher, it calls matches?(self)
. If it returns false
, the spec passes and execution continues. If it returns true
, then the spec fails with the message returned by matcher.negative_failure_message
.
Micronaut ships with a standard set of useful matchers, and writing your own matchers is quite simple. See Micronaut::Matchers for details.
Defined Under Namespace
Modules: ObjectExpectations Classes: ExpectationNotMetError, InvalidMatcherError
Class Method Summary collapse
Class Method Details
.fail_with(message, expected = nil, target = nil) ⇒ Object
:nodoc:
36 37 38 39 40 41 |
# File 'lib/micronaut/expectations.rb', line 36 def self.fail_with(, expected=nil, target=nil) # :nodoc: if Array === && .length == 3 , expected, target = [0], [1], [2] end Kernel::raise(Micronaut::Expectations::ExpectationNotMetError.new()) end |