rspec-xsd 0.0.1

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: 69134355a1c7aed6f984afb046fc4b857680460b
4
+ data.tar.gz: b52cc858ab9edefba1288e977517a465da2a638a
5
+ SHA512:
6
+ metadata.gz: 0c697f05bd3a34f5c4b07998760ea7da200d99104959794cd7cc0ee3c24309de860147184696d04e1b02def4b56809e75dfa150f21a4b5553fbd192c29555b06
7
+ data.tar.gz: c63bc6bbc3b4a88b7db15f47dc50b0d8366c7ece0e123f9aa5f5734a625485cd0d10ed7c08c183b1047ae26d9836a4ecc919e86344b3ff5adeada35d0cb42794
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
4
+ - jruby-19mode
5
+ - rbx-2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-xsd.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kieran Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Rspec::Xsd
2
+
3
+ [![Build Status](https://travis-ci.org/invisiblelines/rspec-xsd.svg)](https://travis-ci.org/invisiblelines/rspec-xsd)
4
+ [![Code Climate](https://codeclimate.com/github/invisiblelines/rspec-xsd/badges/gpa.svg)](https://codeclimate.com/github/invisiblelines/rspec-xsd)
5
+
6
+ ## Overview
7
+
8
+ Rspec matcher for ensuring XML validates against a given XSD
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ group :test do
15
+ gem 'rspec-xsd'
16
+ end
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install rspec-xsd
25
+
26
+ ## Usage
27
+
28
+ Require the gem in your spec_helper
29
+
30
+ require 'rspec-xsd'
31
+
32
+ Now include the matcher in your specs
33
+
34
+ RSpec.configure do |config|
35
+ config.include Rspec::Xsd
36
+ end
37
+
38
+ You can now check that XML validates against a given schema
39
+
40
+ expect(xml).to pass_validation(/path/to/schema.xsd)
41
+
42
+ You can pass either a string or file as the XML document
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (git checkout -b my-new-feature)
48
+ 3. Commit your changes (git commit -am 'Add some feature')
49
+ 4. Push to the branch (git push origin my-new-feature)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :spec
8
+
9
+ task :default => :spec
data/lib/rspec/xsd.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "nokogiri"
2
+
3
+ require "rspec/xsd/version"
4
+ require 'rspec/xsd/matcher'
5
+
6
+ module Rspec
7
+
8
+ module Xsd
9
+
10
+ def pass_validation(schema_path)
11
+ Matcher.new(schema_path)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,40 @@
1
+ module Rspec
2
+
3
+ module Xsd
4
+
5
+ class Matcher
6
+
7
+ def initialize(schema_path)
8
+ @schema_path = schema_path
9
+ @schema = File.basename(schema_path)
10
+ @errors = []
11
+ end
12
+
13
+ def matches?(xml)
14
+ File.open(@schema_path) do |f|
15
+ xsd = Nokogiri::XML::Schema(f)
16
+ @errors = xsd.validate(Nokogiri::XML(xml))
17
+ end
18
+
19
+ @errors.map! { |e| e }
20
+
21
+ @errors.empty?
22
+ end
23
+
24
+ def failure_message
25
+ "expected that XML would validate against #{@schema}\r\n\r\n#{@errors.join("\r\n")}"
26
+ end
27
+
28
+ def failure_message_when_negated
29
+ "expected that XML would not validate against #{@schema}"
30
+ end
31
+
32
+ def description
33
+ "validate against #{@schema}"
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module Xsd
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/rspec-xsd.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/xsd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-xsd"
8
+ spec.version = Rspec::Xsd::VERSION
9
+ spec.authors = ["Kieran Johnson"]
10
+ spec.email = ["hello@invisiblelines.com"]
11
+ spec.summary = %q{Rspec matcher for ensuring XML validates against a given XSD}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rspec", '~> 3'
22
+ spec.add_dependency "nokogiri", '~> 1.6'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake", '~> 0'
26
+ spec.add_development_dependency 'simplecov', '~> 0.9.0'
27
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.0'
28
+ spec.add_development_dependency 'guard', '~> 2.6'
29
+ spec.add_development_dependency 'guard-rspec', '~> 4.3'
30
+ spec.add_development_dependency 'rb-inotify', '~> 0.9'
31
+ spec.add_development_dependency 'rb-fsevent', '~> 0.9'
32
+ end
@@ -0,0 +1,5 @@
1
+ <note>
2
+ <to>John</to>
3
+ <from>Bob</from>
4
+ <heading>Hello</heading>
5
+ </note>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0"?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
+ <xs:element name="note">
4
+ <xs:complexType>
5
+ <xs:sequence>
6
+ <xs:element name="to" type="xs:string"/>
7
+ <xs:element name="from" type="xs:string"/>
8
+ <xs:element name="heading" type="xs:string"/>
9
+ <xs:element name="body" type="xs:string"/>
10
+ </xs:sequence>
11
+ </xs:complexType>
12
+ </xs:element>
13
+ </xs:schema>
@@ -0,0 +1,6 @@
1
+ <note>
2
+ <to>John</to>
3
+ <from>Bob</from>
4
+ <heading>Hello</heading>
5
+ <body>Lorem Ipsum...</body>
6
+ </note>
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rspec::Xsd::Matcher do
4
+ let(:path) { File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', '..', 'fixtures') }
5
+ let(:schema_path) { File.join(path, 'schema.xsd') }
6
+
7
+ let(:matcher) { Rspec::Xsd::Matcher.new(schema_path) }
8
+
9
+ describe '#matches?' do
10
+ let(:xml) { File.read(File.join(path, 'valid.xml')) }
11
+
12
+ context 'with valid XML' do
13
+ it 'returns true' do
14
+ expect(matcher.matches?(xml)).to be(true)
15
+ end
16
+ end
17
+
18
+ context 'with invalid XML' do
19
+ let(:xml) { File.read(File.join(path, 'invalid.xml')) }
20
+
21
+ it 'returns false' do
22
+ expect(matcher.matches?(xml)).to be(false)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '#description' do
28
+ it 'returns description' do
29
+ expect(matcher.description).to eq('validate against schema.xsd')
30
+ end
31
+ end
32
+
33
+ describe '#failure_message' do
34
+ let(:xml) { File.read(File.join(path, 'invalid.xml')) }
35
+
36
+ before do
37
+ matcher.matches?(xml)
38
+ end
39
+
40
+ it 'returns message with validation errors' do
41
+ expect(matcher.failure_message).to match(/expected that XML would validate against schema.xsd\r\n\r\n/)
42
+ end
43
+ end
44
+
45
+ describe '#failure_message_when_negated' do
46
+ it 'returns message' do
47
+ expect(matcher.failure_message_when_negated).to eq('expected that XML would not validate against schema.xsd')
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rspec::Xsd do
4
+ let(:path) { File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'fixtures') }
5
+ let(:schema_path) { File.join(path, 'schema.xsd') }
6
+
7
+ describe '#pass_validation' do
8
+ context 'with valid XML' do
9
+ let(:xml) { File.read(File.join(path, 'valid.xml')) }
10
+
11
+ it 'validates given XML against the given XSD' do
12
+ expect(xml).to pass_validation(schema_path)
13
+ end
14
+ end
15
+
16
+ context 'with invalid XML' do
17
+ let(:xml) { File.read(File.join(path, 'invalid.xml')) }
18
+
19
+ it 'confirms invalid XML does not validate' do
20
+ expect(xml).not_to pass_validation(schema_path)
21
+ end
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+ require 'codeclimate-test-reporter'
3
+
4
+ SimpleCov.start
5
+
6
+ CodeClimate::TestReporter.start
7
+
8
+ require 'rspec'
9
+ require 'rspec/xsd'
10
+
11
+ RSpec.configure do |config|
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+
16
+ config.include Rspec::Xsd
17
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-xsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kieran Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-25 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
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.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.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.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rb-inotify
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rb-fsevent
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.9'
153
+ description: Rspec matcher for ensuring XML validates against a given XSD
154
+ email:
155
+ - hello@invisiblelines.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".travis.yml"
162
+ - Gemfile
163
+ - Guardfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - lib/rspec/xsd.rb
168
+ - lib/rspec/xsd/matcher.rb
169
+ - lib/rspec/xsd/version.rb
170
+ - rspec-xsd.gemspec
171
+ - spec/fixtures/invalid.xml
172
+ - spec/fixtures/schema.xsd
173
+ - spec/fixtures/valid.xml
174
+ - spec/lib/rspec/xsd/matcher_spec.rb
175
+ - spec/lib/rspec/xsd_spec.rb
176
+ - spec/spec_helper.rb
177
+ homepage: ''
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.2.2
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Rspec matcher for ensuring XML validates against a given XSD
201
+ test_files:
202
+ - spec/fixtures/invalid.xml
203
+ - spec/fixtures/schema.xsd
204
+ - spec/fixtures/valid.xml
205
+ - spec/lib/rspec/xsd/matcher_spec.rb
206
+ - spec/lib/rspec/xsd_spec.rb
207
+ - spec/spec_helper.rb