rspec-kwalify 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.travis.yml +7 -0
- data/Gemfile +16 -0
- data/Guardfile +11 -0
- data/README.textile +15 -0
- data/Rakefile +9 -0
- data/lib/rspec-kwalify/version.rb +5 -0
- data/lib/rspec-kwalify.rb +61 -0
- data/rspec-kwalify.gemspec +23 -0
- data/spec/assets/empty.yml +2 -0
- data/spec/assets/schema.yml +11 -0
- data/spec/assets/syntax.yml +2 -0
- data/spec/rspec-kwalify_spec.rb +56 -0
- data/spec/spec_helper.rb +16 -0
- metadata +87 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
guard :bundler, :notify => false do
|
2
|
+
watch("Gemfile")
|
3
|
+
end
|
4
|
+
|
5
|
+
guard :rspec, :version => 2, :cli => "--color --format nested --fail-fast" do
|
6
|
+
watch(%r{spec/assets/.+\.yml}) { "spec" }
|
7
|
+
watch("spec/spec_helper.rb") { "spec" }
|
8
|
+
|
9
|
+
watch(%r{^spec/.+_spec\.rb})
|
10
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
end
|
data/README.textile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
h1. RSpec-Kwalify "!https://secure.travis-ci.org/pmenglund/rspec-kwalify.png?branch=master!":http://travis-ci.org/pmenglund/rspec-kwalify
|
2
|
+
|
3
|
+
RSpec matchers to help you use Kwalify in RSpec
|
4
|
+
|
5
|
+
h1. Examples
|
6
|
+
|
7
|
+
<pre>
|
8
|
+
it "should have 2 errors" do
|
9
|
+
validator.validate(asset("empty.yml")).should have_error(2)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have validation error" do
|
13
|
+
validator.validate(asset("empty.yml")).should have_validation_error
|
14
|
+
end
|
15
|
+
</pre>
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "kwalify"
|
2
|
+
require "rspec-kwalify/version"
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Kwalify
|
6
|
+
|
7
|
+
class HaveError
|
8
|
+
def initialize(error, base_error=::Kwalify::BaseError)
|
9
|
+
@error = error
|
10
|
+
@base_error = base_error
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(errors)
|
14
|
+
@errors = errors
|
15
|
+
|
16
|
+
if @error.nil?
|
17
|
+
@errors.any? { |error| error.is_a?(@base_error) }
|
18
|
+
elsif @error.is_a?(Regexp)
|
19
|
+
@errors.any? do |error|
|
20
|
+
error.is_a?(@base_error) && error.message.match(@error)
|
21
|
+
end
|
22
|
+
elsif @error.is_a?(Fixnum)
|
23
|
+
@errors.size == @error
|
24
|
+
else
|
25
|
+
raise ArgumentError, "don't know how to handle a #{@error.class}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def failure_message_for_should
|
30
|
+
msg = "expected errors to contain '%s' but was '%s'"
|
31
|
+
if @error.nil?
|
32
|
+
errors = @errors.map { |e| e.class.name }.uniq
|
33
|
+
msg % [@base_error, errors.join(", ")]
|
34
|
+
elsif @error.is_a?(Regexp)
|
35
|
+
errors = @errors.map { |e| e.message }.uniq
|
36
|
+
msg % [@error.source, errors.join(", ")]
|
37
|
+
elsif @error.is_a?(Fixnum)
|
38
|
+
"expected #{@error} errors, found #{@errors.size}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# have_error error of type Kwalify::BaseError
|
47
|
+
# have_error(Fixnum) number of errors
|
48
|
+
# have_error(Regexp) error with a message matching
|
49
|
+
def have_error(error=nil)
|
50
|
+
RSpec::Kwalify::HaveError.new(error)
|
51
|
+
end
|
52
|
+
|
53
|
+
# have_validation_error
|
54
|
+
def have_validation_error(error=nil)
|
55
|
+
RSpec::Kwalify::HaveError.new(error, ::Kwalify::ValidationError)
|
56
|
+
end
|
57
|
+
|
58
|
+
# have_syntax_error
|
59
|
+
def have_syntax_error(error=nil)
|
60
|
+
RSpec::Kwalify::HaveError.new(error, ::Kwalify::SyntaxError)
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rspec-kwalify/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rspec-kwalify"
|
7
|
+
s.version = RSpec::Kwalify::VERSION
|
8
|
+
s.authors = ["Martin Englund"]
|
9
|
+
s.email = ["martin@englund.nu"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{rspec matchers for kwalify}
|
12
|
+
s.description = %q{rspec matchers for kwalify}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rspec-kwalify"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency "rspec"
|
22
|
+
s.add_runtime_dependency "kwalify"
|
23
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::Kwalify do
|
4
|
+
|
5
|
+
SCHEMA = asset("schema.yml")
|
6
|
+
|
7
|
+
let(:schema) { Kwalify::Yaml.load_file(SCHEMA) }
|
8
|
+
let(:validator) { Kwalify::Validator.new(schema) }
|
9
|
+
|
10
|
+
describe "base object" do
|
11
|
+
it "should raise an error on String" do
|
12
|
+
lambda {
|
13
|
+
RSpec::Kwalify::HaveError.new("String").matches?([])
|
14
|
+
}.should raise_error ArgumentError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "rspec" do
|
19
|
+
describe "#have_error" do
|
20
|
+
it "should pass on a nil argument" do
|
21
|
+
validator.validate(load_yaml("empty.yml")).should have_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should pass on a Fixnum argument" do
|
25
|
+
validator.validate(load_yaml("empty.yml")).should have_error(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should pass on a Regexp argument" do
|
29
|
+
validator.validate(load_yaml("empty.yml")).should have_error(/key 'foo:' is required/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#have_validation_error" do
|
34
|
+
it "should pass on a nil argument" do
|
35
|
+
validator.validate(load_yaml("empty.yml")).should have_validation_error
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should pass on a Fixnum argument" do
|
39
|
+
validator.validate(load_yaml("empty.yml")).should have_validation_error(1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should pass on a Regexp argument" do
|
43
|
+
validator.validate(load_yaml("empty.yml")).should have_validation_error(/key 'foo:' is required/)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#have_syntax_error" do
|
48
|
+
it "should pass on a nil argument" do
|
49
|
+
pending "find a way to force a 'Kwalify::SyntaxError'"
|
50
|
+
validator.validate(load_yaml("syntax.yml")).should have_syntax_error
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup(:default, :test)
|
6
|
+
|
7
|
+
require "rspec"
|
8
|
+
require "rspec-kwalify"
|
9
|
+
|
10
|
+
def asset(file)
|
11
|
+
File.expand_path(File.join(File.dirname(__FILE__), "assets", file))
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_yaml(file)
|
15
|
+
Kwalify::Yaml.load_file(asset(file))
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-kwalify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Martin Englund
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-17 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70193016224180 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70193016224180
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: kwalify
|
27
|
+
requirement: &70193016223760 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70193016223760
|
36
|
+
description: rspec matchers for kwalify
|
37
|
+
email:
|
38
|
+
- martin@englund.nu
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .travis.yml
|
45
|
+
- Gemfile
|
46
|
+
- Guardfile
|
47
|
+
- README.textile
|
48
|
+
- Rakefile
|
49
|
+
- lib/rspec-kwalify.rb
|
50
|
+
- lib/rspec-kwalify/version.rb
|
51
|
+
- rspec-kwalify.gemspec
|
52
|
+
- spec/assets/empty.yml
|
53
|
+
- spec/assets/schema.yml
|
54
|
+
- spec/assets/syntax.yml
|
55
|
+
- spec/rspec-kwalify_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
homepage: ''
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project: rspec-kwalify
|
77
|
+
rubygems_version: 1.8.10
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: rspec matchers for kwalify
|
81
|
+
test_files:
|
82
|
+
- spec/assets/empty.yml
|
83
|
+
- spec/assets/schema.yml
|
84
|
+
- spec/assets/syntax.yml
|
85
|
+
- spec/rspec-kwalify_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
has_rdoc:
|