class MySQLExpectations::Matchers::HaveField
A matcher that checks if a MySQLDumpExpectations::Table has a field. Optionally, checks the field type and nullability
Attributes
expected_field_name[R]
expected_nullable[R]
expected_type[R]
table[R]
Public Class Methods
new(expected_field_name)
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 14 def initialize(expected_field_name) @expected_field_name = expected_field_name @expected_type = nil @expected_nullable = nil @table = nil end
Public Instance Methods
actual_nullable()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 36 def actual_nullable table.field(expected_field_name).nullable? end
actual_type()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 25 def actual_type table.field(expected_field_name).type end
description()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 52 def description description = "have field '#{expected_field_name}'" description << " of type '#{expected_type}'" if expected_type description << ' that is nullable' if expected_nullable == true description << ' that is not nullable' if expected_nullable == false description end
failure_message()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 81 def failure_message return field_error unless field_match? return type_error unless type_match? return nullable_error unless nullable_match? end
failure_message_when_negated()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 87 def failure_message_when_negated field_error(negated: true) end
field_error(negated: false)
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 60 def field_error(negated: false) "expected '#{table.name}' table" \ " #{negated ? 'not ' : ''}to "\ "have field '#{expected_field_name}'." end
field_match?()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 21 def field_match? table.field?(expected_field_name) end
matches?(table)
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 47 def matches?(table) @table = table field_match? && type_match? && nullable_match? end
nullable_error()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 71 def nullable_error message = "expected '#{table.name}.#{expected_field_name}' field " message << 'to be ' message << 'not ' unless expected_nullable message << 'nullable but it was ' message << 'not ' unless actual_nullable message << 'nullable.' message end
nullable_match?()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 40 def nullable_match? if field_match? && !expected_nullable.nil? return actual_nullable == expected_nullable end true end
of_type(expected_type)
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 91 def of_type(expected_type) @expected_type = expected_type self end
that_is_not_nullable()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 101 def that_is_not_nullable @expected_nullable = false self end
that_is_nullable()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 96 def that_is_nullable @expected_nullable = true self end
type_error()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 66 def type_error "expected '#{table.name}.#{expected_field_name}' field " \ "to be of type '#{expected_type}' but it was '#{actual_type}'" end
type_match?()
click to toggle source
# File lib/mysql_expectations/matchers/table_have_field.rb, line 29 def type_match? if field_match? && !expected_type.nil? return actual_type == expected_type end true end