rspec-json_matcher 0.0.4 → 0.0.5

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: fe8679b010a21084b2b7fa60c0fa4f1f2081cbeb
4
- data.tar.gz: 7cba23c67f6e4037726440ab4b5d08c28e1ffa32
3
+ metadata.gz: 2b5b194d82e6f879060a40c9cee4ecdd96cd38ab
4
+ data.tar.gz: d7e4b9e053a6a0312542f451a9d6be0183cf469f
5
5
  SHA512:
6
- metadata.gz: 0b40b1025ec21c6f52441367a733d3651691cd1db90b2a3c96c81ad115f12b9db0cb13e709abc7850831978bfd9f5e15ec4a4d47bf06a13fdc17c7956eac4b4a
7
- data.tar.gz: 644c8da6b47f9f96eef217a0a522ec08f06053f21b6ea1ba9e70cbbaf85905ca06e104b13f93d209696d2f874c70e6589b257011d88abedf839bae0bca52a43c
6
+ metadata.gz: 419d26029dab6cf9868443c61fe14ddfedbd35cc6a1403b2760b03c0a04771ab202ef868c237311a2edeee08030d78c60a7bc1e5d569f10ccf6ef10ec6f22f3a
7
+ data.tar.gz: 8434fa25f560b14afc212606c994969fefb18368695c9fc5844b96cc18f93faa91e12a547c8a97622ef059dc1f3e18b575ca6a0a54f94f46e0f2e3f33bff87f4
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ ## 0.0.5
2
+ * More strict comparison to detect different Hash keys
3
+
4
+ ## 0.0.4
5
+ * Change indent style on failure message
6
+
7
+ ## 0.0.3
8
+ * Bundler friendliness
9
+
10
+ ## 0.0.2
11
+ * Tiny refactoring
12
+
13
+ ## 0.0.1
14
+ * The first release on 2013-4-25
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module JsonMatcher
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -69,6 +69,14 @@ module RSpec
69
69
  new(*args).compare
70
70
  end
71
71
 
72
+ def self.extract_keys(array_or_hash)
73
+ if array_or_hash.is_a?(Array)
74
+ array_or_hash.each_index.to_a
75
+ else
76
+ array_or_hash.keys
77
+ end
78
+ end
79
+
72
80
  def initialize(actual, expected)
73
81
  @actual = actual
74
82
  @expected = expected
@@ -84,8 +92,8 @@ module RSpec
84
92
  actual.class == expected.class
85
93
  end
86
94
 
87
- def has_same_size?
88
- actual.size == expected.size
95
+ def has_same_keys?
96
+ (self.class.extract_keys(actual) - self.class.extract_keys(expected)).size == 0
89
97
  end
90
98
 
91
99
  def has_same_value?
@@ -97,25 +105,16 @@ module RSpec
97
105
  end
98
106
 
99
107
  def has_same_collection?
100
- collection? && has_same_class? && has_same_size? && has_same_key_values?
108
+ collection? && has_same_class? && has_same_keys? && has_same_values?
101
109
  end
102
110
 
103
- def has_same_key_values?
104
- keys.all? {|key| self.class.compare(actual[key], expected[key]) }
111
+ def has_same_values?
112
+ self.class.extract_keys(actual).all? {|key| self.class.compare(actual[key], expected[key]) }
105
113
  end
106
114
 
107
115
  def collection?
108
116
  actual.is_a?(Array) || actual.is_a?(Hash)
109
117
  end
110
-
111
- def keys
112
- case actual
113
- when Array
114
- actual.each_index
115
- when Hash
116
- actual.keys
117
- end
118
- end
119
118
  end
120
119
  end
121
120
  end
@@ -2,11 +2,21 @@ require "spec_helper"
2
2
 
3
3
  describe RSpec::JsonMatcher do
4
4
  context "with invalid JSON" do
5
- it "does match" do
5
+ it "does not match" do
6
6
  "".should_not be_json
7
7
  end
8
8
  end
9
9
 
10
+ context "with invalid keys JSON" do
11
+ it "does not match" do
12
+ {
13
+ "a" => nil
14
+ }.to_json.should_not be_json(
15
+ "b" => nil
16
+ )
17
+ end
18
+ end
19
+
10
20
  context "with valid JSON" do
11
21
  it "matches with handy patterns" do
12
22
  [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-json_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - .gitignore
91
+ - CHANGELOG.md
91
92
  - Gemfile
92
93
  - LICENSE.txt
93
94
  - README.md
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  requirements: []
120
121
  rubyforge_project:
121
- rubygems_version: 2.0.2
122
+ rubygems_version: 2.0.3
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: RSpec matcher for testing JSON string