rspec_json_schema_matcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c21d41faef5b0c35209ee8f6688d1ee07e88d8a
4
+ data.tar.gz: 7c926063ec39b2584b6ab0a0ca96f0b0e95766c0
5
+ SHA512:
6
+ metadata.gz: d78eaea305ac45aaeda64b144d5322ef42f056d22a54d42a52378748ec93f67102c717a940d313418bfe9364b8da54ab0c1f71e6da2d407e494c9d57be36e4e6
7
+ data.tar.gz: 95aa5560e69456d22126f80dc427524c2c417b9706561e778e4ca4b7f49eea095b3d3e9dc85ca82543a04ddb336c9e7259285d5d3ee800c2a2007730dfa899e4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0-p598
4
+ - 2.1.6
5
+ - 2.2.2
6
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec_json_schema_matcher.gemspec
4
+ gemspec
data/LICENSING.md ADDED
@@ -0,0 +1,16 @@
1
+ ISC licence
2
+ -----------
3
+
4
+ Copyright (c) 2015, Leo Nikkilä <hello@lnikki.la>
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any purpose
7
+ with or without fee is hereby granted, provided that the above copyright notice
8
+ and this permission notice appear in all copies.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
12
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
16
+ THIS SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ RSpec JSON schema matcher
2
+ =========================
3
+
4
+ [![Build status][travis-badge]][travis]
5
+
6
+ Validate JSON in your specs using [JSON schema](http://json-schema.org/):
7
+
8
+ ```ruby
9
+ it "returns a valid user resource" do
10
+ expect(response.body).to match_schema "user"
11
+ end
12
+ ```
13
+
14
+ Handy for testing JSON-based web APIs!
15
+
16
+ ### Installation ###
17
+
18
+ Add this to your application's Gemfile:
19
+
20
+ ```ruby
21
+ group :test do
22
+ gem "rspec_json_schema_matcher"
23
+ end
24
+ ```
25
+
26
+ Then install the gem:
27
+
28
+ ```sh-session
29
+ $ bundle
30
+ ```
31
+
32
+ And finally add this to your `spec_helper.rb`:
33
+
34
+ ```ruby
35
+ require 'rspec_json_schema_matcher'
36
+ ```
37
+
38
+ ### Usage ###
39
+
40
+ Provides a single RSpec matcher called `match_schema` that accepts a relative
41
+ path to a JSON schema without the .json extension.
42
+
43
+ The matcher assumes that your schemas are stored in `./spec/support/schemas` or
44
+ in its subdirectories.
45
+
46
+ For example, if you want to use `./spec/support/schemas/users/instance.json`,
47
+ write `match_schema "users/instance"`.
48
+
49
+ ### Development ###
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
52
+ `rake rspec` to run the tests. You can also run `bin/console` for an interactive
53
+ prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To
56
+ release a new version, update the version number in `version.rb`, and then run
57
+ `bundle exec rake release`, which will create a git tag for the version, push
58
+ git commits and tags, and push the `.gem` file to
59
+ [rubygems.org](https://rubygems.org).
60
+
61
+ ### Contributing ###
62
+
63
+ Bug reports and pull requests are welcome!
64
+
65
+ ### Licence ###
66
+
67
+ The gem is available as open source under the terms of the
68
+ [ISC License](http://opensource.org/licenses/ISC).
69
+
70
+ [travis]: https://travis-ci.org/lnikkila/rspec_json_schema_matcher
71
+ [travis-badge]: https://img.shields.io/travis/lnikkila/rspec_json_schema_matcher.svg?style=flat-square
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec_json_schema_matcher"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "pry"
14
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module RSpecJSONSchemaMatcher
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+ require "rspec_json_schema_matcher/version"
2
+
3
+ require 'rspec'
4
+ require 'rspec/expectations'
5
+ require 'json-schema'
6
+
7
+ # Validates JSON responses against a schema
8
+ RSpec::Matchers.define :match_schema do |schema|
9
+ match do |body|
10
+ schema_directory = "#{Dir.pwd}/spec/support/schemas"
11
+ schema_path = "#{schema_directory}/#{schema}.json"
12
+ opts = { validate_schema: true }
13
+
14
+ begin
15
+ @result = JSON::Validator.fully_validate_json(schema_path, body, opts)
16
+ rescue JSON::Schema::ValidationError => e
17
+ @result = "Schema '#{schema}' did not pass validation:\n\n- #{e.message}"
18
+ end
19
+
20
+ expect(@result).to eq []
21
+ end
22
+
23
+ failure_message do |body|
24
+ "#{messages}\n\n#{body}"
25
+ end
26
+
27
+ description do
28
+ "match the JSON schema '#{schema}'"
29
+ end
30
+
31
+ private
32
+
33
+ def messages
34
+ if @result.respond_to?(:join)
35
+ @result.join("\n")
36
+ else
37
+ @result
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
+
3
+ require 'rspec_json_schema_matcher/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rspec_json_schema_matcher"
7
+ spec.version = RSpecJSONSchemaMatcher::VERSION
8
+ spec.authors = ["Leo Nikkilä"]
9
+ spec.email = ["hello@lnikki.la"]
10
+
11
+ spec.summary = "Validate JSON in your specs using JSON schema."
12
+ spec.homepage = "https://github.com/lnikkila/rspec_json_schema_matcher"
13
+ spec.license = "ISC"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "rspec", "~> 3.0.0"
21
+ spec.add_runtime_dependency "json-schema", "~> 2.5.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry"
26
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_json_schema_matcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Leo Nikkilä
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json-schema
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - hello@lnikki.la
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSING.md
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/rspec_json_schema_matcher.rb
100
+ - lib/rspec_json_schema_matcher/version.rb
101
+ - rspec_json_schema_matcher.gemspec
102
+ homepage: https://github.com/lnikkila/rspec_json_schema_matcher
103
+ licenses:
104
+ - ISC
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.5
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Validate JSON in your specs using JSON schema.
126
+ test_files: []