rspec_multi_matchers 1.0.6 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- metadata +18 -68
- data/History.txt +0 -4
- data/Manifest.txt +0 -18
- data/README.rdoc +0 -77
- data/Rakefile +0 -27
- data/lib/match_each.rb +0 -78
- data/lib/match_enum.rb +0 -66
- data/lib/match_in_order.rb +0 -31
- data/lib/rspec_multi_matchers.rb +0 -10
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/match_each_spec.rb +0 -23
- data/spec/match_enum_spec.rb +0 -14
- data/spec/match_in_order_spec.rb +0 -30
- data/spec/shared_enum_spec.rb +0 -30
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -12
- data/tasks/rspec.rake +0 -21
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_multi_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
9
|
+
- 8
|
10
|
+
version: 1.0.8
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Greg Weber
|
@@ -14,81 +15,31 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-03-31 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 7
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 5
|
30
|
-
- 2
|
31
|
-
version: 1.5.2
|
32
|
-
version:
|
33
|
-
type: :development
|
34
|
-
version_requirement:
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: hoe
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 5
|
43
|
-
segments:
|
44
|
-
- 2
|
45
|
-
- 3
|
46
|
-
- 3
|
47
|
-
version: 2.3.3
|
48
|
-
version:
|
49
|
-
type: :development
|
50
|
-
version_requirement:
|
51
|
-
version_requirements: *id002
|
52
|
-
description: ""
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: better collection testing
|
53
23
|
email:
|
54
|
-
- ""
|
55
24
|
executables: []
|
56
25
|
|
57
26
|
extensions: []
|
58
27
|
|
59
|
-
extra_rdoc_files:
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
- History.txt
|
64
|
-
- Manifest.txt
|
65
|
-
- README.rdoc
|
66
|
-
- Rakefile
|
67
|
-
- lib/match_each.rb
|
68
|
-
- lib/match_enum.rb
|
69
|
-
- lib/match_in_order.rb
|
70
|
-
- lib/rspec_multi_matchers.rb
|
71
|
-
- script/console
|
72
|
-
- script/destroy
|
73
|
-
- script/generate
|
74
|
-
- spec/match_each_spec.rb
|
75
|
-
- spec/match_enum_spec.rb
|
76
|
-
- spec/match_in_order_spec.rb
|
77
|
-
- spec/shared_enum_spec.rb
|
78
|
-
- spec/spec.opts
|
79
|
-
- spec/spec_helper.rb
|
80
|
-
- tasks/rspec.rake
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files: []
|
31
|
+
|
81
32
|
has_rdoc: true
|
82
33
|
homepage:
|
83
34
|
licenses: []
|
84
35
|
|
85
36
|
post_install_message:
|
86
|
-
rdoc_options:
|
87
|
-
|
88
|
-
- README.txt
|
37
|
+
rdoc_options: []
|
38
|
+
|
89
39
|
require_paths:
|
90
40
|
- lib
|
91
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
92
43
|
requirements:
|
93
44
|
- - ">="
|
94
45
|
- !ruby/object:Gem::Version
|
@@ -96,8 +47,8 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
47
|
segments:
|
97
48
|
- 0
|
98
49
|
version: "0"
|
99
|
-
version:
|
100
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
101
52
|
requirements:
|
102
53
|
- - ">="
|
103
54
|
- !ruby/object:Gem::Version
|
@@ -105,11 +56,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
56
|
segments:
|
106
57
|
- 0
|
107
58
|
version: "0"
|
108
|
-
version:
|
109
59
|
requirements: []
|
110
60
|
|
111
|
-
rubyforge_project:
|
112
|
-
rubygems_version: 1.
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.6.2
|
113
63
|
signing_key:
|
114
64
|
specification_version: 3
|
115
65
|
summary: better collection testing
|
data/History.txt
DELETED
data/Manifest.txt
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.rdoc
|
4
|
-
Rakefile
|
5
|
-
lib/match_each.rb
|
6
|
-
lib/match_enum.rb
|
7
|
-
lib/match_in_order.rb
|
8
|
-
lib/rspec_multi_matchers.rb
|
9
|
-
script/console
|
10
|
-
script/destroy
|
11
|
-
script/generate
|
12
|
-
spec/match_each_spec.rb
|
13
|
-
spec/match_enum_spec.rb
|
14
|
-
spec/match_in_order_spec.rb
|
15
|
-
spec/shared_enum_spec.rb
|
16
|
-
spec/spec.opts
|
17
|
-
spec/spec_helper.rb
|
18
|
-
tasks/rspec.rake
|
data/README.rdoc
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
= rspec-multi-matchers
|
2
|
-
|
3
|
-
== Summary
|
4
|
-
* test collection using each or other enumerable methods
|
5
|
-
* tests fell more natural and have a friendlier failure message
|
6
|
-
|
7
|
-
== HomePage
|
8
|
-
* http://github.com/gregwebs/rspec-multi-matchers
|
9
|
-
|
10
|
-
== DESCRIPTION:
|
11
|
-
|
12
|
-
* match_each
|
13
|
-
* match_enum
|
14
|
-
* match_in_order
|
15
|
-
|
16
|
-
require 'rubygems'
|
17
|
-
require 'spec'
|
18
|
-
require 'rspec_multi_matchers'
|
19
|
-
|
20
|
-
describe 'array of ones' do
|
21
|
-
it 'should be all ones' do
|
22
|
-
[1,2,3].should each { |n|
|
23
|
-
n.should == 1
|
24
|
-
}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
=begin output
|
29
|
-
'array of ones should fail on 2' FAILED
|
30
|
-
line: 14
|
31
|
-
item 1: 2
|
32
|
-
expected: 1,
|
33
|
-
got: 2 (using ==)
|
34
|
-
=end
|
35
|
-
|
36
|
-
As expected, the output shows expected and got fields
|
37
|
-
line is the line number of the expectiation inside the block
|
38
|
-
the item line gives the index of the item being yielded to the block, and the item itself
|
39
|
-
|
40
|
-
|
41
|
-
=== Warning
|
42
|
-
|
43
|
-
Note the use of brackets '{ ... }' instead of 'do ... end'
|
44
|
-
this is necessary because 'do .. end' does not bind strong enough
|
45
|
-
|
46
|
-
== RELATED ARTICLES:
|
47
|
-
|
48
|
-
* http://blog.thoughtfolder.com/2008-11-05-rspec-should-each-matcher.html
|
49
|
-
|
50
|
-
== INSTALL:
|
51
|
-
|
52
|
-
* gem install rspec_multi_matchers
|
53
|
-
|
54
|
-
== LICENSE:
|
55
|
-
|
56
|
-
(The MIT License)
|
57
|
-
|
58
|
-
Copyright (c) 2008 Greg Weber
|
59
|
-
|
60
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
61
|
-
a copy of this software and associated documentation files (the
|
62
|
-
'Software'), to deal in the Software without restriction, including
|
63
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
64
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
65
|
-
permit persons to whom the Software is furnished to do so, subject to
|
66
|
-
the following conditions:
|
67
|
-
|
68
|
-
The above copyright notice and this permission notice shall be
|
69
|
-
included in all copies or substantial portions of the Software.
|
70
|
-
|
71
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
72
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
73
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
74
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
75
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
76
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
77
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem rubigen hoe].each { |f| require f }
|
2
|
-
require File.dirname(__FILE__) + '/lib/rspec_multi_matchers'
|
3
|
-
|
4
|
-
# Generate all the Rake tasks
|
5
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
-
$hoe = Hoe.new('rspec_multi_matchers', RspecMultiMatchers::VERSION) do |p|
|
7
|
-
p.developer('Greg Weber', '')
|
8
|
-
p.summary = "better collection testing"
|
9
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
|
-
# p.extra_deps = [
|
11
|
-
# ['activesupport','>= 2.0.2'],
|
12
|
-
# ]
|
13
|
-
p.extra_dev_deps = [
|
14
|
-
['newgem', ">= #{::Newgem::VERSION}"]
|
15
|
-
]
|
16
|
-
|
17
|
-
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
18
|
-
#path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
19
|
-
#p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
20
|
-
#p.rsync_args = '-av --delete --ignore-errors'
|
21
|
-
end
|
22
|
-
|
23
|
-
require 'newgem/tasks' # load /tasks/*.rake
|
24
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
25
|
-
|
26
|
-
remove_task :default
|
27
|
-
task :default => [:spec]
|
data/lib/match_each.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
class MatchEach
|
2
|
-
|
3
|
-
class MatchEachError < Exception; end
|
4
|
-
class NoBlockGivenError < MatchEachError; end
|
5
|
-
|
6
|
-
class BlankEnumerableError < MatchEachError; end
|
7
|
-
|
8
|
-
def initialize(options, &block)
|
9
|
-
@empty_okay = (options and options[:empty])
|
10
|
-
unless @block = block
|
11
|
-
raise NoBlockGivenError, 'No block given. You probably need to use brackets "{...}" instead of "do...end"'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def matches?(target)
|
16
|
-
if target.nil?
|
17
|
-
raise BlankEnumerableError, "Expected an enumerable object, but got nil"
|
18
|
-
end
|
19
|
-
|
20
|
-
if !@empty_okay && target.empty?
|
21
|
-
raise BlankEnumerableError, "No items in the given enumerator.\nTo allow an empty enumerator pass the :empty option with a true value"
|
22
|
-
end
|
23
|
-
|
24
|
-
@counter = 0
|
25
|
-
target.each do |obj|
|
26
|
-
begin
|
27
|
-
@block.call(obj)
|
28
|
-
rescue Spec::Expectations::ExpectationNotMetError => e
|
29
|
-
@error = e
|
30
|
-
@failure_object = obj
|
31
|
-
return false
|
32
|
-
end
|
33
|
-
@counter += 1
|
34
|
-
end
|
35
|
-
true
|
36
|
-
end
|
37
|
-
|
38
|
-
def object_description
|
39
|
-
insp = @failure_object.inspect
|
40
|
-
return insp if insp.length < 300
|
41
|
-
|
42
|
-
if @failure_object.respond_to?(:to_s)
|
43
|
-
str = @failure_object.to_s
|
44
|
-
return str if str .length < 300
|
45
|
-
end
|
46
|
-
|
47
|
-
insp[0..300] + ' ... '
|
48
|
-
end
|
49
|
-
|
50
|
-
def failure_line
|
51
|
-
# find 'matches?' in statck trace
|
52
|
-
# then move back to the first line number that is not a function call
|
53
|
-
error_line = nil
|
54
|
-
@error.backtrace.each do |line|
|
55
|
-
if line.match(/:\d+:in\s*[`'"](.*)[`'"]\s*$/)
|
56
|
-
return error_line if $1 == 'matches?'
|
57
|
-
else
|
58
|
-
error_line = line.match(/^[^:]+:(\d+)/)[1]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
nil # should not reach here
|
63
|
-
end
|
64
|
-
|
65
|
-
def failure_message
|
66
|
-
padding = ' ' * if @error.message =~ /expected not/ then 4 else 0 end
|
67
|
-
|
68
|
-
[" line: #{failure_line}",
|
69
|
-
" item #{@counter}: #{object_description}"
|
70
|
-
].map { |line| padding + line }.push(@error.message).join("\n")
|
71
|
-
end
|
72
|
-
|
73
|
-
# no need for should_not, so no negative_failure_messages
|
74
|
-
end
|
75
|
-
|
76
|
-
def each(options=nil, &block)
|
77
|
-
MatchEach.new options, &block
|
78
|
-
end
|
data/lib/match_enum.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
class MatchEnum
|
2
|
-
@@enum_methods = [] # avoid re-defining
|
3
|
-
|
4
|
-
class MatchEnumError < Exception; end
|
5
|
-
class BlankEnumerableError < MatchEnumError; end
|
6
|
-
class NoBlockGivenError < MatchEnumError; end
|
7
|
-
|
8
|
-
def initialize(method, options, &block)
|
9
|
-
@method = method
|
10
|
-
@empty_okay = (options and options[:empty])
|
11
|
-
@block = block
|
12
|
-
if !@block
|
13
|
-
raise NoBlockGivenError, 'no block given, you probably need to use brackets instead of "do...end"'
|
14
|
-
end
|
15
|
-
|
16
|
-
@num_args = @block.arity
|
17
|
-
@num_args = 0 if @num_args == -1 # correct ruby error
|
18
|
-
return if @@enum_methods[@num_args]
|
19
|
-
@@enum_methods[@num_args] = true
|
20
|
-
|
21
|
-
args = (1..(@num_args)).map {|i| 'arg_' << i.to_s}.join(',')
|
22
|
-
eval <<-EOS
|
23
|
-
def enum_#{@num_args}(target)
|
24
|
-
@counter = 0
|
25
|
-
target.send(@method) do |#{args}|
|
26
|
-
begin
|
27
|
-
@block.call(#{args})
|
28
|
-
rescue Spec::Expectations::ExpectationNotMetError => e
|
29
|
-
@error_msg = e.to_s
|
30
|
-
@failure_object = [#{args}]
|
31
|
-
return false
|
32
|
-
end
|
33
|
-
@counter += 1
|
34
|
-
end
|
35
|
-
true
|
36
|
-
end
|
37
|
-
EOS
|
38
|
-
end
|
39
|
-
|
40
|
-
def enum(target)
|
41
|
-
eval("enum_#{@num_args}(target)")
|
42
|
-
end
|
43
|
-
|
44
|
-
def matches?(target)
|
45
|
-
if target.nil?
|
46
|
-
raise BlankEnumerableError, "Expected an enumerable object, but got nil"
|
47
|
-
end
|
48
|
-
|
49
|
-
if !@empty_okay && target.empty?
|
50
|
-
raise BlankEnumerableError, "No items in the given enumerator.\nTo allow an empty enumerator pass the :empty option with a true value"
|
51
|
-
end
|
52
|
-
|
53
|
-
return enum(target)
|
54
|
-
end
|
55
|
-
|
56
|
-
def failure_message
|
57
|
-
if @error_msg =~ /expected not/ then ' ' else '' end <<
|
58
|
-
" item #{@counter}: #{@failure_object.inspect}\n#{@error_msg}"
|
59
|
-
end
|
60
|
-
|
61
|
-
# no need for should_not, so no negative_failure_messages
|
62
|
-
end
|
63
|
-
|
64
|
-
def enum(method, options=nil, &block)
|
65
|
-
MatchEnum.new method, options, &block
|
66
|
-
end
|
data/lib/match_in_order.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class MatchInOrder
|
2
|
-
def initialize(regexps)
|
3
|
-
@regexps = regexps
|
4
|
-
end
|
5
|
-
|
6
|
-
def matches?(target)
|
7
|
-
@target = target
|
8
|
-
@regexps.inject(target) do |str, regexp|
|
9
|
-
m = str.match(regexp)
|
10
|
-
if m.nil?
|
11
|
-
@failure_string = str
|
12
|
-
@failure_regex = regexp
|
13
|
-
return false
|
14
|
-
end
|
15
|
-
m.post_match
|
16
|
-
end
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
def failure_message
|
21
|
-
"expected #{@failure_string.inspect} to match #{@failure_regex.inspect}\nwithin string: #{@target.inspect}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def negative_failure_message
|
25
|
-
"expected #{@target.inspect} to not match in order against: #{@regexps.inspect}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def match_in_order(*regexps)
|
30
|
-
MatchInOrder.new(regexps)
|
31
|
-
end
|
data/lib/rspec_multi_matchers.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
4
|
-
module RspecMultiMatchers
|
5
|
-
VERSION = '1.0.6'
|
6
|
-
end
|
7
|
-
|
8
|
-
require "match_each"
|
9
|
-
require "match_enum"
|
10
|
-
require "match_in_order"
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/rspec_multi_matchers.rb'}"
|
9
|
-
puts "Loading rspec_multi_matchers gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/match_each_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe MatchEach do
|
4
|
-
it_should_behave_like "each matcher"
|
5
|
-
|
6
|
-
before do
|
7
|
-
@class = MatchEach
|
8
|
-
@iterator = [:each]
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should add to the inner error message' do
|
12
|
-
begin
|
13
|
-
2.should == 1
|
14
|
-
rescue Spec::Expectations::ExpectationNotMetError => e
|
15
|
-
@line = __LINE__ + 2
|
16
|
-
lambda{ [1,2,3].should each { |n|
|
17
|
-
n.should == 1
|
18
|
-
} }.should raise_error(
|
19
|
-
Spec::Expectations::ExpectationNotMetError, /^\s*line: #{@line}\s*item 1: 2\s*#{Regexp.escape(e.message)}/m)
|
20
|
-
else fail
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/spec/match_enum_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe MatchEnum do
|
4
|
-
it_should_behave_like "each matcher"
|
5
|
-
|
6
|
-
before do
|
7
|
-
@class = MatchEnum
|
8
|
-
@iterator = [:enum, :each]
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should enum with each_with_index' do
|
12
|
-
[1,2,3].should enum(:each_with_index) { |n,i| n.should == i + 1 }
|
13
|
-
end
|
14
|
-
end
|
data/spec/match_in_order_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe MatchInOrder do
|
4
|
-
|
5
|
-
it "should match a single regular expression" do
|
6
|
-
"a".should match_in_order(//)
|
7
|
-
"a".should match_in_order(/a/)
|
8
|
-
"a".should_not match_in_order(/b/)
|
9
|
-
"z".should_not match_in_order(/a/)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should not match the same regular expressions twice" do
|
13
|
-
"a".should_not match_in_order(/a/,/a/)
|
14
|
-
lambda{ "a".should match_in_order(/a/,/a/) }.should raise_error(Spec::Expectations::ExpectationNotMetError, 'expected "" to match /a/' << "\n" << 'within string: "a"')
|
15
|
-
|
16
|
-
"abc".should_not match_in_order(/a/,/b/,/c/,/a/)
|
17
|
-
lambda{ "abc".should match_in_order(/a/,/b/,/c/,/a/) }.should raise_error(Spec::Expectations::ExpectationNotMetError, 'expected "" to match /a/' << "\n" << 'within string: "abc"')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should match multiple regular expressions in order" do
|
21
|
-
"abc".should match_in_order(/a/,/b/,/c/)
|
22
|
-
lambda{ "abc".should_not match_in_order(/a/,/b/,/c/) }.should raise_error(Spec::Expectations::ExpectationNotMetError,'expected "abc" to not match in order against: [/a/, /b/, /c/]')
|
23
|
-
|
24
|
-
"abc".should_not match_in_order(/a/,/c/,/b/)
|
25
|
-
lambda{ "abc".should match_in_order(/a/,/c/,/b/) }.should raise_error(Spec::Expectations::ExpectationNotMetError,'expected "" to match /b/' << "\n" << 'within string: "abc"')
|
26
|
-
|
27
|
-
"abc".should_not match_in_order(/b/,/a/,/c/)
|
28
|
-
lambda{ "abc".should match_in_order(/b/,/a/,/c/) }.should raise_error(Spec::Expectations::ExpectationNotMetError,'expected "c" to match /a/' << "\n" << 'within string: "abc"')
|
29
|
-
end
|
30
|
-
end
|
data/spec/shared_enum_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
shared_examples_for "each matcher" do
|
2
|
-
it 'should raise an error when a block is not given' do
|
3
|
-
# do...end does not bind strongly enough, must use brackets
|
4
|
-
lambda do
|
5
|
-
[1,2,3].should send(*@iterator) do |n| n.should == n end
|
6
|
-
end.should raise_error(@class::NoBlockGivenError)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should not raise an error for met expectations' do
|
10
|
-
i = 0
|
11
|
-
[1,2,3].should send(*@iterator) {|n| n.should == (i+=1)}
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should raise an error if there are no items in the enumerable object' do
|
15
|
-
lambda{ [].should send(*@iterator){} }.should raise_error(@class::BlankEnumerableError)
|
16
|
-
[false, nil].each do |f|
|
17
|
-
@iterator.push(:empty => f)
|
18
|
-
lambda{ [].should send(*@iterator){}}.should raise_error(@class::BlankEnumerableError)
|
19
|
-
@iterator.pop
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should not raise an error if there are no items in the enumerable object and the empty flag is passed' do
|
24
|
-
['okay', true].each do |t|
|
25
|
-
@iterator.push(:empty => t)
|
26
|
-
lambda{ [].should send(*@iterator){} }.should_not raise_error
|
27
|
-
@iterator.pop
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|
data/spec/spec_helper.rb
DELETED
data/tasks/rspec.rake
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'spec'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems'
|
5
|
-
require 'spec'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'spec/rake/spectask'
|
9
|
-
rescue LoadError
|
10
|
-
puts <<-EOS
|
11
|
-
To use rspec for testing you must install rspec gem:
|
12
|
-
gem install rspec
|
13
|
-
EOS
|
14
|
-
exit(0)
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Run the specs under spec/models"
|
18
|
-
Spec::Rake::SpecTask.new do |t|
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
-
end
|