Class: Jsonschema::Matchers::MatchJsonschema

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonschema/matchers/match_jsonschema.rb

Overview

Match Jsonschema snapshot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata, name) ⇒ MatchJsonschema

Returns a new instance of MatchJsonschema.



11
12
13
14
15
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 11

def initialize(, name)
  @metadata = 
  @path = "#{root_dir}/#{Metadater.call()}"
  @name = name.downcase.gsub(%r{[\/\s]}, '/' => '_', ' ' => '_')
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9

def errors
  @errors
end

#metadataObject (readonly)

Returns the value of attribute metadata.



9
10
11
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 9

def path
  @path
end

Instance Method Details

#failure_messageObject



26
27
28
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 26

def failure_message
  errors.join("\n")
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
# File 'lib/jsonschema/matchers/match_jsonschema.rb', line 17

def matches?(actual)
  file_full_path = "#{path}/#{name}.json"
  record(actual) unless File.exist?(file_full_path)
  file = File.open(file_full_path)

  @errors = JSON::Validator.fully_validate(file.path, actual)
  errors.empty?
end