rspec-json_matcher 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aea2e2c2395eca489ac7a672f7cbdfdc22db91f6
4
- data.tar.gz: d5bc11c37a503f0ff4b8db0c1e456c162825bb02
3
+ metadata.gz: e45eac67dbe3e29c027ac71c53f7729303270e19
4
+ data.tar.gz: bf794ed34f279494b7908e55050c3dda5099b6be
5
5
  SHA512:
6
- metadata.gz: 4ebf3089fd90e425dedfd883287ad02ffc94615312ec8fca156128a575a9d7a151f4f0416ff933082667fa2f0a595c5a4e91f6084f4ee35dac6b0b66f58e975f
7
- data.tar.gz: 57b8cd3c74f36fb6f936e5244bd9bab12b8c179c01f49ae8d997661fabdfdc9e1d8c9647646fbd6802854af18d1f62ce9e2ce8eda57c6bf47be756418a1a5c29
6
+ metadata.gz: ed23cc7165475a0e11a4bfb26a1eebeb185c1029711bb7067d86411fe22a77cf0289646ab2dc75d9139654b66361626fdd2ccc5932cf1e6b85209180b6e37b14
7
+ data.tar.gz: 4541d20701817b6e58ee6ba3aee7efee59b57fe204292fd1651f66d19f41320e392c54510ca9c3983bb8fc357c99def3fe98e72ad8df6a59d1e55a38c810a55d
data/README.md CHANGED
@@ -1,17 +1,18 @@
1
1
  # RSpec::JsonMatcher
2
2
  This library provides RSpec matcher for testing JSON string.
3
3
 
4
+ * parsing a given value as JSON string
5
+ * handy pattern matching with `#===` method like case-when statement
6
+ * supporting nested pattern matching
7
+
4
8
  ## Usage
9
+ ### Configuration
5
10
  ```ruby
6
11
  # spec/spec_helper.rb
12
+ require "rspec/json_matcher"
7
13
  RSpec.configuration.include RSpec::JsonMatcher
8
14
  ```
9
15
 
10
- ### Features
11
- * parsing a given value as JSON string
12
- * handy pattern matching with `#===` method like case-when statement
13
- * supporting nested pattern matching
14
-
15
16
  ### Example
16
17
  ```ruby
17
18
  [
@@ -9,7 +9,7 @@ module RSpec
9
9
  end
10
10
 
11
11
  class Matcher
12
- attr_reader :expected
12
+ attr_reader :expected, :parsed
13
13
 
14
14
  def initialize(expected = nil)
15
15
  @expected = expected
@@ -18,7 +18,7 @@ module RSpec
18
18
  def matches?(json)
19
19
  @parsed = JSON.parse(json)
20
20
  if has_expectation?
21
- Comparer.compare(@parsed, expected)
21
+ Comparer.compare(parsed, expected)
22
22
  else
23
23
  true
24
24
  end
@@ -58,7 +58,7 @@ module RSpec
58
58
  end
59
59
 
60
60
  def inspection(prefix = nil)
61
- ["expected #{prefix}to match:", @expected.ai, "", "actual:", @parsed.ai].join("\n")
61
+ ["expected #{prefix}to match:", expected.ai, "", "actual:", parsed.ai].join("\n")
62
62
  end
63
63
  end
64
64
 
@@ -75,7 +75,7 @@ module RSpec
75
75
  end
76
76
 
77
77
  def compare
78
- has_same_value?
78
+ has_equal_value? || has_same_collection?
79
79
  end
80
80
 
81
81
  private
@@ -88,10 +88,6 @@ module RSpec
88
88
  actual.size == expected.size
89
89
  end
90
90
 
91
- def has_same_value?
92
- has_equal_value? || has_same_collection?
93
- end
94
-
95
91
  def has_equal_value?
96
92
  if expected.respond_to?(:call)
97
93
  expected.call(actual)
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module JsonMatcher
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -38,7 +38,7 @@ describe RSpec::JsonMatcher do
38
38
  }
39
39
  ].to_json.should be_json([
40
40
  {
41
- "url" => /^invalid pattern$/,
41
+ "url" => /^https:/,
42
42
  "id" => /^\d+$/,
43
43
  "description" => /gist/,
44
44
  "public" => true,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-json_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura