Class: JsonMatchers::RSpec

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/json_matchers/rspec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_name, **options) ⇒ RSpec

Returns a new instance of RSpec.



7
8
9
10
11
# File 'lib/json_matchers/rspec.rb', line 7

def initialize(schema_name, **options)
  @schema_name = schema_name

  super(JsonMatchers::Matcher.new(schema_path, options))
end

Instance Attribute Details

#schema_nameObject (readonly)

Returns the value of attribute schema_name.



5
6
7
# File 'lib/json_matchers/rspec.rb', line 5

def schema_name
  @schema_name
end

Instance Method Details

#failure_message(response) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/json_matchers/rspec.rb', line 13

def failure_message(response)
  <<-FAIL.strip_heredoc
  expected

  #{response.body}

  to match schema "#{schema_name}":

  #{schema_body}

  ---

  #{validation_failure_message}

  FAIL
end

#failure_message_when_negated(response) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/json_matchers/rspec.rb', line 30

def failure_message_when_negated(response)
  <<-FAIL.strip_heredoc
  expected

  #{response.body}

  not to match schema "#{schema_name}":

  #{schema_body}

  ---

  #{validation_failure_message}

  FAIL
end

#schema_bodyObject



51
52
53
# File 'lib/json_matchers/rspec.rb', line 51

def schema_body
  File.read(schema_path)
end

#schema_pathObject



47
48
49
# File 'lib/json_matchers/rspec.rb', line 47

def schema_path
  JsonMatchers.path_to_schema(schema_name)
end