Class: Dumbo::Matchers::QueryMatcher

Inherits:
RSpec::Matchers::BuiltIn::ContainExactly
  • Object
show all
Defined in:
lib/dumbo/test/matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected = UNDEFINED, options = {}) ⇒ QueryMatcher

Returns a new instance of QueryMatcher.



65
66
67
68
# File 'lib/dumbo/test/matchers.rb', line 65

def initialize(expected = UNDEFINED, options={})
  @expected = expected unless UNDEFINED.equal?(expected)
  @options = options
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



63
64
65
# File 'lib/dumbo/test/matchers.rb', line 63

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



63
64
65
# File 'lib/dumbo/test/matchers.rb', line 63

def expected
  @expected
end

#optionsObject (readonly)

Returns the value of attribute options.



63
64
65
# File 'lib/dumbo/test/matchers.rb', line 63

def options
  @options
end

Instance Method Details

#convert_actualObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/dumbo/test/matchers.rb', line 95

def convert_actual
  @actual = if options[:header]
    [actual.columns] + actual.rows
  else
    case actual.rows.size
    when 0
      []
    when 1
      actual.rows.first
    else
      actual.rows
    end
  end
end

#convert_expectedObject



91
92
93
# File 'lib/dumbo/test/matchers.rb', line 91

def convert_expected
  @expected = [expected] unless expected.is_a?(Array)
end

#failure_message_for_shouldObject



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dumbo/test/matchers.rb', line 79

def failure_message_for_should
  if @missing_items.empty? && @extra_items.empty?
    message = "actual collection is in the wrong order\n"
    message +=  "expected collection contained:  #{expected.inspect}\n"
    message += "actual collection contained:    #{actual.inspect}\n"
    message
  else
    super
  end

end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
# File 'lib/dumbo/test/matchers.rb', line 70

def matches?(actual)
  raise actual if actual.kind_of?(Exception)
  @actual = actual
  convert_actual
  convert_expected
  match = match(expected, self.actual)
  options[:ordered] ? expected == self.actual : match
end