Class: Simmer::Specification::Assert::Assertions::Table
- Inherits:
-
Object
- Object
- Simmer::Specification::Assert::Assertions::Table
- Includes:
- Logic
- Defined in:
- lib/simmer/specification/assert/assertions/table.rb
Overview
Describes an expected state of a database table.
Defined Under Namespace
Modules: Logic
Constant Summary collapse
- LOGIC_METHODS =
{ EQUALS => ->(actual_record_set, record_set) { actual_record_set == record_set }, INCLUDES => lambda { |actual_record_set, record_set| (actual_record_set & record_set) == record_set } }.freeze
Constants included from Logic
Logic::EQUALS, Logic::INCLUDES
Instance Attribute Summary collapse
-
#logic ⇒ Object
readonly
Returns the value of attribute logic.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#record_set ⇒ Object
readonly
Returns the value of attribute record_set.
Instance Method Summary collapse
- #assert(database, _output) ⇒ Object
-
#initialize(logic: EQUALS, name:, records: []) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(logic: EQUALS, name:, records: []) ⇒ Table
Returns a new instance of Table.
35 36 37 38 39 40 41 |
# File 'lib/simmer/specification/assert/assertions/table.rb', line 35 def initialize(logic: EQUALS, name:, records: []) @logic = Logic.const_get(logic.to_s.upcase.to_sym) @name = name.to_s @record_set = Util::RecordSet.new(records) freeze end |
Instance Attribute Details
#logic ⇒ Object (readonly)
Returns the value of attribute logic.
33 34 35 |
# File 'lib/simmer/specification/assert/assertions/table.rb', line 33 def logic @logic end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/simmer/specification/assert/assertions/table.rb', line 33 def name @name end |
#record_set ⇒ Object (readonly)
Returns the value of attribute record_set.
33 34 35 |
# File 'lib/simmer/specification/assert/assertions/table.rb', line 33 def record_set @record_set end |
Instance Method Details
#assert(database, _output) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/simmer/specification/assert/assertions/table.rb', line 43 def assert(database, _output) keys = record_set.keys actual_records = database.records(name, keys) actual_record_set = Util::RecordSet.new(actual_records) return nil if LOGIC_METHODS[logic].call(actual_record_set, record_set) BadTableAssertion.new(name, record_set, actual_record_set) end |