assert_json 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +14 -0
- data/CHANGELOG.md +8 -0
- data/README.md +11 -8
- data/Rakefile +3 -4
- data/assert_json.gemspec +1 -0
- data/lib/assert_json/assert_json.rb +9 -5
- data/lib/assert_json/version.rb +1 -1
- data/test/assert_json_new_dsl_test.rb +70 -2
- data/test/assert_json_test.rb +2 -2
- data/test/test_helper.rb +1 -3
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MjhlOGNmZGE0YTlmYzA0YTIyYmM0MTVlMTlkMDZkYmMxMzBiZDVjYg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b01b0ad73c49c672ad096d20bc0c01989f47bd2f
|
4
|
+
data.tar.gz: 89aefc5f150b7955103a3099cca8a82ade7fa4a7
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTMzYzkyNzgzNmRkOTU0NWZiMTViNTE0NGQzNzA3NGI5ODFiYWM0Y2VlYTAy
|
11
|
-
ZDUxMThjMjE3YzJhMjU2MGFjZjc1ZTNiMjdkOWIxZjMzMjU0ZDM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YjlkZTk5NTQzOWU5MGQ3MjY1OGY4ZWNkMjkzMmJmZTg2YjY5Y2M3YjdiMzc2
|
14
|
-
ZTA3NzE3NjgxYjc5ZmEzMTYzZTNhODRjY2ZlODNhMWE1OTJjMmJkYmE2MmEw
|
15
|
-
ODRlYWZjYjU2OGZiMTk5NDk4MGFhNDUyYWRjN2FhYjA3YmI2MDI=
|
6
|
+
metadata.gz: d25fdba2cfa9776c19bb5ddc62cdae83b1fd3d603f8440c331b56c9f7849ae261c833e30bfaaecad0a06d00bc8ee069c58402508978829de381146df84e3a8ba
|
7
|
+
data.tar.gz: 39e7799b0c82bf725a396b187ef4f2596da1888d583dfeeb99e960d4dfb956e2b9c74aec6fc3546f23b4b30186fd881777533c4ec1c64e21b5052262e7ecd916
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.3.0 (not yet released)
|
4
|
+
|
5
|
+
* allow Ruby symbols as keys and values (thanks to [@pgaertig](https://github.com/pgaertig), see [issue 4](https://github.com/alto/assert_json/issues/4))
|
6
|
+
|
7
|
+
## 0.2.2
|
8
|
+
|
9
|
+
* allowing to validate real numbers (thanks to [@plu](https://github.com/plu), see [issue 6](https://github.com/alto/assert_json/pull/6))
|
10
|
+
|
3
11
|
## 0.2.1
|
4
12
|
|
5
13
|
* correctly match boolean and null values (thanks to [@pgaertig](https://github.com/pgaertig), see [issue 3](https://github.com/alto/assert_json/issues/3))
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# AssertJson #
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/alto/assert_json.svg?branch=master)](https://travis-ci.org/alto/assert_json)
|
4
|
+
|
3
5
|
Test your JSON strings.
|
4
6
|
|
5
7
|
## Installation ##
|
@@ -25,14 +27,15 @@ class MyActionTest < ActionController::TestCase
|
|
25
27
|
|
26
28
|
def test_my_action
|
27
29
|
get :my_action, :format => 'json'
|
28
|
-
# => @response.body= '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}]}'
|
30
|
+
# => @response.body= '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}, {'special-key': null}]}'
|
29
31
|
|
30
32
|
assert_json(@response.body) do
|
31
|
-
has
|
32
|
-
has
|
33
|
-
has
|
33
|
+
has :key do
|
34
|
+
has :inner_key1, 'value1'
|
35
|
+
has :inner_key2, /lue2/
|
34
36
|
end
|
35
|
-
|
37
|
+
has 'special-key', nil
|
38
|
+
has_not :key_not_included
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
@@ -45,9 +48,9 @@ use `item(i)` to select the item to test, like this
|
|
45
48
|
```ruby
|
46
49
|
assert_json '[{"id":1, "key":"test", "name":"test"}, {"id":2, "key":"test", "name":"test"}, {"id":3, "key":"test", "name":"test"}]' do
|
47
50
|
item 0 do
|
48
|
-
has
|
49
|
-
has
|
50
|
-
has
|
51
|
+
has :id, 1
|
52
|
+
has :key, 'test'
|
53
|
+
has :name, 'test'
|
51
54
|
end
|
52
55
|
item 2 do
|
53
56
|
has 'id', 3
|
data/Rakefile
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'bundler/gem_tasks'
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
4
3
|
|
5
4
|
require 'rake/testtask'
|
6
5
|
|
7
6
|
desc 'Test the assert_json plugin.'
|
8
7
|
Rake::TestTask.new(:test) do |t|
|
9
|
-
t.libs << 'lib'
|
8
|
+
t.libs << 'lib' << 'test'
|
10
9
|
t.pattern = 'test/**/*_test.rb'
|
11
10
|
t.verbose = true
|
12
11
|
end
|
data/assert_json.gemspec
CHANGED
@@ -44,14 +44,18 @@ module AssertJson
|
|
44
44
|
end
|
45
45
|
case token
|
46
46
|
when Hash
|
47
|
+
arg = arg.to_s
|
47
48
|
raise_error("element #{arg} not found") unless token.keys.include?(arg)
|
48
49
|
unless args.empty?
|
49
50
|
second_arg = args.shift
|
51
|
+
gen_error = lambda {raise_error("element #{token[arg].inspect} does not match #{second_arg.inspect}")}
|
50
52
|
case second_arg
|
51
53
|
when Regexp
|
52
|
-
|
54
|
+
gen_error.call if second_arg !~ token[arg].to_s
|
55
|
+
when Symbol
|
56
|
+
gen_error.call if second_arg.to_s != token[arg]
|
53
57
|
else
|
54
|
-
|
58
|
+
gen_error.call if second_arg != token[arg]
|
55
59
|
end
|
56
60
|
end
|
57
61
|
when Array
|
@@ -61,7 +65,7 @@ module AssertJson
|
|
61
65
|
when Regexp
|
62
66
|
raise_error("element #{arg.inspect} not found") if token !~ arg
|
63
67
|
else
|
64
|
-
raise_error("element #{arg.inspect} not found") if token != arg
|
68
|
+
raise_error("element #{arg.inspect} not found") if token != arg.to_s
|
65
69
|
end
|
66
70
|
when NilClass
|
67
71
|
raise_error("no element left")
|
@@ -86,9 +90,9 @@ module AssertJson
|
|
86
90
|
token = @decoded_json
|
87
91
|
case token
|
88
92
|
when Array
|
89
|
-
raise_error("element #{arg} found, but not expected") if token.include?(arg)
|
93
|
+
raise_error("element #{arg} found, but not expected") if token.include?(arg.to_s)
|
90
94
|
else
|
91
|
-
raise_error("element #{arg} found, but not expected") if token.keys.include?(arg)
|
95
|
+
raise_error("element #{arg} found, but not expected") if token.keys.include?(arg.to_s)
|
92
96
|
end
|
93
97
|
end
|
94
98
|
alias has_not not_element
|
data/lib/assert_json/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
class AssertJsonNewDslTest < Test
|
3
|
+
class AssertJsonNewDslTest < Minitest::Test
|
4
4
|
include AssertJson
|
5
5
|
|
6
6
|
def test_string
|
@@ -344,4 +344,72 @@ class AssertJsonNewDslTest < Test::Unit::TestCase
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
+
def test_symbol_as_a_value
|
348
|
+
assert_json '{"key": "text"}' do
|
349
|
+
has :key, :text
|
350
|
+
end
|
351
|
+
assert_raises(MiniTest::Assertion) do
|
352
|
+
assert_json '{"key": "badtext"}' do
|
353
|
+
has :key, :text
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_symbol_as_a_key
|
359
|
+
assert_json '{"sym": true, "text": "1"}' do
|
360
|
+
has :sym, true
|
361
|
+
has :text, /\d+/
|
362
|
+
has_not :bad_sym
|
363
|
+
end
|
364
|
+
assert_json '{"sym": false, "text": "2", "topkey": {"subkey": "value1"}}' do
|
365
|
+
has :sym, false
|
366
|
+
has :text, /\d+/
|
367
|
+
has_not :bad_sym
|
368
|
+
has :topkey do
|
369
|
+
has :subkey, :value1
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_symbol_as_string_value
|
375
|
+
assert_json '{"topkey": {"subkey": "value1"}}' do
|
376
|
+
has :topkey do
|
377
|
+
has :subkey do
|
378
|
+
has :value1
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
|
385
|
+
def test_symbol_as_a_key_crossheck
|
386
|
+
assert_raises(MiniTest::Assertion) do
|
387
|
+
assert_json '{"text": "1"}' do
|
388
|
+
has :sym, true #this should fail
|
389
|
+
has :text, /\d+/
|
390
|
+
has_not :bad_sym
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
assert_raises(MiniTest::Assertion) do
|
395
|
+
assert_json '{"sym": false, "text": "abc"}' do
|
396
|
+
has :sym, false
|
397
|
+
has :text, /\d+/ #this should fail
|
398
|
+
has_not :bad_sym
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
assert_raises(MiniTest::Assertion) do
|
403
|
+
assert_json '{"sym": false}' do
|
404
|
+
has_not :sym
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_regex_with_number
|
410
|
+
assert_json '{"number": 1}' do
|
411
|
+
has :number, /^\d+$/
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
347
415
|
end
|
data/test/assert_json_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorsten Böttger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - '>='
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - '>='
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
description: A gem to test JSON strings.
|
@@ -45,6 +59,7 @@ extensions: []
|
|
45
59
|
extra_rdoc_files: []
|
46
60
|
files:
|
47
61
|
- .gitignore
|
62
|
+
- .travis.yml
|
48
63
|
- CHANGELOG.md
|
49
64
|
- Gemfile
|
50
65
|
- MIT-LICENSE
|
@@ -67,17 +82,17 @@ require_paths:
|
|
67
82
|
- lib
|
68
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
84
|
requirements:
|
70
|
-
- -
|
85
|
+
- - '>='
|
71
86
|
- !ruby/object:Gem::Version
|
72
87
|
version: '0'
|
73
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
89
|
requirements:
|
75
|
-
- -
|
90
|
+
- - '>='
|
76
91
|
- !ruby/object:Gem::Version
|
77
92
|
version: '0'
|
78
93
|
requirements: []
|
79
94
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.1.11
|
81
96
|
signing_key:
|
82
97
|
specification_version: 4
|
83
98
|
summary: A gem to test JSON strings.
|