class MySQLExpectations::Matchers::HaveKey

A matcher that checks if a MySQLDumpExpectations::Table has a field. Optionally, checks the field type and nullability

Attributes

expected_key[R]
table[R]

Public Class Methods

new(expected_key) click to toggle source
# File lib/mysql_expectations/matchers/table_have_key.rb, line 13
def initialize(expected_key)
  @expected_key = expected_key
  @table = nil
end

Public Instance Methods

current_keys(keys) click to toggle source
# File lib/mysql_expectations/matchers/table_have_key.rb, line 29
def current_keys(keys)
  result = ''
  keys.each_with_index do |key, index|
    result << key.to_s
    result << ",\n" unless index == keys.size - 1
  end
  result
end
description() click to toggle source
# File lib/mysql_expectations/matchers/table_have_key.rb, line 24
def description
  description = "have key #{expected_key}"
  description
end
failure_message() click to toggle source
# File lib/mysql_expectations/matchers/table_have_key.rb, line 38
def failure_message
  result = "expected '#{table.name}' table to " \
    "have key #{expected_key}"
  keys = table.keys
  if keys.empty?
    result << ' but it has no keys.'
  else
    result << " but it has keys:\n"
    result << current_keys(keys)
  end
  result
end
matches?(table) click to toggle source
# File lib/mysql_expectations/matchers/table_have_key.rb, line 18
def matches?(table)
  @table = table
  @table.key?(expected_key.name) &&
    @table.key(expected_key.name) == expected_key
end