Class: Shindo::Tests
- Inherits:
-
Object
- Object
- Shindo::Tests
- Defined in:
- lib/fog/test_helpers/formats_helper.rb,
lib/fog/test_helpers/succeeds_helper.rb,
lib/fog/test_helpers/responds_to_helper.rb
Instance Method Summary collapse
-
#data_matches_schema(schema, options = {}) { ... } ⇒ Boolean
Generates a Shindo test that compares a hash schema to the result of the passed in block returning true if they match.
-
#formats(format, strict = true) ⇒ Object
deprecated
Deprecated.
#formats is deprecated. Use #data_matches_schema instead
- #responds_to(method_names) ⇒ Object
- #succeeds(&block) ⇒ Object
Instance Method Details
#data_matches_schema(schema, options = {}) { ... } ⇒ Boolean
Generates a Shindo test that compares a hash schema to the result of the passed in block returning true if they match.
The schema that is passed in is a Hash or Array of hashes that have Classes in place of values. When checking the schema the value should match the Class.
Strict mode will fail if the data has additional keys. Setting strict
to false
will allow additional keys to appear.
50 51 52 53 54 55 56 57 |
# File 'lib/fog/test_helpers/formats_helper.rb', line 50 def data_matches_schema(schema, = {}) test("data matches schema") do validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, schema, ) @message = validator. unless valid valid end end |
#formats(format, strict = true) ⇒ Object
Deprecated.
#formats is deprecated. Use #data_matches_schema instead
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fog/test_helpers/formats_helper.rb', line 60 def formats(format, strict = true) test("has proper format") do if strict = { allow_extra_keys: false, allow_optional_rules: true } else = { allow_extra_keys: true, allow_optional_rules: true } end validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, format, ) @message = validator. unless valid valid end end |
#responds_to(method_names) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/fog/test_helpers/responds_to_helper.rb', line 3 def responds_to(method_names) method_names.each do |method_name| tests("#respond_to?(:#{method_name})").returns(true) do @instance.respond_to?(method_name) end end end |
#succeeds(&block) ⇒ Object
3 4 5 6 7 |
# File 'lib/fog/test_helpers/succeeds_helper.rb', line 3 def succeeds(&block) test("succeeds") do !!instance_eval(&block) end end |