json_spec 1.1.3 → 1.1.4

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: 98cdb5ce2f62a93c0ba56565fceea1f93a7d1d1e
4
- data.tar.gz: 149b6060bc8514bcd6ad856e7ef748d622414f0b
3
+ metadata.gz: 1f89c2ff2fad3cd8fc443551ea7d118d7ae865ed
4
+ data.tar.gz: 999fffbcd5db02290e7bd36762bee3c7e3e50c69
5
5
  SHA512:
6
- metadata.gz: 0c6d9cad2a54c5485f142bc581a789d495542e7a4fee7ed385c6e1e147ec0a374486f673718e8dfeb1ad1feccb471ea09247c1500a8bb0907ac76d617d9be0d0
7
- data.tar.gz: c4c4b16b051f2af4fe1e09151c6c6bbcd26c6f348db1ee3ccf06c784fbac9970708deec2b8386ce2ab63d3711621188d5d6a08f7a5a0a61b64f92d450f7932ee
6
+ metadata.gz: aa4a0d179b15d62a16e11e16fbabda7dd642e7015903964b17c51846e21273f4904555e641c20ffade46301bc1e5277cd96df2efb2c7e74c38d31e78c39ca245
7
+ data.tar.gz: 6b7f34cd9a5b8f326976e6335c64b93f63cd0d0fb0d204e04606013e3e6d1b8fae055f889543ba50ce08fb77cf07373c090f6d9deb0252b5b1c76bedee4fb2f6
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "json_spec"
5
- gem.version = "1.1.3"
5
+ gem.version = "1.1.4"
6
6
 
7
7
  gem.authors = ["Steve Richert"]
8
8
  gem.email = ["steve.richert@gmail.com"]
@@ -31,4 +31,16 @@ module JsonSpec
31
31
  "No JSON file at #{path}"
32
32
  end
33
33
  end
34
+
35
+ class EnumerableExpected < Error
36
+ attr_reader :actual_value
37
+
38
+ def initialize(actual_value)
39
+ @actual_value = actual_value
40
+ end
41
+
42
+ def to_s
43
+ "Enumerable expected, got #{actual_value.inspect}"
44
+ end
45
+ end
34
46
  end
@@ -10,7 +10,8 @@ module JsonSpec
10
10
 
11
11
  def matches?(json)
12
12
  ruby = parse_json(json, @path)
13
- @actual = Enumerable === ruby ? ruby.size : 1
13
+ raise EnumerableExpected.new(ruby) unless Enumerable === ruby
14
+ @actual = ruby.size
14
15
  @actual == @expected
15
16
  end
16
17
 
@@ -46,4 +46,16 @@ describe JsonSpec::Matchers::HaveJsonSize do
46
46
  matcher.matches?(%({"id":1,"json":["spec"]}))
47
47
  matcher.description.should == %(have JSON size "1" at path "json")
48
48
  end
49
+
50
+ it "provides an error when parsing nil" do
51
+ matcher = have_json_size(0).at_path("json")
52
+ expect { matcher.matches?(%({"id":1,"json":null})) }.to raise_error(JsonSpec::EnumerableExpected,
53
+ "Enumerable expected, got nil")
54
+ end
55
+
56
+ it "provides an error when parsing non-enumerables" do
57
+ matcher = have_json_size(0).at_path("json")
58
+ expect { matcher.matches?(%({"id":1,"json":12345})) }.to raise_error(JsonSpec::EnumerableExpected,
59
+ "Enumerable expected, got 12345")
60
+ end
49
61
  end
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.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Richert