Class: Wukong::SpecHelpers::UnitTestMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb

Direct Known Subclasses

DelimitedMatcher, JsonMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*expected) ⇒ UnitTestMatcher

Returns a new instance of UnitTestMatcher.



28
29
30
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 28

def initialize *expected
  self.expected = expected
end

Instance Attribute Details

#actual_recordObject

Returns the value of attribute actual_record.



5
6
7
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5

def actual_record
  @actual_record
end

#driverObject

Returns the value of attribute driver.



5
6
7
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5

def driver
  @driver
end

#expectedObject

Returns the value of attribute expected.



5
6
7
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5

def expected
  @expected
end

#expected_recordObject

Returns the value of attribute expected_record.



5
6
7
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5

def expected_record
  @expected_record
end

#mismatched_indexObject

Returns the value of attribute mismatched_index.



5
6
7
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5

def mismatched_index
  @mismatched_index
end

#reasonObject

Returns the value of attribute reason.



5
6
7
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5

def reason
  @reason
end

Instance Method Details

#failure_messageObject



32
33
34
35
36
37
38
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 32

def failure_message
  if reason == :size
    "Expected #{expected_size} records, got #{actual_size}:\n\n#{pretty_output}"
  else
    "Expected the #{ordinalize(mismatched_index)} record to be#{parse_modifier}\n\n#{expected_record}\n\nbut got\n\n#{pretty_output}"
  end
end

#matches?(driver) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 7

def matches?(driver)
  self.driver = driver
  driver.run
  if actual_size != expected_size
    self.reason = :size
    return false
  end
  return true if just_count?
  expected.each_with_index do |expectation, index|
    actual = output[index]
    if actual != expectation
      self.reason           = :element
      self.expected_record  = expectation
      self.actual_record    = actual
      self.mismatched_index = index
      return false
    end
  end
  true
end

#negative_failure_messageObject



40
41
42
43
44
45
46
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 40

def negative_failure_message
  if reason == :size
    "Expected to NOT get #{expected_size} records:\n\n#{output}"
  else
    "Expected the #{ordinalize(mismatched_index)} record to NOT be#{parse_modifier}\n\n#{pretty_output}"
  end
end

#recordsObject Also known as: record



48
49
50
51
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 48

def records
  @just_count = true
  self                    # chaining
end