Class: RSpec::ComposableJSONMatchers::BeJSON Private

Inherits:
Object
  • Object
show all
Includes:
Matchers::Composable
Defined in:
lib/rspec/composable_json_matchers/be_json.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, configuration) ⇒ BeJSON

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BeJSON.



11
12
13
14
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 11

def initialize(matcher, configuration)
  @matcher = matcher
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 9

def configuration
  @configuration
end

#decoded_actualObject (readonly) Also known as: actual

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 9

def decoded_actual
  @decoded_actual
end

#matcherObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 9

def matcher
  @matcher
end

#original_actualObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 9

def original_actual
  @original_actual
end

#parser_errorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 9

def parser_error
  @parser_error
end

Instance Method Details

#descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 30

def description
  "be JSON #{matcher.description}"
end

#diffable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


44
45
46
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 44

def diffable?
  parser_error.nil? && matcher.diffable?
end

#does_not_match?(actual) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 25

def does_not_match?(actual)
  matched = matches?(actual)
  parser_error ? false : !matched
end

#expectedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 48

def expected
  matcher.expected
end

#failure_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 34

def failure_message
  return parser_failure_message if parser_failure_message
  "expected #{original_actual} to be JSON #{matcher.description}"
end

#failure_message_when_negatedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
42
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 39

def failure_message_when_negated
  return parser_failure_message if parser_failure_message
  "expected #{original_actual} not to be JSON #{matcher.description}"
end

#matches?(actual) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
# File 'lib/rspec/composable_json_matchers/be_json.rb', line 16

def matches?(actual)
  @original_actual = actual
  @decoded_actual = parse(original_actual)
  matcher.matches?(decoded_actual)
rescue JSON::ParserError => error
  @parser_error = error
  false
end