Class: Matchy::Expectations::Base

Inherits:
Object
  • Object
show all
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”).

Instance Method Summary collapse

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 ? failure_message : negative_failure_message)
end

#failure_messageObject

Failure message. Should be overriden.



37
38
39
# File 'lib/matchy/expectation.rb', line 37

def failure_message
  "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.

Returns:

  • (Boolean)


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_messageObject

Negative failure message (i.e., for should_not). Should be overridden.



42
43
44
# File 'lib/matchy/expectation.rb', line 42

def negative_failure_message
  "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