Class: RSpec::JsonMatchers::Matchers::BeJsonMatcher Private

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

Overview

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.

The implementation for #be_json

Direct Known Subclasses

BeJsonWithContentMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#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.



21
22
23
# File 'lib/rspec/json_matchers/matchers/be_json_matcher.rb', line 21

def actual
  @actual
end

Instance Method Details

#descriptionString

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.

Expectation description in spec result summary

Returns:

  • (String)


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

def description
  "be a valid JSON string"
end

#does_not_match?(*args) ⇒ 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)


31
32
33
# File 'lib/rspec/json_matchers/matchers/be_json_matcher.rb', line 31

def does_not_match?(*args)
  !matches?(*args)
end

#failure_messageString

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.

Failure message displayed when a positive example failed (e.g. using should)

Returns:

  • (String)


59
60
61
# File 'lib/rspec/json_matchers/matchers/be_json_matcher.rb', line 59

def failure_message
  "expected value to be parsed as JSON, but failed"
end

#failure_message_when_negatedString

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.

Failure message displayed when a negative example failed (e.g. using should_not)

Returns:

  • (String)


67
68
69
# File 'lib/rspec/json_matchers/matchers/be_json_matcher.rb', line 67

def failure_message_when_negated
  "expected value not to be parsed as JSON, but succeeded"
end

#matches?(json) ⇒ 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)


23
24
25
26
27
28
29
# File 'lib/rspec/json_matchers/matchers/be_json_matcher.rb', line 23

def matches?(json)
  @actual = JSON.parse(json)
  true
rescue JSON::ParserError
  @has_parser_error = true
  false
end

#with_content(expected) ⇒ BeJsonWithContentMatcher

Get a matcher that try to match the content of actual with nested various expectations

Parameters:

  • expected (Hash, Array, Object)

    the expectation object

Returns:



44
45
46
# File 'lib/rspec/json_matchers/matchers/be_json_matcher.rb', line 44

def with_content(expected)
  BeJsonWithContentMatcher.new(expected)
end