json_spec 1.1.4 → 1.1.5
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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +8 -0
- data/Rakefile +3 -1
- data/json_spec.gemspec +1 -1
- data/lib/json_spec/configuration.rb +2 -7
- data/lib/json_spec/matchers/be_json_eql.rb +1 -0
- data/lib/json_spec/matchers/have_json_size.rb +1 -0
- data/lib/json_spec/matchers/have_json_type.rb +1 -0
- data/lib/json_spec/matchers/include_json.rb +1 -0
- data/spec/json_spec/configuration_spec.rb +10 -10
- data/spec/json_spec/helpers_spec.rb +15 -15
- data/spec/json_spec/matchers/be_json_eql_spec.rb +3 -1
- data/spec/json_spec/matchers/have_json_size_spec.rb +6 -6
- data/spec/json_spec/matchers/have_json_type_spec.rb +6 -6
- data/spec/json_spec/matchers/include_json_spec.rb +3 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a1c0fcfcd1630fe44a795106af21ceef630600
|
4
|
+
data.tar.gz: 435c1191fc28f12c184cc15de540096b17712d1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc4126f5010185650d7aabdd0d934a026b7d9c2526eda3c6b71404261634fa4e68a5d4c8d62a6148ca3014d0225e6041ef07194aed647fc0bbc2ff187088128f
|
7
|
+
data.tar.gz: e0554b32b24c9faef17ca12e2ad49bfccc7c23061428335d990695663d68f42c399b8861cff5caa6a7f758453e375f821a76b2a0138b26eb806c33a173b74c67
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
## Unreleased (master)
|
2
|
+
|
3
|
+
- Added Changelog
|
4
|
+
- Fix RSpec warnings for uninitialized instance variables on matchers [#78](https://github.com/collectiveidea/json_spec/pull/78)
|
5
|
+
|
6
|
+
## Version 1.1.4
|
7
|
+
|
8
|
+
- Raise error when checking a size of a json ruby value of nil [#82](https://github.com/collectiveidea/json_spec/pull/82)
|
data/Rakefile
CHANGED
@@ -2,7 +2,9 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
require "cucumber/rake/task"
|
4
4
|
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
6
|
+
task.rspec_opts = "--warnings"
|
7
|
+
end
|
6
8
|
|
7
9
|
Cucumber::Rake::Task.new(:cucumber) do |task|
|
8
10
|
task.cucumber_opts = "--tags ~@fail"
|
data/json_spec.gemspec
CHANGED
@@ -4,6 +4,8 @@ module JsonSpec
|
|
4
4
|
module Configuration
|
5
5
|
DEFAULT_EXCLUDED_KEYS = %w(id created_at updated_at)
|
6
6
|
|
7
|
+
attr_accessor :directory
|
8
|
+
|
7
9
|
def configure(&block)
|
8
10
|
instance_eval(&block)
|
9
11
|
end
|
@@ -20,13 +22,6 @@ module JsonSpec
|
|
20
22
|
self.excluded_keys = keys
|
21
23
|
end
|
22
24
|
|
23
|
-
def directory
|
24
|
-
@directory
|
25
|
-
end
|
26
|
-
|
27
|
-
def directory=(directory)
|
28
|
-
@directory = directory
|
29
|
-
end
|
30
25
|
|
31
26
|
def reset
|
32
27
|
instance_variables.each { |ivar| remove_instance_variable(ivar) }
|
@@ -2,52 +2,52 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe JsonSpec::Configuration do
|
4
4
|
it "excludes id and timestamps by default" do
|
5
|
-
JsonSpec.excluded_keys.should
|
5
|
+
JsonSpec.excluded_keys.should eq ["id", "created_at", "updated_at"]
|
6
6
|
end
|
7
7
|
|
8
8
|
it "excludes custom keys" do
|
9
9
|
JsonSpec.exclude_keys("token")
|
10
|
-
JsonSpec.excluded_keys.should
|
10
|
+
JsonSpec.excluded_keys.should eq ["token"]
|
11
11
|
end
|
12
12
|
|
13
13
|
it "excludes custom keys via setter" do
|
14
14
|
JsonSpec.excluded_keys = ["token"]
|
15
|
-
JsonSpec.excluded_keys.should
|
15
|
+
JsonSpec.excluded_keys.should eq ["token"]
|
16
16
|
end
|
17
17
|
|
18
18
|
it "excludes custom keys via block" do
|
19
19
|
JsonSpec.configure { |c| c.exclude_keys("token") }
|
20
|
-
JsonSpec.excluded_keys.should
|
20
|
+
JsonSpec.excluded_keys.should eq ["token"]
|
21
21
|
end
|
22
22
|
|
23
23
|
it "excludes custom keys via block setter" do
|
24
24
|
JsonSpec.configure { |c| c.excluded_keys = ["token"] }
|
25
|
-
JsonSpec.excluded_keys.should
|
25
|
+
JsonSpec.excluded_keys.should eq ["token"]
|
26
26
|
end
|
27
27
|
|
28
28
|
it "excludes custom keys via instance-evaluated block" do
|
29
29
|
JsonSpec.configure{ exclude_keys("token") }
|
30
|
-
JsonSpec.excluded_keys.should
|
30
|
+
JsonSpec.excluded_keys.should eq ["token"]
|
31
31
|
end
|
32
32
|
|
33
33
|
it "ensures its excluded keys are strings" do
|
34
34
|
JsonSpec.exclude_keys(:token)
|
35
|
-
JsonSpec.excluded_keys.should
|
35
|
+
JsonSpec.excluded_keys.should eq ["token"]
|
36
36
|
end
|
37
37
|
|
38
38
|
it "ensures its excluded keys are unique" do
|
39
39
|
JsonSpec.exclude_keys("token", :token)
|
40
|
-
JsonSpec.excluded_keys.should
|
40
|
+
JsonSpec.excluded_keys.should eq ["token"]
|
41
41
|
end
|
42
42
|
|
43
43
|
it "resets its excluded keys" do
|
44
44
|
original = JsonSpec.excluded_keys
|
45
45
|
|
46
46
|
JsonSpec.exclude_keys("token")
|
47
|
-
JsonSpec.excluded_keys.should_not
|
47
|
+
JsonSpec.excluded_keys.should_not eq original
|
48
48
|
|
49
49
|
JsonSpec.reset
|
50
|
-
JsonSpec.excluded_keys.should
|
50
|
+
JsonSpec.excluded_keys.should eq original
|
51
51
|
end
|
52
52
|
|
53
53
|
it "resets its directory" do
|
@@ -5,11 +5,11 @@ describe JsonSpec::Helpers do
|
|
5
5
|
|
6
6
|
context "parse_json" do
|
7
7
|
it "parses JSON documents" do
|
8
|
-
parse_json(%({"json":["spec"]})).should
|
8
|
+
parse_json(%({"json":["spec"]})).should eq({"json" => ["spec"]})
|
9
9
|
end
|
10
10
|
|
11
11
|
it "parses JSON values" do
|
12
|
-
parse_json(%("json_spec")).should
|
12
|
+
parse_json(%("json_spec")).should eq "json_spec"
|
13
13
|
end
|
14
14
|
|
15
15
|
it "raises a parser error for invalid JSON" do
|
@@ -18,8 +18,8 @@ describe JsonSpec::Helpers do
|
|
18
18
|
|
19
19
|
it "parses at a path if given" do
|
20
20
|
json = %({"json":["spec"]})
|
21
|
-
parse_json(json, "json").should
|
22
|
-
parse_json(json, "json/0").should
|
21
|
+
parse_json(json, "json").should eq ["spec"]
|
22
|
+
parse_json(json, "json/0").should eq "spec"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "raises an error for a missing path" do
|
@@ -31,7 +31,7 @@ describe JsonSpec::Helpers do
|
|
31
31
|
|
32
32
|
it "parses at a numeric string path" do
|
33
33
|
json = %({"1":"two"})
|
34
|
-
parse_json(
|
34
|
+
parse_json(json, "1").should eq "two"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -44,19 +44,19 @@ describe JsonSpec::Helpers do
|
|
44
44
|
]
|
45
45
|
}
|
46
46
|
JSON
|
47
|
-
normalize_json(%({"json":["spec"]})).should
|
47
|
+
normalize_json(%({"json":["spec"]})).should eq normalized.chomp
|
48
48
|
end
|
49
49
|
|
50
50
|
it "normalizes at a path" do
|
51
|
-
normalize_json(%({"json":["spec"]}), "json/0").should
|
51
|
+
normalize_json(%({"json":["spec"]}), "json/0").should eq %("spec")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "accepts a JSON value" do
|
55
|
-
normalize_json(%("json_spec")).should
|
55
|
+
normalize_json(%("json_spec")).should eq %("json_spec")
|
56
56
|
end
|
57
57
|
|
58
58
|
it "normalizes JSON values" do
|
59
|
-
normalize_json(%(1e+1)).should
|
59
|
+
normalize_json(%(1e+1)).should eq %(10.0)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -69,11 +69,11 @@ describe JsonSpec::Helpers do
|
|
69
69
|
]
|
70
70
|
}
|
71
71
|
JSON
|
72
|
-
generate_normalized_json({"json" => ["spec"]}).should
|
72
|
+
generate_normalized_json({"json" => ["spec"]}).should eq normalized.chomp
|
73
73
|
end
|
74
74
|
|
75
75
|
it "generates a normalized JSON value" do
|
76
|
-
generate_normalized_json(nil).should
|
76
|
+
generate_normalized_json(nil).should eq %(null)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -84,12 +84,12 @@ describe JsonSpec::Helpers do
|
|
84
84
|
|
85
85
|
it "returns JSON when the file exists" do
|
86
86
|
JsonSpec.directory = files_path
|
87
|
-
load_json("one.json").should
|
87
|
+
load_json("one.json").should eq %({"value":"from_file"})
|
88
88
|
end
|
89
89
|
|
90
90
|
it "ignores extra slashes" do
|
91
91
|
JsonSpec.directory = "/#{files_path}/"
|
92
|
-
load_json("one.json").should
|
92
|
+
load_json("one.json").should eq %({"value":"from_file"})
|
93
93
|
end
|
94
94
|
|
95
95
|
it "raises an error when the file doesn't exist" do
|
@@ -104,8 +104,8 @@ describe JsonSpec::Helpers do
|
|
104
104
|
|
105
105
|
it "finds nested files" do
|
106
106
|
JsonSpec.directory = files_path
|
107
|
-
load_json("project/one.json").should
|
108
|
-
load_json("project/version/one.json").should
|
107
|
+
load_json("project/one.json").should eq %({"nested":"inside_folder"})
|
108
|
+
load_json("project/version/one.json").should eq %({"nested":"deeply"})
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
@@ -99,7 +99,9 @@ describe JsonSpec::Matchers::BeJsonEql do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it "raises an error when not given expected JSON" do
|
102
|
-
expect{ %({"id":1,"json":"spec"}).should be_json_eql }.to raise_error
|
102
|
+
expect{ %({"id":1,"json":"spec"}).should be_json_eql }.to raise_error do |error|
|
103
|
+
error.message.should == "Expected equivalent JSON not provided"
|
104
|
+
end
|
103
105
|
end
|
104
106
|
|
105
107
|
it "matches file contents" do
|
@@ -24,27 +24,27 @@ describe JsonSpec::Matchers::HaveJsonSize do
|
|
24
24
|
it "provides a failure message" do
|
25
25
|
matcher = have_json_size(3)
|
26
26
|
matcher.matches?(%([1,2]))
|
27
|
-
matcher.failure_message.should
|
28
|
-
matcher.failure_message_for_should.should
|
27
|
+
matcher.failure_message.should eq "Expected JSON value size to be 3, got 2"
|
28
|
+
matcher.failure_message_for_should.should eq "Expected JSON value size to be 3, got 2" # RSpec 2 interface
|
29
29
|
end
|
30
30
|
|
31
31
|
it "provides a failure message for negation" do
|
32
32
|
matcher = have_json_size(3)
|
33
33
|
matcher.matches?(%([1,2,3]))
|
34
|
-
matcher.failure_message_when_negated.should
|
35
|
-
matcher.failure_message_for_should_not.should
|
34
|
+
matcher.failure_message_when_negated.should eq "Expected JSON value size to not be 3, got 3"
|
35
|
+
matcher.failure_message_for_should_not.should eq "Expected JSON value size to not be 3, got 3" # RSpec 2 interface
|
36
36
|
end
|
37
37
|
|
38
38
|
it "provides a description message" do
|
39
39
|
matcher = have_json_size(1)
|
40
40
|
matcher.matches?(%({"id":1,"json":["spec"]}))
|
41
|
-
matcher.description.should
|
41
|
+
matcher.description.should eq %(have JSON size "1")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "provides a description message with path" do
|
45
45
|
matcher = have_json_size(1).at_path("json")
|
46
46
|
matcher.matches?(%({"id":1,"json":["spec"]}))
|
47
|
-
matcher.description.should
|
47
|
+
matcher.description.should eq %(have JSON size "1" at path "json")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "provides an error when parsing nil" do
|
@@ -49,27 +49,27 @@ describe JsonSpec::Matchers::HaveJsonType do
|
|
49
49
|
it "provides a failure message" do
|
50
50
|
matcher = have_json_type(Numeric)
|
51
51
|
matcher.matches?(%("foo"))
|
52
|
-
matcher.failure_message.should
|
53
|
-
matcher.failure_message_for_should.should
|
52
|
+
matcher.failure_message.should eq "Expected JSON value type to be Numeric, got String"
|
53
|
+
matcher.failure_message_for_should.should eq "Expected JSON value type to be Numeric, got String" # RSpec 2 interface
|
54
54
|
end
|
55
55
|
|
56
56
|
it "provides a failure message for negation" do
|
57
57
|
matcher = have_json_type(Numeric)
|
58
58
|
matcher.matches?(%(10))
|
59
|
-
matcher.failure_message_when_negated.should
|
60
|
-
matcher.failure_message_for_should_not.should
|
59
|
+
matcher.failure_message_when_negated.should eq "Expected JSON value type to not be Numeric, got Fixnum"
|
60
|
+
matcher.failure_message_for_should_not.should eq "Expected JSON value type to not be Numeric, got Fixnum" # RSpec 2 interface
|
61
61
|
end
|
62
62
|
|
63
63
|
it "provides a description message" do
|
64
64
|
matcher = have_json_type(String)
|
65
65
|
matcher.matches?(%({"id":1,"json":"spec"}))
|
66
|
-
matcher.description.should
|
66
|
+
matcher.description.should eq %(have JSON type "String")
|
67
67
|
end
|
68
68
|
|
69
69
|
it "provides a description message with path" do
|
70
70
|
matcher = have_json_type(String).at_path("json")
|
71
71
|
matcher.matches?(%({"id":1,"json":"spec"}))
|
72
|
-
matcher.description.should
|
72
|
+
matcher.description.should eq %(have JSON type "String" at path "json")
|
73
73
|
end
|
74
74
|
|
75
75
|
context "somewhat uselessly" do
|
@@ -84,7 +84,9 @@ describe JsonSpec::Matchers::IncludeJson do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "raises an error when not given expected JSON" do
|
87
|
-
expect{ %([{"id":1,"two":3}]).should include_json }.to raise_error
|
87
|
+
expect{ %([{"id":1,"two":3}]).should include_json }.to raise_error do |error|
|
88
|
+
error.message.should == "Expected included JSON not provided"
|
89
|
+
end
|
88
90
|
end
|
89
91
|
|
90
92
|
it "matches file contents" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Richert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -81,6 +81,7 @@ extra_rdoc_files: []
|
|
81
81
|
files:
|
82
82
|
- ".gitignore"
|
83
83
|
- ".travis.yml"
|
84
|
+
- CHANGELOG.md
|
84
85
|
- Gemfile
|
85
86
|
- LICENSE.txt
|
86
87
|
- README.md
|
@@ -147,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
version: '0'
|
148
149
|
requirements: []
|
149
150
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.6.11
|
151
152
|
signing_key:
|
152
153
|
specification_version: 4
|
153
154
|
summary: Easily handle JSON in RSpec and Cucumber
|