easy_json_matcher 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/lib/easy_json_matcher/array_validator.rb +8 -0
- data/lib/easy_json_matcher/boolean_validator.rb +9 -0
- data/lib/easy_json_matcher/content_wrapper.rb +18 -0
- data/lib/easy_json_matcher/date_validator.rb +35 -0
- data/lib/easy_json_matcher/node.rb +64 -0
- data/lib/easy_json_matcher/number_validator.rb +15 -0
- data/lib/easy_json_matcher/object_validator.rb +8 -0
- data/lib/easy_json_matcher/schema_generator.rb +49 -0
- data/lib/easy_json_matcher/string_validator.rb +10 -0
- data/lib/easy_json_matcher/validation_error.rb +8 -0
- data/lib/easy_json_matcher/validator.rb +19 -0
- data/lib/easy_json_matcher/validator_factory.rb +71 -0
- data/lib/easy_json_matcher/value_validator.rb +8 -0
- data/lib/easy_json_matcher/version.rb +3 -0
- data/lib/easy_json_matcher.rb +27 -0
- data/lib/tasks/jsonapi_matcher_tasks.rake +4 -0
- data/test/date_format_test.rb +0 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +7182 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/json_api_home.txt +76 -0
- data/test/jsonapi_matcher_test.rb +231 -0
- data/test/test_helper.rb +22 -0
- metadata +170 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,76 @@
|
|
1
|
+
{
|
2
|
+
"links": {
|
3
|
+
"self": "http://example.com/articles",
|
4
|
+
"next": "http://example.com/articles?page[offset]=2",
|
5
|
+
"last": "http://example.com/articles?page[offset]=10"
|
6
|
+
},
|
7
|
+
"data": [{
|
8
|
+
"type": "articles",
|
9
|
+
"id": "1",
|
10
|
+
"attributes": {
|
11
|
+
"title": "JSON API paints my bikeshed!"
|
12
|
+
},
|
13
|
+
"relationships": {
|
14
|
+
"author": {
|
15
|
+
"links": {
|
16
|
+
"self": "http://example.com/articles/1/relationships/author",
|
17
|
+
"related": "http://example.com/articles/1/author"
|
18
|
+
},
|
19
|
+
"data": { "type": "people", "id": "9" }
|
20
|
+
},
|
21
|
+
"comments": {
|
22
|
+
"links": {
|
23
|
+
"self": "http://example.com/articles/1/relationships/comments",
|
24
|
+
"related": "http://example.com/articles/1/comments"
|
25
|
+
},
|
26
|
+
"data": [
|
27
|
+
{ "type": "comments", "id": "5" },
|
28
|
+
{ "type": "comments", "id": "12" }
|
29
|
+
]
|
30
|
+
}
|
31
|
+
},
|
32
|
+
"links": {
|
33
|
+
"self": "http://example.com/articles/1"
|
34
|
+
}
|
35
|
+
}],
|
36
|
+
"included": [{
|
37
|
+
"type": "people",
|
38
|
+
"id": "9",
|
39
|
+
"attributes": {
|
40
|
+
"first-name": "Dan",
|
41
|
+
"last-name": "Gebhardt",
|
42
|
+
"twitter": "dgeb"
|
43
|
+
},
|
44
|
+
"links": {
|
45
|
+
"self": "http://example.com/people/9"
|
46
|
+
}
|
47
|
+
}, {
|
48
|
+
"type": "comments",
|
49
|
+
"id": "5",
|
50
|
+
"attributes": {
|
51
|
+
"body": "First!"
|
52
|
+
},
|
53
|
+
"relationships": {
|
54
|
+
"author": {
|
55
|
+
"data": { "type": "people", "id": "2" }
|
56
|
+
}
|
57
|
+
},
|
58
|
+
"links": {
|
59
|
+
"self": "http://example.com/comments/5"
|
60
|
+
}
|
61
|
+
}, {
|
62
|
+
"type": "comments",
|
63
|
+
"id": "12",
|
64
|
+
"attributes": {
|
65
|
+
"body": "I like XML better"
|
66
|
+
},
|
67
|
+
"relationships": {
|
68
|
+
"author": {
|
69
|
+
"data": { "type": "people", "id": "9" }
|
70
|
+
}
|
71
|
+
},
|
72
|
+
"links": {
|
73
|
+
"self": "http://example.com/comments/12"
|
74
|
+
}
|
75
|
+
}]
|
76
|
+
}
|
@@ -0,0 +1,231 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
|
5
|
+
class JsonapiMatcherTest < ActiveSupport::TestCase
|
6
|
+
|
7
|
+
test "As a user I want to create new Schemas to match JSON objects" do
|
8
|
+
# This test represents the minimum level of implementation required to create a
|
9
|
+
# working node.
|
10
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new { |schema|
|
11
|
+
schema.contains_node(key: :data) do |node|
|
12
|
+
node.has_attribute(key: :title, opts: {type: :string})
|
13
|
+
end
|
14
|
+
}.register(schema_name: :test)
|
15
|
+
|
16
|
+
valid_json = {
|
17
|
+
data: {
|
18
|
+
'title'=> "Here's a title"
|
19
|
+
}
|
20
|
+
}.to_json
|
21
|
+
assert(test_schema.valid? valid_json)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
test "As a user I want to be able to validate numbers" do
|
26
|
+
|
27
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new {|schema|
|
28
|
+
schema.has_attribute(key: :number, opts: {type: :number})
|
29
|
+
}.generate_node
|
30
|
+
|
31
|
+
valid_json = {
|
32
|
+
number: 5.55,
|
33
|
+
}.to_json
|
34
|
+
|
35
|
+
assert(test_schema.valid?(valid_json), "Number was not validated")
|
36
|
+
|
37
|
+
invalid_json = {
|
38
|
+
number: "hi"
|
39
|
+
}.to_json
|
40
|
+
assert_not(test_schema.valid?(invalid_json), "\"hi\" should not have been valid")
|
41
|
+
end
|
42
|
+
|
43
|
+
test "As a user I want to be able to validate booleans" do
|
44
|
+
|
45
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new {|schema|
|
46
|
+
schema.has_attribute(key: :true, opts: {type: :boolean})
|
47
|
+
schema.has_attribute(key: :false, opts: {type: :boolean})
|
48
|
+
}.generate_node
|
49
|
+
|
50
|
+
valid_json = {
|
51
|
+
true: true,
|
52
|
+
false: false
|
53
|
+
}.to_json
|
54
|
+
|
55
|
+
assert(test_schema.valid?(valid_json), "Boolean was not validated")
|
56
|
+
|
57
|
+
invalid_json = {
|
58
|
+
true: 1,
|
59
|
+
false: "wibble"
|
60
|
+
}
|
61
|
+
|
62
|
+
assert_not(test_schema.valid?(invalid_json), "\"1\" and \"wibble\" are not valid boolean values")
|
63
|
+
end
|
64
|
+
|
65
|
+
test "As a user I want to be able to validate Array values" do
|
66
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new {|schema|
|
67
|
+
schema.has_attribute(key: :array, opts: {type: :array})
|
68
|
+
}.generate_node
|
69
|
+
|
70
|
+
valid_json = {
|
71
|
+
array: []
|
72
|
+
}.to_json
|
73
|
+
|
74
|
+
assert(test_schema.valid?(valid_json), "Array was not validated")
|
75
|
+
|
76
|
+
invalid_json = {
|
77
|
+
array: 1
|
78
|
+
}.to_json
|
79
|
+
|
80
|
+
assert(!test_schema.valid?(invalid_json), "\"1\" is not a valid array value")
|
81
|
+
end
|
82
|
+
|
83
|
+
test "As a user I want to be able to specify what should be found in an array" do
|
84
|
+
flunk "Implement me"
|
85
|
+
end
|
86
|
+
|
87
|
+
test "As a user I want to be able to validate date values" do
|
88
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new { |schema|
|
89
|
+
schema.has_attribute(key: :date, opts: {type: :date})
|
90
|
+
}.generate_node
|
91
|
+
|
92
|
+
valid_json = {
|
93
|
+
date: "2015-01-15"
|
94
|
+
}.to_json
|
95
|
+
|
96
|
+
assert(test_schema.valid?(valid_json), "Date was not validated")
|
97
|
+
|
98
|
+
not_a_date = 'Good Night Mr. Tom'
|
99
|
+
invalid_json = {
|
100
|
+
date: not_a_date
|
101
|
+
}.to_json
|
102
|
+
|
103
|
+
assert_not(test_schema.valid?(invalid_json), "\"#{not_a_date}\" should not have been validated as a date")
|
104
|
+
end
|
105
|
+
|
106
|
+
test "As a user I want to be able to use different types of date format" do
|
107
|
+
flunk "Implement me"
|
108
|
+
end
|
109
|
+
|
110
|
+
test "As a user I want to validate object values" do
|
111
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new { |schema|
|
112
|
+
schema.has_attribute(key: :object, opts: {type: :object})
|
113
|
+
}.generate_node
|
114
|
+
|
115
|
+
is_an_object = {}
|
116
|
+
|
117
|
+
valid_json = {
|
118
|
+
object: is_an_object
|
119
|
+
}.to_json
|
120
|
+
|
121
|
+
assert(test_schema.valid?(valid_json),"#{is_an_object} was not validated as an object" )
|
122
|
+
|
123
|
+
not_an_object = "Popular Music"
|
124
|
+
|
125
|
+
invalid_json = {
|
126
|
+
object: not_an_object
|
127
|
+
}
|
128
|
+
|
129
|
+
assert_not(test_schema.valid?(invalid_json), "#{not_an_object} should not have validated as an object")
|
130
|
+
end
|
131
|
+
|
132
|
+
# Refers to validation of a JSON value attribute. This one is slightly tricky
|
133
|
+
# though since attempting to access a Ruby Hash with a missing key will return
|
134
|
+
# nil. The ValueValidator (or indeed any Validator) will accept nil as a value.
|
135
|
+
# However, if in future we want to implement the :required option then in the
|
136
|
+
# case of ValueValidator we will be stuck because for all of the other Validator
|
137
|
+
# classes nil indicates a missing value, but in the case of the ValueValidator
|
138
|
+
# we just want to check that there is a key available. It makes sense, therefore,
|
139
|
+
# to reverse the dependency such that the Node instance is passed to the Validator
|
140
|
+
# with its key and it then tests for the presence of the attribute and what it
|
141
|
+
# whether or not it is available
|
142
|
+
test "As a user I want to validate json value attributes" do
|
143
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new {|schema|
|
144
|
+
schema.has_attribute(key: :array, opts: {type: :value})
|
145
|
+
schema.has_attribute(key: :boolean, opts: {type: :value})
|
146
|
+
schema.has_attribute(key: :date, opts: {type: :value})
|
147
|
+
schema.has_attribute(key: :number, opts: {type: :value})
|
148
|
+
schema.has_attribute(key: :object, opts: {type: :value})
|
149
|
+
schema.has_attribute(key: :string, opts: {type: :value})
|
150
|
+
schema.has_attribute(key: :null, opts: {type: :value})
|
151
|
+
}.generate_node
|
152
|
+
|
153
|
+
|
154
|
+
valid_json = {
|
155
|
+
array: [],
|
156
|
+
boolean: true,
|
157
|
+
date: Date.today,
|
158
|
+
number: 1.11,
|
159
|
+
object: {},
|
160
|
+
string: 'The Tenderness of Wolves',
|
161
|
+
null: nil
|
162
|
+
}.to_json
|
163
|
+
|
164
|
+
assert(test_schema.valid?(valid_json), 'Value did not validate')
|
165
|
+
|
166
|
+
# There is no 'negative' test for this validator at this stage, since
|
167
|
+
# the lack of a value does not mean the key is required. See the tests
|
168
|
+
# on required validation later on.
|
169
|
+
end
|
170
|
+
|
171
|
+
test "As a user I want to validate nested json objects" do
|
172
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new {|schema|
|
173
|
+
schema.has_attribute(key: :level_1_attribute, opts: {type: :number})
|
174
|
+
schema.contains_node(key: :level_2) do |n|
|
175
|
+
n.has_attribute(key: :level_2_attribute, opts: {type: :number})
|
176
|
+
n.contains_node(key: :level_3) do |n3|
|
177
|
+
n3.has_attribute(key: :level_3_attribute, opts: {type: :number})
|
178
|
+
end
|
179
|
+
end
|
180
|
+
}.generate_node
|
181
|
+
|
182
|
+
valid_json = {
|
183
|
+
level_1_attribute: 1,
|
184
|
+
level_2:{
|
185
|
+
level_2_attribute: 2,
|
186
|
+
level_3:{
|
187
|
+
level_3_attribute: 3
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}.to_json
|
191
|
+
|
192
|
+
assert(test_schema.valid?(valid_json), "Nested JSON was not correctly validated")
|
193
|
+
end
|
194
|
+
|
195
|
+
test "As a user I want to be able to register a Schema so I can reuse it later" do
|
196
|
+
|
197
|
+
EasyJSONMatcher::SchemaGenerator.new { |schema|
|
198
|
+
schema.has_attribute(key: :ignore_me, opts: {type: :value})
|
199
|
+
}.register(schema_name: :test)
|
200
|
+
|
201
|
+
assert(EasyJSONMatcher.available_schemas.include?(:test), ":test not found in available_nodes")
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
test "As a user I want to know why my json was not valid" do
|
206
|
+
|
207
|
+
class Validator
|
208
|
+
def valid?(json)
|
209
|
+
raise EasyJSONMatcher::ValidationError.new ("Oops!!")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
test_schema = EasyJSONMatcher::SchemaGenerator.new { |schema|
|
214
|
+
schema.has_attribute(key: :oops, opts: {type: :value})
|
215
|
+
schema.contains_node(key: :nested_oops) do |node|
|
216
|
+
node.has_attribute(key: :bigger_oops, opts: {type: :value})
|
217
|
+
end
|
218
|
+
}.generate_node
|
219
|
+
|
220
|
+
# This JSON only reflects the structure of the above, it's validity is rendered
|
221
|
+
# irrelevant by our monkey-patch of Validator
|
222
|
+
valid_json = {
|
223
|
+
oops: 'oops',
|
224
|
+
nested_oops: {
|
225
|
+
bigger_oops: 'bigger_oops'
|
226
|
+
}
|
227
|
+
}
|
228
|
+
flunk "Implement me"
|
229
|
+
|
230
|
+
end
|
231
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pretty_backtrace/enable'
|
2
|
+
require 'mocha/mini_test'
|
3
|
+
# Configure Rails Environment
|
4
|
+
ENV["RAILS_ENV"] = "test"
|
5
|
+
|
6
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
7
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
8
|
+
require "rails/test_help"
|
9
|
+
|
10
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
11
|
+
# to be shown.
|
12
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
13
|
+
|
14
|
+
# Load support files
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
16
|
+
|
17
|
+
# Load fixtures from the engine
|
18
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
19
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
20
|
+
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
|
21
|
+
ActiveSupport::TestCase.fixtures :all
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_json_matcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- WJD Hamilton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.5.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
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
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: 'TBC: Description of JsonapiMatcher.'
|
42
|
+
email:
|
43
|
+
- wjdhamilton@hotmail.co.uk
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- Rakefile
|
50
|
+
- lib/easy_json_matcher.rb
|
51
|
+
- lib/easy_json_matcher/array_validator.rb
|
52
|
+
- lib/easy_json_matcher/boolean_validator.rb
|
53
|
+
- lib/easy_json_matcher/content_wrapper.rb
|
54
|
+
- lib/easy_json_matcher/date_validator.rb
|
55
|
+
- lib/easy_json_matcher/node.rb
|
56
|
+
- lib/easy_json_matcher/number_validator.rb
|
57
|
+
- lib/easy_json_matcher/object_validator.rb
|
58
|
+
- lib/easy_json_matcher/schema_generator.rb
|
59
|
+
- lib/easy_json_matcher/string_validator.rb
|
60
|
+
- lib/easy_json_matcher/validation_error.rb
|
61
|
+
- lib/easy_json_matcher/validator.rb
|
62
|
+
- lib/easy_json_matcher/validator_factory.rb
|
63
|
+
- lib/easy_json_matcher/value_validator.rb
|
64
|
+
- lib/easy_json_matcher/version.rb
|
65
|
+
- lib/tasks/jsonapi_matcher_tasks.rake
|
66
|
+
- test/date_format_test.rb
|
67
|
+
- test/dummy/README.rdoc
|
68
|
+
- test/dummy/Rakefile
|
69
|
+
- test/dummy/app/assets/javascripts/application.js
|
70
|
+
- test/dummy/app/assets/stylesheets/application.css
|
71
|
+
- test/dummy/app/controllers/application_controller.rb
|
72
|
+
- test/dummy/app/helpers/application_helper.rb
|
73
|
+
- test/dummy/app/views/layouts/application.html.erb
|
74
|
+
- test/dummy/bin/bundle
|
75
|
+
- test/dummy/bin/rails
|
76
|
+
- test/dummy/bin/rake
|
77
|
+
- test/dummy/bin/setup
|
78
|
+
- test/dummy/config.ru
|
79
|
+
- test/dummy/config/application.rb
|
80
|
+
- test/dummy/config/boot.rb
|
81
|
+
- test/dummy/config/database.yml
|
82
|
+
- test/dummy/config/environment.rb
|
83
|
+
- test/dummy/config/environments/development.rb
|
84
|
+
- test/dummy/config/environments/production.rb
|
85
|
+
- test/dummy/config/environments/test.rb
|
86
|
+
- test/dummy/config/initializers/assets.rb
|
87
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
88
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
89
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
90
|
+
- test/dummy/config/initializers/inflections.rb
|
91
|
+
- test/dummy/config/initializers/mime_types.rb
|
92
|
+
- test/dummy/config/initializers/session_store.rb
|
93
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
94
|
+
- test/dummy/config/locales/en.yml
|
95
|
+
- test/dummy/config/routes.rb
|
96
|
+
- test/dummy/config/secrets.yml
|
97
|
+
- test/dummy/db/test.sqlite3
|
98
|
+
- test/dummy/log/test.log
|
99
|
+
- test/dummy/public/404.html
|
100
|
+
- test/dummy/public/422.html
|
101
|
+
- test/dummy/public/500.html
|
102
|
+
- test/dummy/public/favicon.ico
|
103
|
+
- test/json_api_home.txt
|
104
|
+
- test/jsonapi_matcher_test.rb
|
105
|
+
- test/test_helper.rb
|
106
|
+
homepage: https://github.com/wjdhamilton/easy-json-matcher
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Easily test your JSON output with templates and Schemas
|
130
|
+
test_files:
|
131
|
+
- test/date_format_test.rb
|
132
|
+
- test/json_api_home.txt
|
133
|
+
- test/test_helper.rb
|
134
|
+
- test/jsonapi_matcher_test.rb
|
135
|
+
- test/dummy/config.ru
|
136
|
+
- test/dummy/bin/rails
|
137
|
+
- test/dummy/bin/bundle
|
138
|
+
- test/dummy/bin/setup
|
139
|
+
- test/dummy/bin/rake
|
140
|
+
- test/dummy/config/initializers/inflections.rb
|
141
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
142
|
+
- test/dummy/config/initializers/assets.rb
|
143
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
144
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
145
|
+
- test/dummy/config/initializers/mime_types.rb
|
146
|
+
- test/dummy/config/initializers/session_store.rb
|
147
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
148
|
+
- test/dummy/config/secrets.yml
|
149
|
+
- test/dummy/config/database.yml
|
150
|
+
- test/dummy/config/application.rb
|
151
|
+
- test/dummy/config/environments/test.rb
|
152
|
+
- test/dummy/config/environments/development.rb
|
153
|
+
- test/dummy/config/environments/production.rb
|
154
|
+
- test/dummy/config/locales/en.yml
|
155
|
+
- test/dummy/config/environment.rb
|
156
|
+
- test/dummy/config/boot.rb
|
157
|
+
- test/dummy/config/routes.rb
|
158
|
+
- test/dummy/db/test.sqlite3
|
159
|
+
- test/dummy/app/assets/javascripts/application.js
|
160
|
+
- test/dummy/app/assets/stylesheets/application.css
|
161
|
+
- test/dummy/app/views/layouts/application.html.erb
|
162
|
+
- test/dummy/app/helpers/application_helper.rb
|
163
|
+
- test/dummy/app/controllers/application_controller.rb
|
164
|
+
- test/dummy/Rakefile
|
165
|
+
- test/dummy/public/404.html
|
166
|
+
- test/dummy/public/422.html
|
167
|
+
- test/dummy/public/500.html
|
168
|
+
- test/dummy/public/favicon.ico
|
169
|
+
- test/dummy/README.rdoc
|
170
|
+
- test/dummy/log/test.log
|