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.



31
32
33
34
# File 'lib/dumbo/test/matchers.rb', line 31

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.



29
30
31
# File 'lib/dumbo/test/matchers.rb', line 29

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



29
30
31
# File 'lib/dumbo/test/matchers.rb', line 29

def expected
  @expected
end

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/dumbo/test/matchers.rb', line 29

def options
  @options
end

Instance Method Details

#convert_actualObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dumbo/test/matchers.rb', line 60

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



56
57
58
# File 'lib/dumbo/test/matchers.rb', line 56

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

#failure_message_for_shouldObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dumbo/test/matchers.rb', line 44

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)


36
37
38
39
40
41
42
# File 'lib/dumbo/test/matchers.rb', line 36

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