Class: Vident::Testing::AttributesTester
- Inherits:
-
Object
- Object
- Vident::Testing::AttributesTester
- Defined in:
- lib/vident/testing/attributes_tester.rb
Instance Method Summary collapse
-
#initialize(test_configurations) ⇒ AttributesTester
constructor
A new instance of AttributesTester.
-
#invalid_configurations ⇒ Object
Generates attribute hashes for all permutations of the given invalid values.
-
#valid_configurations ⇒ Object
Generates attribute hashes for all permutations of the given valid values.
Constructor Details
#initialize(test_configurations) ⇒ AttributesTester
Returns a new instance of AttributesTester.
6 7 8 |
# File 'lib/vident/testing/attributes_tester.rb', line 6 def initialize(test_configurations) @test_configurations = test_configurations end |
Instance Method Details
#invalid_configurations ⇒ Object
Generates attribute hashes for all permutations of the given invalid values.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vident/testing/attributes_tester.rb', line 25 def invalid_configurations return [] unless invalid_configured? # prepare a valid initial state, then add any attrs that have :invalid initial_state = prepare_initial_test_state(prepare_attributes_to_test) # Merge in the invalid permutations test_configurations.inject([]) do |memo, attr| key, opts = attr next memo += nil if opts == :strict_boolean if opts.is_a?(Hash) values = if opts[:invalid].nil? && opts[:valid].is_a?(Hash) # If no invalid key specified we generate based on whats valid config = invalid_attribute_test_values_for(opts[:valid][:type], opts[:valid]) (config&.fetch(:invalid, []) || []) + (config&.fetch(:converts, []) || []) elsif opts[:invalid].is_a?(Array) opts[:invalid] end memo += values.map { |i| initial_state.merge(key => i) } if values end memo end end |
#valid_configurations ⇒ Object
Generates attribute hashes for all permutations of the given valid values.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vident/testing/attributes_tester.rb', line 11 def valid_configurations # Expands any auto generated values and returns all attributes and their values test_attrs = prepare_attributes_to_test # The first permutation is the initial state initial_state = prepare_initial_test_state(test_attrs) # Create remaining permutations test_attrs.flat_map do |attr_name, values| values.map { |v| initial_state.merge(attr_name => v) } end end |