Module: Respect::UnitTestHelper

Defined in:
lib/respect/unit_test_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) assert_schema_invalidate(schema, object, msg = nil)



30
31
32
# File 'lib/respect/unit_test_helper.rb', line 30

def assert_schema_invalidate(schema, object, msg = nil)
  assert_schema_validation_is(false, schema, object, msg)
end

- (Object) assert_schema_validate(schema, object, msg = nil)



26
27
28
# File 'lib/respect/unit_test_helper.rb', line 26

def assert_schema_validate(schema, object, msg = nil)
  assert_schema_validation_is(true, schema, object, msg)
end

- (Object) assert_schema_validation_is(expected, schema, object, msg = nil)



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/respect/unit_test_helper.rb', line 3

def assert_schema_validation_is(expected, schema, object, msg = nil)
  valid = schema.validate?(object)
  if expected
    if !valid
      if msg
        message = msg
      else
        message = "Schema:\n#{schema}expected to validate object <#{object.inspect}> but failed with \"#{schema.last_error.context.join(" ")}\"."
      end
      assert false, message
    end
  else
    if valid
      if msg
        message = msg
      else
        message = "Schema:\n#{schema}expected to invalidate object <#{object.inspect}> but succeed."
      end
      assert false, message
    end
  end
end