Class: Matchy::Expectations::Base
- Inherits:
-
Object
- Object
- Matchy::Expectations::Base
- Includes:
- Test::Unit::Assertions
- Defined in:
- lib/matchy/expectation.rb
Overview
Base class for all expectations. Inheriting from this DRYs up a lot of the constructor logic, etc.
TODO: Implement failure messages, inluding negative failure messages. Also, need to name variables/parameters to go with testing nomenclature (expected rather than just “object”).
Direct Known Subclasses
BeCloseExpectation, BeExpectation, BeKindOfExpectation, EqlExpectation, EqualExpectation, ExcludeExpectation, ExistExpectation, IncludeExpectation, OperatorExpectation, RaiseErrorExpectation, RespondToExpectation, SatisfyExpectation, ThrowSymbolExpectation
Instance Method Summary collapse
-
#fail!(which) ⇒ Object
Fail the expectation.
-
#failure_message ⇒ Object
Failure message.
-
#initialize(expected, test_case) ⇒ Base
constructor
Takes object to match against and the test_case we’re in so we can feed it the successes/failures.
-
#matches?(receiver) ⇒ Boolean
Match the given objects against some logic.
-
#negative_failure_message ⇒ Object
Negative failure message (i.e., for should_not).
-
#pass!(which) ⇒ Object
Pass the expectations.
Constructor Details
#initialize(expected, test_case) ⇒ Base
Takes object to match against and the test_case we’re in so we can feed it the successes/failures.
14 15 16 17 |
# File 'lib/matchy/expectation.rb', line 14 def initialize(expected, test_case) @expected = expected @test_case = test_case end |
Instance Method Details
#fail!(which) ⇒ Object
Fail the expectation. Calls flunk on the test case.
26 27 28 |
# File 'lib/matchy/expectation.rb', line 26 def fail!(which) @test_case.flunk(which ? : ) end |
#failure_message ⇒ Object
Failure message. Should be overriden.
37 38 39 |
# File 'lib/matchy/expectation.rb', line 37 def "OMG FAIL." end |
#matches?(receiver) ⇒ Boolean
Match the given objects against some logic. This raises an error in Base because each matcher (obviously) has to implement its own logic.
21 22 23 |
# File 'lib/matchy/expectation.rb', line 21 def matches?(receiver) raise "Please provide logic to match your expectation to an object! OR ELSE." end |
#negative_failure_message ⇒ Object
Negative failure message (i.e., for should_not). Should be overridden.
42 43 44 |
# File 'lib/matchy/expectation.rb', line 42 def "OMG FAIL TO FAIL." end |
#pass!(which) ⇒ Object
Pass the expectations. Calls assert true
. May want to consider something different here.
32 33 34 |
# File 'lib/matchy/expectation.rb', line 32 def pass!(which) @test_case.assert true end |