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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69134355a1c7aed6f984afb046fc4b857680460b
4
- data.tar.gz: b52cc858ab9edefba1288e977517a465da2a638a
3
+ metadata.gz: e0fe3718567bcdac88f56e9cc9c59b92b4540ef5
4
+ data.tar.gz: a864ab660751c4ecc0f83562a4205578520f8f3d
5
5
  SHA512:
6
- metadata.gz: 0c697f05bd3a34f5c4b07998760ea7da200d99104959794cd7cc0ee3c24309de860147184696d04e1b02def4b56809e75dfa150f21a4b5553fbd192c29555b06
7
- data.tar.gz: c63bc6bbc3b4a88b7db15f47dc50b0d8366c7ece0e123f9aa5f5734a625485cd0d10ed7c08c183b1047ae26d9836a4ecc919e86344b3ff5adeada35d0cb42794
6
+ metadata.gz: a3df860d28e80108a1cb22a23e3082d536c77e7a9f85d1071aa44d872177d826e1913ff1b20c5575be520dab3f68904cda1070f5667db31a42bdc956cd00eb86
7
+ data.tar.gz: 895b73b12973deb9cd52df615f462254270b983ac9b3d08dc7a8eab644bb545a27219b52925c3c5d8b64fe5d3f5451c4455700e9b64888e19c9b2bb63e7bc29e
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
4
  - 2.1.3
4
5
  - jruby-19mode
data/README.md CHANGED
@@ -1,43 +1,69 @@
1
- # Rspec::Xsd
1
+ # RSpec::XSD
2
2
 
3
3
  [![Build Status](https://travis-ci.org/invisiblelines/rspec-xsd.svg)](https://travis-ci.org/invisiblelines/rspec-xsd)
4
4
  [![Code Climate](https://codeclimate.com/github/invisiblelines/rspec-xsd/badges/gpa.svg)](https://codeclimate.com/github/invisiblelines/rspec-xsd)
5
5
 
6
6
  ## Overview
7
7
 
8
- Rspec matcher for ensuring XML validates against a given XSD
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
- group :test do
15
- gem 'rspec-xsd'
16
- end
14
+ ```ruby
15
+ group :test do
16
+ gem 'rspec-xsd'
17
+ end
18
+ ```
17
19
 
18
20
  And then execute:
19
21
 
20
- $ bundle
22
+ ```
23
+ $ bundle
24
+ ```
21
25
 
22
- Or install it yourself as:
26
+ Or install it yourself with:
23
27
 
24
- $ gem install rspec-xsd
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
- require 'rspec-xsd'
36
+ ```ruby
37
+ require 'rspec/xsd'
38
+ ```
31
39
 
32
40
  Now include the matcher in your specs
33
41
 
34
- RSpec.configure do |config|
35
- config.include Rspec::Xsd
36
- end
42
+ ```ruby
43
+ RSpec.configure do |config|
44
+ config.include RSpec::XSD
45
+ end
46
+ ```
37
47
 
38
- You can now check that XML validates against a given schema
48
+ You can validate either an XML string or a Nokogiri::XML::Document.
39
49
 
40
- expect(xml).to pass_validation(/path/to/schema.xsd)
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
 
@@ -3,12 +3,12 @@ require "nokogiri"
3
3
  require "rspec/xsd/version"
4
4
  require 'rspec/xsd/matcher'
5
5
 
6
- module Rspec
6
+ module RSpec
7
7
 
8
- module Xsd
8
+ module XSD
9
9
 
10
- def pass_validation(schema_path)
11
- Matcher.new(schema_path)
10
+ def pass_validation(schema, schema_name = nil)
11
+ Matcher.new(schema, schema_name)
12
12
  end
13
13
 
14
14
  end
@@ -1,19 +1,34 @@
1
- module Rspec
1
+ module RSpec
2
2
 
3
- module Xsd
3
+ module XSD
4
4
 
5
5
  class Matcher
6
6
 
7
- def initialize(schema_path)
8
- @schema_path = schema_path
9
- @schema = File.basename(schema_path)
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
- File.open(@schema_path) do |f|
15
- xsd = Nokogiri::XML::Schema(f)
16
- @errors = xsd.validate(Nokogiri::XML(xml))
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 #{@schema}\r\n\r\n#{@errors.join("\r\n")}"
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 #{@schema}"
44
+ "expected that XML would not validate against #{@schema_name}"
30
45
  end
31
46
 
32
47
  def description
33
- "validate against #{@schema}"
48
+ "validate against #{@schema_name}"
34
49
  end
35
50
 
36
51
  end
@@ -1,5 +1,5 @@
1
- module Rspec
2
- module Xsd
3
- VERSION = "0.0.1"
1
+ module RSpec
2
+ module XSD
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -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 = Rspec::Xsd::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 Rspec::Xsd::Matcher do
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) { Rspec::Xsd::Matcher.new(schema_path) }
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
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Rspec::Xsd do
3
+ describe RSpec::XSD 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
 
@@ -1,9 +1,12 @@
1
- require 'simplecov'
2
- require 'codeclimate-test-reporter'
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
3
 
4
- SimpleCov.start
4
+ CodeClimate::TestReporter.start
5
+ else
6
+ require 'simplecov'
5
7
 
6
- CodeClimate::TestReporter.start
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 Rspec::Xsd
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.1
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-09-25 00:00:00.000000000 Z
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: