Class: MatchJson::Matchers::IncludeJson
- Inherits:
-
Object
- Object
- MatchJson::Matchers::IncludeJson
- Defined in:
- lib/match_json/matchers/include_json.rb
Constant Summary collapse
- PATTERNS =
{ 'date_time_iso8601' => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/, 'date' => /^\d{4}-\d{2}-\d{2}/, 'uuid' => /\h{32}/, 'email' => /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,6}\z/i, 'string' => /\A.+\z/i }
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected_json) ⇒ IncludeJson
constructor
A new instance of IncludeJson.
- #matches?(actual_json) ⇒ Boolean
Constructor Details
#initialize(expected_json) ⇒ IncludeJson
Returns a new instance of IncludeJson.
13 14 15 |
# File 'lib/match_json/matchers/include_json.rb', line 13 def initialize(expected_json) @expected_json = JSON.parse(expected_json.gsub(/(?<!")(\{\w+\})(?!")/, '"\1:non-string"')) end |
Instance Method Details
#failure_message ⇒ Object
23 24 25 |
# File 'lib/match_json/matchers/include_json.rb', line 23 def @failure_message end |
#failure_message_when_negated ⇒ Object
27 28 29 |
# File 'lib/match_json/matchers/include_json.rb', line 27 def "does not support negation" end |
#matches?(actual_json) ⇒ Boolean
17 18 19 20 21 |
# File 'lib/match_json/matchers/include_json.rb', line 17 def matches?(actual_json) @actual_json = actual_json.respond_to?(:body) ? JSON.parse(actual_json.body) : JSON.parse(actual_json) catch(:match) { json_included?(@actual_json, @expected_json) } end |