json_schema_power_validator 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06fcc8aa4f8d7fc45dbdddd8a35c74e937a1479a
4
- data.tar.gz: f031b1619b76312287ea55d848b9a4ea7a22f188
3
+ metadata.gz: 217f235573a81f3d22ebb64633f775e1fbe3a9f9
4
+ data.tar.gz: a0b7ac78f8beac81d279b74729b555299c279bec
5
5
  SHA512:
6
- metadata.gz: 474b829ca277ef7da0aef946331d326222b8194ff37e584a794fadb3ffe1380ff94595af97074a2d9bccca1548096d09bf58758d132c2b58f8a87b131f3be8b7
7
- data.tar.gz: cbde5b9b928923862f11e97c69d8dbb9cc7d1f23d46f02f29775097ff304a7c42578edfa9249b9e6168a6d5a8e863c8f3c2b6aabd7b0c35331153f599269afa6
6
+ metadata.gz: 260a86c6ffa094e83778a21349db4697f55d942b6954dda5e3bcc9b7f1cb03fc1e445e3aa9656d36ebd05940b6cae6805e5af5f56f13289c5fa9179f6fda2641
7
+ data.tar.gz: fd07b1aa717066dba3b93fb87220e01b3634c957e8ed236f84a860eab3ab6fefebb6417139c97a7759f35f63c56f90928a8ad7a20d37ed015550718d447d884d
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /vendor/bundle/
11
+ .DS_Store
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in json_schema_spec.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'test-unit'
8
+ end
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # JsonSchema::PowerValidator
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/json_schema_power_validator`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Test JSON Schema itself with contexts.
4
+ After preparation of schema and test suite, you can test schema response.
5
+ It'll display each results with json format.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,62 +22,39 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- ```json
26
- {
27
- "id": "https://github.com/timakin/json_schema_power_validator/schema/sample.json",
28
- "$schema": "http://json-schema.org/draft-04/schema#",
29
- "description": "Test schema for example",
30
- "definitions": {
31
- "positiveInt": {
32
- "type": "integer",
33
- "minimum": 0
34
- },
35
- "name": {
36
- "type": "string",
37
- "minimumLength": 4,
38
- "maximumLength": 12
39
- }
40
- },
41
- "type": "object",
42
- "properties": {
43
- "id": {
44
- "$ref": "#/definitions/positiveInt"
45
- },
46
- "username": {
47
- "$ref": "#/definitions/name"
48
- }
49
- }
50
- }
51
- ```
25
+ Prepare json schema you'd like to test and test suite.
26
+ A test suite must be written on the fixed format.
27
+ The suite must include parameters:
28
+
29
+ - examples - Array of test cases, and each of them should include following parameters
30
+ - context - Title of each test
31
+ - description - Detail of the test
32
+ - expect - Expectation of a result of test (it must be "valid"/"invalid")
33
+ - values - Parameters that'll be used as test values.
34
+
35
+ The below json is the example of test suite on the above format.
52
36
 
53
37
  ```json
54
38
  {
55
- "id": "https://github.com/timakin/json_schema_power_validator/schema/suite/sample.json",
56
- "description": "Schema PowerValidator for example.json",
57
39
  "examples": [
58
40
  {
59
41
  "context": "Success",
60
42
  "description": "Success Case",
61
43
  "expect": "valid",
62
44
  "values": {
63
- "id": 1,
64
- "username": "timakin"
45
+ "id": 1234,
46
+ "name": "timakin",
47
+ ...
65
48
  }
66
49
  },
67
50
  { ... },
68
- {
69
- "context": "Fail",
70
- "description": "fail",
71
- "expect": "valid",
72
- "values": {
73
- "id": -100,
74
- "username": "tim"
75
- }
76
- }
51
+ { ... }
77
52
  ]
78
53
  }
79
54
  ```
80
55
 
56
+ With the suite, you can get a detail error message, and check whether the results are all clear or not.
57
+
81
58
  ```ruby
82
59
  require 'json_schema_power_validator'
83
60
 
@@ -90,11 +67,11 @@ validated_schema.get_result
90
67
  # "description": "Success Case",
91
68
  # "result": "success"
92
69
  # },
93
- # { ... }
70
+ # { ... },
94
71
  # {
95
72
  # "context": "Fail",
96
- # "description": "fail"
97
- # "reason": "Invalid parameter: id should satisfy the condition minimumLength"
73
+ # "description": "Failed Case",
74
+ # "result": "The property '#/id' did not have a minimum value of 0, inclusively"
98
75
  # }
99
76
  # ]
100
77
  #}
@@ -109,6 +86,16 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
109
86
 
110
87
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
111
88
 
89
+ ## Test
90
+
91
+ To run test:
92
+
93
+ ```
94
+ $ cd /path/to/repository
95
+ $ bundle install --path vendor/bundle
96
+ $ bundle exec ruby spec/json_schema_power_validator_spec.rb
97
+ ```
98
+
112
99
  ## Contributing
113
100
 
114
101
  1. Fork it ( https://github.com/timakin/json_schema_power_validator/fork )
@@ -1,4 +1,5 @@
1
1
  require "json_schema_power_validator/version"
2
+ require "json_schema_power_validator/errors/parse_suite_error"
2
3
  require "json-schema"
3
4
 
4
5
  module JsonSchema
@@ -22,6 +23,8 @@ module JsonSchema
22
23
  private
23
24
 
24
25
  def validate
26
+ verify_suite_parameters
27
+
25
28
  @suites["examples"].each do |suite|
26
29
  begin
27
30
  JSON::Validator.validate!(@schema, suite["values"])
@@ -30,9 +33,24 @@ module JsonSchema
30
33
  suite["expect"] == "invalid" ? @raw_results.push("Success") : @raw_results.push($!.message)
31
34
  end
32
35
  end
36
+
33
37
  get_result_by_json
34
38
  end
35
39
 
40
+ def verify_suite_parameters
41
+ unless @suites["examples"]
42
+ raise ParseSuiteError.new("examples for a test suite is undefined, or format is invalid.")
43
+ end
44
+
45
+ @suites["examples"].each do |suite|
46
+ ["context", "description", "expect", "values"].each do |param|
47
+ if suite[param].nil?
48
+ raise ParseSuiteError.new("#{param} for a test suite is undefined.")
49
+ end
50
+ end
51
+ end
52
+ end
53
+
36
54
  def get_result_by_json
37
55
  @raw_results.each_with_index { |result, index|
38
56
  @result_json << {
@@ -0,0 +1,4 @@
1
+ module JsonSchema
2
+ class ParseSuiteError < StandardError
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module JsonSchema
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema_power_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - timakin
@@ -68,6 +68,7 @@ files:
68
68
  - bin/setup
69
69
  - json_schema_power_validator.gemspec
70
70
  - lib/json_schema_power_validator.rb
71
+ - lib/json_schema_power_validator/errors/parse_suite_error.rb
71
72
  - lib/json_schema_power_validator/version.rb
72
73
  homepage: https://github.com/timakin/json_schema_power_validator
73
74
  licenses: