bc-rspec-matchers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +48 -0
- data/Rakefile +17 -0
- data/bc-rspec-matchers.gemspec +22 -0
- data/lib/bc-rspec-matchers.rb +10 -0
- data/lib/bc-rspec-matchers/data_structure.rb +75 -0
- data/lib/bc-rspec-matchers/version.rb +7 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/unit/data_structure_spec.rb +108 -0
- metadata +133 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Vasco
|
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,48 @@
|
|
1
|
+
# Bc::Rspec::Matchers
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bc-rspec-matchers'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bc-rspec-matchers
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
## Notes to Manage and improve this gem
|
32
|
+
|
33
|
+
See: http://railscasts.com/episodes/245-new-gem-with-bundler?view=asciicast
|
34
|
+
|
35
|
+
### Update & Release
|
36
|
+
|
37
|
+
Run `bundle exec rake release`
|
38
|
+
|
39
|
+
or
|
40
|
+
|
41
|
+
1. Update `lib/bc-rspec-matchers/version.rb` version.rb
|
42
|
+
2. gem build
|
43
|
+
3. gem push
|
44
|
+
|
45
|
+
# Relevant blog posts
|
46
|
+
* http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/
|
47
|
+
* http://benscheirman.com/2011/05/dry-up-your-rspec-files-with-subject-let-blocks
|
48
|
+
* http://solnic.eu/2011/01/14/custom-rspec-2-matchers.html (chains)
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
10
|
+
spec.pattern = "./spec/**/*_spec.rb"
|
11
|
+
spec.rspec_opts = File.read(".rspec").split("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
15
|
+
spec.pattern = "./spec/**/*_spec.rb"
|
16
|
+
spec.rcov = true
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bc-rspec-matchers/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Byclosure"]
|
6
|
+
gem.email = ["info@byclosure.com"]
|
7
|
+
gem.description = %q{Collection of rspec matchers to improve spec writing performance}
|
8
|
+
gem.summary = %q{Collection of rspec matchers to improve spec writing performance}
|
9
|
+
gem.homepage = "http://github.com/Byclosure/bc-rspec-matchers"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "bc-rspec-matchers"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Bc::Rspec::Matchers::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_development_dependency "ruby-debug"
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
gem.add_development_dependency "ZenTest"
|
22
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Bc
|
2
|
+
module RSpec
|
3
|
+
module Matchers
|
4
|
+
class DataStructure
|
5
|
+
WILDCARD = :"***__w_i_l_d_c_a_r_d__***"
|
6
|
+
|
7
|
+
def initialize(pattern)
|
8
|
+
@pattern = pattern
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(actual)
|
12
|
+
@actual = actual
|
13
|
+
|
14
|
+
is_match(@actual, @pattern)
|
15
|
+
end
|
16
|
+
|
17
|
+
def description
|
18
|
+
"match to #{@pattern.inspect}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message_for_should
|
22
|
+
"expected #{self} to match to #{@actual.inspect}. " + (@failure_message_for_should_fragments ||
|
23
|
+
"Fragment #{@fragment_pattern.inspect} didn't match to #{@fragment_actual.inspect}."
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure_message_for_should_not
|
28
|
+
"expected #{self} not to match to #{@actual.inspect}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
"#{self.class.basename}(#{@pattern.inspect})"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.basename
|
38
|
+
name.sub(/^.*::/, '')
|
39
|
+
end
|
40
|
+
|
41
|
+
def is_match(actual, pattern)
|
42
|
+
@fragment_actual, @fragment_pattern = actual, pattern
|
43
|
+
if !actual.is_a?(pattern.class)
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
|
47
|
+
if pattern.is_a?(Hash)
|
48
|
+
pattern.each do |(k,v)|
|
49
|
+
if !actual.has_key?(k)
|
50
|
+
@fragment_actual, @fragment_pattern = actual, {k => v}
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
return false unless is_match(actual[k], v)
|
54
|
+
end
|
55
|
+
true
|
56
|
+
elsif pattern.is_a?(Array)
|
57
|
+
if pattern.size == actual.size
|
58
|
+
pattern.each_with_index do |el, i|
|
59
|
+
return false unless is_match(actual[i], el)
|
60
|
+
end
|
61
|
+
true
|
62
|
+
else
|
63
|
+
@failure_message_for_should_fragments = "Fragment #{pattern.inspect}.size == #{pattern.size} where #{actual.inspect}.size == #{actual.size}"
|
64
|
+
false
|
65
|
+
end
|
66
|
+
elsif pattern == WILDCARD
|
67
|
+
!actual.blank?
|
68
|
+
else
|
69
|
+
actual == pattern
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
$:.push File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
require 'rspec'
|
10
|
+
require 'rspec/core'
|
11
|
+
require 'rspec/expectations'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec::Matchers.define :match_to do |expected|
|
17
|
+
match do |actual|
|
18
|
+
actual.matches?(expected)
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_for_should do |actual|
|
22
|
+
"expected that #{actual} matches to #{expected.inspect} (using #matches?)"
|
23
|
+
end
|
24
|
+
|
25
|
+
failure_message_for_should_not do |actual|
|
26
|
+
"expected that #{actual} doesn't match to #{expected.inspect} (using #matches?)"
|
27
|
+
end
|
28
|
+
|
29
|
+
description do
|
30
|
+
"match to #{expected.inspect}"
|
31
|
+
end
|
32
|
+
|
33
|
+
=begin
|
34
|
+
chain :after_matches do |actual|
|
35
|
+
@actual = actual
|
36
|
+
end
|
37
|
+
=end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require "bc-rspec-matchers/data_structure"
|
4
|
+
|
5
|
+
describe Bc::RSpec::Matchers::DataStructure do
|
6
|
+
describe "created with nil" do
|
7
|
+
subject do
|
8
|
+
Bc::RSpec::Matchers::DataStructure.new(nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
it { should match_to(nil) }
|
12
|
+
it { should_not match_to("") }
|
13
|
+
it { should_not match_to({}) }
|
14
|
+
it { should_not match_to([]) }
|
15
|
+
|
16
|
+
its(:description) { should == "match to nil" }
|
17
|
+
|
18
|
+
describe "after matches?(\"\")" do
|
19
|
+
before { subject.matches?("") }
|
20
|
+
|
21
|
+
its(:failure_message_for_should) { should == "expected DataStructure(nil) to match to \"\". Fragment nil didn't match to \"\"." }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "after matches?(nil)" do
|
25
|
+
before { subject.matches?(nil) }
|
26
|
+
|
27
|
+
its(:failure_message_for_should_not) { should == "expected DataStructure(nil) not to match to nil" }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "created with 'string'" do
|
32
|
+
subject do
|
33
|
+
Bc::RSpec::Matchers::DataStructure.new("string")
|
34
|
+
end
|
35
|
+
|
36
|
+
it { should match_to("string") }
|
37
|
+
it { should_not match_to(:string) }
|
38
|
+
it { should_not match_to(nil) }
|
39
|
+
|
40
|
+
its(:description) { should == "match to \"string\"" }
|
41
|
+
|
42
|
+
describe "after matches?(:symbol)" do
|
43
|
+
before { subject.matches?(:symbol) }
|
44
|
+
|
45
|
+
its(:failure_message_for_should) { should == "expected DataStructure(\"string\") to match to :symbol. Fragment \"string\" didn't match to :symbol." }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "after matches?(\"string\")" do
|
49
|
+
before { subject.matches?("string") }
|
50
|
+
|
51
|
+
its(:failure_message_for_should_not) { should == "expected DataStructure(\"string\") not to match to \"string\"" }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "created with :symbol" do
|
56
|
+
subject do
|
57
|
+
Bc::RSpec::Matchers::DataStructure.new(:symbol)
|
58
|
+
end
|
59
|
+
|
60
|
+
it { should match_to(:symbol) }
|
61
|
+
it { should_not match_to("symbol") }
|
62
|
+
it { should_not match_to(nil) }
|
63
|
+
|
64
|
+
its(:description) { should == "match to :symbol" }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "created with []" do
|
68
|
+
subject do
|
69
|
+
Bc::RSpec::Matchers::DataStructure.new([])
|
70
|
+
end
|
71
|
+
|
72
|
+
it { should match_to([]) }
|
73
|
+
it { should_not match_to([nil]) }
|
74
|
+
it { should_not match_to(["every", :array]) }
|
75
|
+
it { should_not match_to(nil) }
|
76
|
+
it { should_not match_to({}) }
|
77
|
+
|
78
|
+
its(:description) { should == "match to []" }
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "created with ['string']" do
|
82
|
+
subject do
|
83
|
+
Bc::RSpec::Matchers::DataStructure.new(["string"])
|
84
|
+
end
|
85
|
+
|
86
|
+
it { should match_to(["string"]) }
|
87
|
+
it { should_not match_to([:symbol, "string"]) }
|
88
|
+
it { should_not match_to(["string", :symbol]) }
|
89
|
+
it { should_not match_to([:string]) }
|
90
|
+
it { should_not match_to("string") }
|
91
|
+
it { should_not match_to(nil) }
|
92
|
+
it { should_not match_to([]) }
|
93
|
+
it { should_not match_to({}) }
|
94
|
+
|
95
|
+
its(:description) { should == "match to [\"string\"]" }
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "created with {}" do
|
99
|
+
subject do
|
100
|
+
Bc::RSpec::Matchers::DataStructure.new({})
|
101
|
+
end
|
102
|
+
|
103
|
+
it { should match_to({}) }
|
104
|
+
it { should match_to({:every => "hash"}) }
|
105
|
+
it { should_not match_to([]) }
|
106
|
+
it { should_not match_to(nil) }
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bc-rspec-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Byclosure
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-09-09 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
prerelease: false
|
31
|
+
type: :development
|
32
|
+
name: rake
|
33
|
+
requirement: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
|
+
name: ruby-debug
|
47
|
+
requirement: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
prerelease: false
|
59
|
+
type: :development
|
60
|
+
name: rspec
|
61
|
+
requirement: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
prerelease: false
|
73
|
+
type: :development
|
74
|
+
name: ZenTest
|
75
|
+
requirement: *id004
|
76
|
+
description: Collection of rspec matchers to improve spec writing performance
|
77
|
+
email:
|
78
|
+
- info@byclosure.com
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files: []
|
84
|
+
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .rspec
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- bc-rspec-matchers.gemspec
|
93
|
+
- lib/bc-rspec-matchers.rb
|
94
|
+
- lib/bc-rspec-matchers/data_structure.rb
|
95
|
+
- lib/bc-rspec-matchers/version.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/unit/data_structure_spec.rb
|
98
|
+
homepage: http://github.com/Byclosure/bc-rspec-matchers
|
99
|
+
licenses: []
|
100
|
+
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Collection of rspec matchers to improve spec writing performance
|
131
|
+
test_files:
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/unit/data_structure_spec.rb
|