rspec-xsd 0.0.1 → 0.1.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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +40 -14
- data/lib/rspec/xsd.rb +4 -4
- data/lib/rspec/xsd/matcher.rb +26 -11
- data/lib/rspec/xsd/version.rb +3 -3
- data/rspec-xsd.gemspec +1 -1
- data/spec/lib/rspec/xsd/matcher_spec.rb +15 -2
- data/spec/lib/rspec/xsd_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0fe3718567bcdac88f56e9cc9c59b92b4540ef5
|
4
|
+
data.tar.gz: a864ab660751c4ecc0f83562a4205578520f8f3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3df860d28e80108a1cb22a23e3082d536c77e7a9f85d1071aa44d872177d826e1913ff1b20c5575be520dab3f68904cda1070f5667db31a42bdc956cd00eb86
|
7
|
+
data.tar.gz: 895b73b12973deb9cd52df615f462254270b983ac9b3d08dc7a8eab644bb545a27219b52925c3c5d8b64fe5d3f5451c4455700e9b64888e19c9b2bb63e7bc29e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,43 +1,69 @@
|
|
1
|
-
#
|
1
|
+
# RSpec::XSD
|
2
2
|
|
3
3
|
[](https://travis-ci.org/invisiblelines/rspec-xsd)
|
4
4
|
[](https://codeclimate.com/github/invisiblelines/rspec-xsd)
|
5
5
|
|
6
6
|
## Overview
|
7
7
|
|
8
|
-
|
8
|
+
RSpec matcher for ensuring XML validates against a given XSD
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
```ruby
|
15
|
+
group :test do
|
16
|
+
gem 'rspec-xsd'
|
17
|
+
end
|
18
|
+
```
|
17
19
|
|
18
20
|
And then execute:
|
19
21
|
|
20
|
-
|
22
|
+
```
|
23
|
+
$ bundle
|
24
|
+
```
|
21
25
|
|
22
|
-
Or install it yourself
|
26
|
+
Or install it yourself with:
|
23
27
|
|
24
|
-
|
28
|
+
```
|
29
|
+
$ gem install rspec-xsd
|
30
|
+
```
|
25
31
|
|
26
32
|
## Usage
|
27
33
|
|
28
34
|
Require the gem in your spec_helper
|
29
35
|
|
30
|
-
|
36
|
+
```ruby
|
37
|
+
require 'rspec/xsd'
|
38
|
+
```
|
31
39
|
|
32
40
|
Now include the matcher in your specs
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
|
42
|
+
```ruby
|
43
|
+
RSpec.configure do |config|
|
44
|
+
config.include RSpec::XSD
|
45
|
+
end
|
46
|
+
```
|
37
47
|
|
38
|
-
You can
|
48
|
+
You can validate either an XML string or a Nokogiri::XML::Document.
|
39
49
|
|
40
|
-
|
50
|
+
You can check that XML validates against a given schema by passing in a Nokogiri::XML::Schema object
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
expect(xml).to pass_validation(xsd)
|
54
|
+
```
|
55
|
+
|
56
|
+
or by passing in the path to your XSD
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
expect(xml).to pass_validation('/path/to/schema.xsd')
|
60
|
+
```
|
61
|
+
|
62
|
+
If you wish to give your XSD a more descriptive name you can pass this in as an optional argument
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
expect(xml).to pass_validation('/path/to/schema.xsd', 'My Complex XSD')
|
66
|
+
```
|
41
67
|
|
42
68
|
You can pass either a string or file as the XML document
|
43
69
|
|
data/lib/rspec/xsd.rb
CHANGED
@@ -3,12 +3,12 @@ require "nokogiri"
|
|
3
3
|
require "rspec/xsd/version"
|
4
4
|
require 'rspec/xsd/matcher'
|
5
5
|
|
6
|
-
module
|
6
|
+
module RSpec
|
7
7
|
|
8
|
-
module
|
8
|
+
module XSD
|
9
9
|
|
10
|
-
def pass_validation(
|
11
|
-
Matcher.new(
|
10
|
+
def pass_validation(schema, schema_name = nil)
|
11
|
+
Matcher.new(schema, schema_name)
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
data/lib/rspec/xsd/matcher.rb
CHANGED
@@ -1,19 +1,34 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
|
3
|
-
module
|
3
|
+
module XSD
|
4
4
|
|
5
5
|
class Matcher
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
|
7
|
+
def initialize(schema, schema_name)
|
8
|
+
@schema_name = schema_name
|
9
|
+
case schema
|
10
|
+
when Nokogiri::XML::Schema
|
11
|
+
@xsd = schema
|
12
|
+
@schema_name = "In Memory Schema" if @schema_name.nil?
|
13
|
+
else
|
14
|
+
@schema_path = schema
|
15
|
+
@schema_name = File.basename(@schema_path) if @schema_name.nil?
|
16
|
+
end
|
10
17
|
@errors = []
|
11
18
|
end
|
12
19
|
|
13
20
|
def matches?(xml)
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
if @xsd.nil?
|
22
|
+
File.open(@schema_path) do |f|
|
23
|
+
@xsd = Nokogiri::XML::Schema(f)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
case xml
|
28
|
+
when Nokogiri::XML::Document
|
29
|
+
@errors = @xsd.validate(xml)
|
30
|
+
else
|
31
|
+
@errors = @xsd.validate(Nokogiri::XML(xml))
|
17
32
|
end
|
18
33
|
|
19
34
|
@errors.map! { |e| e }
|
@@ -22,15 +37,15 @@ module Rspec
|
|
22
37
|
end
|
23
38
|
|
24
39
|
def failure_message
|
25
|
-
"expected that XML would validate against #{@
|
40
|
+
"expected that XML would validate against #{@schema_name}\r\n\r\n#{@errors.join("\r\n")}"
|
26
41
|
end
|
27
42
|
|
28
43
|
def failure_message_when_negated
|
29
|
-
"expected that XML would not validate against #{@
|
44
|
+
"expected that XML would not validate against #{@schema_name}"
|
30
45
|
end
|
31
46
|
|
32
47
|
def description
|
33
|
-
"validate against #{@
|
48
|
+
"validate against #{@schema_name}"
|
34
49
|
end
|
35
50
|
|
36
51
|
end
|
data/lib/rspec/xsd/version.rb
CHANGED
data/rspec-xsd.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'rspec/xsd/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rspec-xsd"
|
8
|
-
spec.version =
|
8
|
+
spec.version = RSpec::XSD::VERSION
|
9
9
|
spec.authors = ["Kieran Johnson"]
|
10
10
|
spec.email = ["hello@invisiblelines.com"]
|
11
11
|
spec.summary = %q{Rspec matcher for ensuring XML validates against a given XSD}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe RSpec::XSD::Matcher do
|
4
4
|
let(:path) { File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', '..', 'fixtures') }
|
5
5
|
let(:schema_path) { File.join(path, 'schema.xsd') }
|
6
6
|
|
7
|
-
let(:matcher) {
|
7
|
+
let(:matcher) { RSpec::XSD::Matcher.new(schema_path, File.basename(schema_path)) }
|
8
8
|
|
9
9
|
describe '#matches?' do
|
10
10
|
let(:xml) { File.read(File.join(path, 'valid.xml')) }
|
@@ -15,6 +15,12 @@ describe Rspec::Xsd::Matcher do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
context 'with XML object' do
|
19
|
+
it 'returns true' do
|
20
|
+
expect(matcher.matches?(Nokogiri::XML(xml))).to be(true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
18
24
|
context 'with invalid XML' do
|
19
25
|
let(:xml) { File.read(File.join(path, 'invalid.xml')) }
|
20
26
|
|
@@ -22,6 +28,13 @@ describe Rspec::Xsd::Matcher do
|
|
22
28
|
expect(matcher.matches?(xml)).to be(false)
|
23
29
|
end
|
24
30
|
end
|
31
|
+
|
32
|
+
context 'with schema object' do
|
33
|
+
it 'returns true' do
|
34
|
+
schema = Nokogiri::XML::Schema(File.read(schema_path))
|
35
|
+
expect(RSpec::XSD::Matcher.new(schema, File.basename(schema_path)).matches?(xml)).to be(true)
|
36
|
+
end
|
37
|
+
end
|
25
38
|
end
|
26
39
|
|
27
40
|
describe '#description' do
|
data/spec/lib/rspec/xsd_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
2
|
-
require 'codeclimate-test-reporter'
|
1
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
2
|
+
require 'codeclimate-test-reporter'
|
3
3
|
|
4
|
-
|
4
|
+
CodeClimate::TestReporter.start
|
5
|
+
else
|
6
|
+
require 'simplecov'
|
5
7
|
|
6
|
-
|
8
|
+
SimpleCov.start
|
9
|
+
end
|
7
10
|
|
8
11
|
require 'rspec'
|
9
12
|
require 'rspec/xsd'
|
@@ -13,5 +16,5 @@ RSpec.configure do |config|
|
|
13
16
|
c.syntax = :expect
|
14
17
|
end
|
15
18
|
|
16
|
-
config.include
|
19
|
+
config.include RSpec::XSD
|
17
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-xsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kieran Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -205,3 +205,4 @@ test_files:
|
|
205
205
|
- spec/lib/rspec/xsd/matcher_spec.rb
|
206
206
|
- spec/lib/rspec/xsd_spec.rb
|
207
207
|
- spec/spec_helper.rb
|
208
|
+
has_rdoc:
|