json_spec 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +0 -1
- data/README.md +2 -2
- data/json_spec.gemspec +1 -1
- data/lib/json_spec/helpers.rb +8 -7
- data/lib/json_spec/matchers/include_json.rb +1 -0
- data/spec/json_spec/helpers_spec.rb +5 -0
- data/spec/json_spec/matchers/be_json_eql_spec.rb +2 -2
- data/spec/json_spec/matchers/have_json_path_spec.rb +1 -1
- data/spec/json_spec/matchers/have_json_size_spec.rb +2 -2
- data/spec/json_spec/matchers/have_json_type_spec.rb +2 -2
- data/spec/json_spec/matchers/include_json_spec.rb +9 -3
- metadata +3 -3
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
json_spec [](http://travis-ci.org/collectiveidea/json_spec) [](https://gemnasium.com/collectiveidea/json_spec)
|
1
|
+
json_spec [](http://travis-ci.org/collectiveidea/json_spec) [](https://gemnasium.com/collectiveidea/json_spec) [](https://codeclimate.com/github/collectiveidea/json_spec)
|
2
2
|
=========
|
3
3
|
|
4
4
|
Easily handle JSON in RSpec and Cucumber
|
@@ -313,7 +313,7 @@ Then the JSON response at "0/first_name" should be %{FIRST_NAME}
|
|
313
313
|
### More
|
314
314
|
|
315
315
|
Check out the [specs](https://github.com/collectiveidea/json_spec/blob/master/spec)
|
316
|
-
and [features](https://github.com/collectiveidea/json_spec/blob/master/features)
|
316
|
+
and [features](https://github.com/collectiveidea/json_spec/blob/master/features) to see all the
|
317
317
|
various ways you can use json_spec.
|
318
318
|
|
319
319
|
Contributing
|
data/json_spec.gemspec
CHANGED
data/lib/json_spec/helpers.rb
CHANGED
@@ -34,18 +34,19 @@ module JsonSpec
|
|
34
34
|
def value_at_json_path(ruby, path)
|
35
35
|
return ruby unless path
|
36
36
|
|
37
|
-
|
37
|
+
path.split("/").inject(ruby) do |value, key|
|
38
38
|
case value
|
39
|
-
when Hash
|
40
|
-
|
39
|
+
when Hash
|
40
|
+
value.fetch(key){ missing_json_path!(path) }
|
41
|
+
when Array
|
42
|
+
missing_json_path!(path) unless key =~ /^\d+$/
|
43
|
+
value.fetch(key.to_i){ missing_json_path!(path) }
|
44
|
+
else
|
45
|
+
missing_json_path!(path)
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
44
49
|
|
45
|
-
def json_path_to_keys(path)
|
46
|
-
path.split("/").map{|k| k =~ /^\d+$/ ? k.to_i : k }
|
47
|
-
end
|
48
|
-
|
49
50
|
def missing_json_path!(path)
|
50
51
|
raise JsonSpec::MissingPath.new(path)
|
51
52
|
end
|
@@ -28,6 +28,11 @@ describe JsonSpec::Helpers do
|
|
28
28
|
expect{ parse_json(json, path) }.to raise_error(JsonSpec::MissingPath)
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
it "parses at a numeric string path" do
|
33
|
+
json = %({"1":"two"})
|
34
|
+
parse_json(%({"1":"two"}), "1").should == "two"
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
context "normalize_json" do
|
@@ -86,13 +86,13 @@ describe JsonSpec::Matchers::BeJsonEql do
|
|
86
86
|
%({"id":1,"json":"spec"}).should_not be_json_eql(%({"id":2,"json":"different"})).including(:id, :json)
|
87
87
|
end
|
88
88
|
|
89
|
-
it "
|
89
|
+
it "provides a description message" do
|
90
90
|
matcher = be_json_eql(%({"id":2,"json":"spec"}))
|
91
91
|
matcher.matches?(%({"id":1,"json":"spec"}))
|
92
92
|
matcher.description.should == "equal JSON"
|
93
93
|
end
|
94
94
|
|
95
|
-
it "
|
95
|
+
it "provides a description message with path" do
|
96
96
|
matcher = be_json_eql(%({"id":1,"json":["spec"]})).at_path("json/0")
|
97
97
|
matcher.matches?(%({"id":1,"json":["spec"]}))
|
98
98
|
matcher.description.should == %(equal JSON at path "json/0")
|
@@ -21,7 +21,7 @@ describe JsonSpec::Matchers::HaveJsonPath do
|
|
21
21
|
%({"one":[1,2,{"three":4}]}).should have_json_path("one/2/three")
|
22
22
|
end
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "provides a description message" do
|
25
25
|
matcher = have_json_path("json")
|
26
26
|
matcher.matches?(%({"id":1,"json":"spec"}))
|
27
27
|
matcher.description.should == %(have JSON path "json")
|
@@ -33,13 +33,13 @@ describe JsonSpec::Matchers::HaveJsonSize do
|
|
33
33
|
matcher.failure_message_for_should_not.should == "Expected JSON value size to not be 3, got 3"
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "provides a description message" do
|
37
37
|
matcher = have_json_size(1)
|
38
38
|
matcher.matches?(%({"id":1,"json":["spec"]}))
|
39
39
|
matcher.description.should == %(have JSON size "1")
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "provides a description message with path" do
|
43
43
|
matcher = have_json_size(1).at_path("json")
|
44
44
|
matcher.matches?(%({"id":1,"json":["spec"]}))
|
45
45
|
matcher.description.should == %(have JSON size "1" at path "json")
|
@@ -58,13 +58,13 @@ describe JsonSpec::Matchers::HaveJsonType do
|
|
58
58
|
matcher.failure_message_for_should_not.should == "Expected JSON value type to not be Numeric, got Fixnum"
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "provides a description message" do
|
62
62
|
matcher = have_json_type(String)
|
63
63
|
matcher.matches?(%({"id":1,"json":"spec"}))
|
64
64
|
matcher.description.should == %(have JSON type "String")
|
65
65
|
end
|
66
66
|
|
67
|
-
it "
|
67
|
+
it "provides a description message with path" do
|
68
68
|
matcher = have_json_type(String).at_path("json")
|
69
69
|
matcher.matches?(%({"id":1,"json":"spec"}))
|
70
70
|
matcher.description.should == %(have JSON type "String" at path "json")
|
@@ -23,7 +23,7 @@ describe JsonSpec::Matchers::IncludeJson do
|
|
23
23
|
json.should include_json(%({"two":2}))
|
24
24
|
end
|
25
25
|
|
26
|
-
it "matches
|
26
|
+
it "matches included hash values" do
|
27
27
|
json = %({"string":"one","integer":1,"float":1.0,"true":true,"false":false,"null":null})
|
28
28
|
json.should include_json(%("one"))
|
29
29
|
json.should include_json(%(1))
|
@@ -45,6 +45,12 @@ describe JsonSpec::Matchers::IncludeJson do
|
|
45
45
|
json.should include_json(%([5,6]))
|
46
46
|
end
|
47
47
|
|
48
|
+
it "matches a substring" do
|
49
|
+
json = %("json")
|
50
|
+
json.should include_json(%("js"))
|
51
|
+
json.should include_json(%("json"))
|
52
|
+
end
|
53
|
+
|
48
54
|
it "matches at a path" do
|
49
55
|
%({"one":{"two":[3,4]}}).should include_json(%([3,4])).at_path("one")
|
50
56
|
end
|
@@ -53,13 +59,13 @@ describe JsonSpec::Matchers::IncludeJson do
|
|
53
59
|
%([{"id":1,"two":3}]).should include_json(%({"two":3}))
|
54
60
|
end
|
55
61
|
|
56
|
-
it "
|
62
|
+
it "provides a description message" do
|
57
63
|
matcher = include_json(%({"json":"spec"}))
|
58
64
|
matcher.matches?(%({"id":1,"json":"spec"}))
|
59
65
|
matcher.description.should == "include JSON"
|
60
66
|
end
|
61
67
|
|
62
|
-
it "
|
68
|
+
it "provides a description message with path" do
|
63
69
|
matcher = include_json(%("spec")).at_path("json/0")
|
64
70
|
matcher.matches?(%({"id":1,"json":["spec"]}))
|
65
71
|
matcher.description.should == %(include JSON at path "json/0")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
|
-
rubygems_version: 1.8.
|
157
|
+
rubygems_version: 1.8.24
|
158
158
|
signing_key:
|
159
159
|
specification_version: 3
|
160
160
|
summary: Easily handle JSON in RSpec and Cucumber
|