Module: ActiveCucumber
- Defined in:
- lib/active_cucumber.rb,
lib/active_cucumber/creator.rb,
lib/active_cucumber/cucumparer.rb,
lib/active_cucumber/cucumberator.rb,
lib/active_cucumber/active_record_builder.rb
Overview
The main namespace for this gem
Defined Under Namespace
Classes: ActiveRecordBuilder, Creator, Cucumberator, Cucumparer
Class Method Summary collapse
-
.attributes_for(activerecord_class, cucumber_table, context: {}) ⇒ Hash
Returns the attributes to create an instance of the given ActiveRecord class that matches the given vertical Cucumber table.
-
.create_many(activerecord_class, cucumber_table, context: {}) ⇒ Array<ActiveRecord::Base>
Creates entries of the given ActiveRecord class specified by the given horizontal Cucumber table.
-
.create_one(activerecord_class, cucumber_table, context: {}) ⇒ ActiveRecord::Base
Creates an entry of the given ActiveRecord class specified by the given vertical Cucumber table.
-
.diff_all!(clazz, cucumber_table, context: {}) ⇒ void
Verifies that the database table for the given ActiveRecord class matches the given horizontal Cucumber table.
-
.diff_one!(object, cucumber_table, context: {}) ⇒ void
Verifies that the given object matches the given vertical Cucumber table.
-
.horizontal_table(table) ⇒ Array<Hash>
Returns the given horizontal Cucumber table in standardized format.
- .validate_activerecord_class!(klass) ⇒ Object private
- .validate_activerecord_class_or_collection!(value) ⇒ Object private
- .validate_activerecord_instance!(object) ⇒ Object private
- .validate_context!(context) ⇒ Object private
-
.vertical_table(table) ⇒ Hash
Returns the given vertical Cucumber table in standardized format.
Class Method Details
.attributes_for(activerecord_class, cucumber_table, context: {}) ⇒ Hash
Returns the attributes to create an instance of the given ActiveRecord class that matches the given vertical Cucumber table.
19 20 21 22 23 24 |
# File 'lib/active_cucumber.rb', line 19 def self.attributes_for(activerecord_class, cucumber_table, context: {}) validate_activerecord_class!(activerecord_class) validate_context!(context) builder = ActiveRecordBuilder.new activerecord_class, context builder.attributes_for ActiveCucumber.vertical_table(cucumber_table) end |
.create_many(activerecord_class, cucumber_table, context: {}) ⇒ Array<ActiveRecord::Base>
Creates entries of the given ActiveRecord class specified by the given horizontal Cucumber table.
35 36 37 38 39 40 |
# File 'lib/active_cucumber.rb', line 35 def self.create_many(activerecord_class, cucumber_table, context: {}) validate_activerecord_class!(activerecord_class) validate_context!(context) builder = ActiveRecordBuilder.new activerecord_class, context builder.create_many ActiveCucumber.horizontal_table(cucumber_table) end |
.create_one(activerecord_class, cucumber_table, context: {}) ⇒ ActiveRecord::Base
Creates an entry of the given ActiveRecord class specified by the given vertical Cucumber table.
51 52 53 54 55 56 |
# File 'lib/active_cucumber.rb', line 51 def self.create_one(activerecord_class, cucumber_table, context: {}) validate_activerecord_class!(activerecord_class) validate_context!(context) builder = ActiveRecordBuilder.new activerecord_class, context builder.create_record ActiveCucumber.vertical_table(cucumber_table) end |
.diff_all!(clazz, cucumber_table, context: {}) ⇒ void
Records are sorted by creation date before comparison
This method returns an undefined value.
Verifies that the database table for the given ActiveRecord class matches the given horizontal Cucumber table.
67 68 69 70 71 72 |
# File 'lib/active_cucumber.rb', line 67 def self.diff_all!(clazz, cucumber_table, context: {}) validate_activerecord_class_or_collection!(clazz) validate_context!(context) cucumparer = Cucumparer.new clazz, cucumber_table, context cucumber_table.diff! cucumparer.to_horizontal_table end |
.diff_one!(object, cucumber_table, context: {}) ⇒ void
This method returns an undefined value.
Verifies that the given object matches the given vertical Cucumber table.
81 82 83 84 85 86 |
# File 'lib/active_cucumber.rb', line 81 def self.diff_one!(object, cucumber_table, context: {}) validate_activerecord_instance!(object) validate_context!(context) cucumparer = Cucumparer.new object.class, cucumber_table, context cucumber_table.diff! cucumparer.to_vertical_table(object) end |
.horizontal_table(table) ⇒ Array<Hash>
Returns the given horizontal Cucumber table in standardized format.
92 93 94 |
# File 'lib/active_cucumber.rb', line 92 def self.horizontal_table(table) table.hashes end |
.validate_activerecord_class!(klass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 108 109 |
# File 'lib/active_cucumber.rb', line 105 def self.validate_activerecord_class!(klass) return if klass.is_a?(Class) && klass < ActiveRecord::Base raise TypeError, "Expected an ActiveRecord class, got #{klass.inspect}" end |
.validate_activerecord_class_or_collection!(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 115 116 117 118 |
# File 'lib/active_cucumber.rb', line 112 def self.validate_activerecord_class_or_collection!(value) # Allow ActiveRecord class, array of instances, or ActiveRecord relation/association return if value.is_a?(Class) && value < ActiveRecord::Base return if value.is_a?(Array) || value.respond_to?(:all) raise TypeError, "Expected an ActiveRecord class or collection, got #{value.class}" end |
.validate_activerecord_instance!(object) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
121 122 123 124 125 |
# File 'lib/active_cucumber.rb', line 121 def self.validate_activerecord_instance!(object) return if object.is_a?(ActiveRecord::Base) raise TypeError, "Expected an ActiveRecord instance, got #{object.class}" end |
.validate_context!(context) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
128 129 130 131 132 |
# File 'lib/active_cucumber.rb', line 128 def self.validate_context!(context) return if context.is_a?(Hash) raise TypeError, "Expected context to be a Hash, got #{context.class}" end |
.vertical_table(table) ⇒ Hash
Returns the given vertical Cucumber table in standardized format.
100 101 102 |
# File 'lib/active_cucumber.rb', line 100 def self.vertical_table(table) table.rows_hash end |