jeremymcanally-matchy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +22 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +68 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/matchy.rb +16 -0
- data/lib/matchy/built_in/enumerable_expectations.rb +69 -0
- data/lib/matchy/built_in/error_expectations.rb +80 -0
- data/lib/matchy/built_in/operator_expectations.rb +97 -0
- data/lib/matchy/built_in/truth_expectations.rb +181 -0
- data/lib/matchy/expectation.rb +47 -0
- data/lib/matchy/modals.rb +46 -0
- data/lib/matchy/version.rb +9 -0
- data/matchy.gemspec +47 -0
- data/setup.rb +1585 -0
- data/test/test_enumerable_expectations.rb +91 -0
- data/test/test_error_expectations.rb +109 -0
- data/test/test_expectation_base.rb +35 -0
- data/test/test_modals.rb +27 -0
- data/test/test_operator_expectations.rb +159 -0
- data/test/test_truth_expectations.rb +217 -0
- metadata +79 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jeremy McAnally
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
matchy.gemspec
|
6
|
+
History.txt
|
7
|
+
License.txt
|
8
|
+
Manifest.txt
|
9
|
+
PostInstall.txt
|
10
|
+
README.rdoc
|
11
|
+
Rakefile
|
12
|
+
config/hoe.rb
|
13
|
+
config/requirements.rb
|
14
|
+
lib/matchy.rb
|
15
|
+
lib/matchy/version.rb
|
16
|
+
lib/matchy/expectation.rb
|
17
|
+
lib/matchy/modals.rb
|
18
|
+
lib/matchy/built_in/enumerable_expectations.rb
|
19
|
+
lib/matchy/built_in/error_expectations.rb
|
20
|
+
lib/matchy/built_in/operator_expectations.rb
|
21
|
+
lib/matchy/built_in/truth_expectations.rb
|
22
|
+
setup.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
= matchy
|
2
|
+
|
3
|
+
* http://github.com/jeremymcanally/matchy
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Hate writing assertions? Need a little behavior-driven love in your tests? Then matchy is for you.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Get the beauty of RSpec without all the overhead
|
12
|
+
* Create your own matchers (coming soon)
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
* Get BDD on your objects
|
17
|
+
|
18
|
+
x = 13 * 4
|
19
|
+
x.should == 42
|
20
|
+
|
21
|
+
y = "hello"
|
22
|
+
y.length.should_not be(4)
|
23
|
+
|
24
|
+
* Use familiar syntax to specify things
|
25
|
+
|
26
|
+
# RSpec
|
27
|
+
"my string".should =~ /string/
|
28
|
+
lambda { raise "FAIL" }.should raise_error
|
29
|
+
|
30
|
+
# matchy
|
31
|
+
"my string".should =~ /string/
|
32
|
+
lambda { raise "FAIL" }.should raise_error
|
33
|
+
|
34
|
+
* Get the speed of Test:Unit with the syntax of RSpec
|
35
|
+
|
36
|
+
== REQUIREMENTS:
|
37
|
+
|
38
|
+
* Test::Unit (you got it)
|
39
|
+
|
40
|
+
== INSTALL:
|
41
|
+
|
42
|
+
$ gem sources -a http://gems.github.com
|
43
|
+
$ sudo gem install jeremymcanally-matchy
|
44
|
+
|
45
|
+
== LICENSE:
|
46
|
+
|
47
|
+
(The MIT License)
|
48
|
+
|
49
|
+
Copyright (c) 2008 Jeremy McAnally
|
50
|
+
|
51
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
52
|
+
a copy of this software and associated documentation files (the
|
53
|
+
'Software'), to deal in the Software without restriction, including
|
54
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
55
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
56
|
+
permit persons to whom the Software is furnished to do so, subject to
|
57
|
+
the following conditions:
|
58
|
+
|
59
|
+
The above copyright notice and this permission notice shall be
|
60
|
+
included in all copies or substantial portions of the Software.
|
61
|
+
|
62
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
63
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
64
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
65
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
66
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
67
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
68
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'matchy/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Jeremy McAnally' # can also be an array of Authors
|
4
|
+
EMAIL = "jeremy@entp.com"
|
5
|
+
DESCRIPTION = "RSpec-esque matchers for use in Test::Unit"
|
6
|
+
GEM_NAME = 'matchy' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'matchy' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
# ['activesupport', '>= 1.3.1']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "unknown"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = YAML.load(`svn info`)['Revision']
|
37
|
+
VERS = Matchy::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'matchy documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README.rdoc",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.developer(AUTHOR, EMAIL)
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.summary = DESCRIPTION
|
57
|
+
p.url = HOMEPATH
|
58
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
59
|
+
p.test_globs = ["test/**/test_*.rb"]
|
60
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
61
|
+
|
62
|
+
# == Optional
|
63
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
64
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
65
|
+
|
66
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
67
|
+
end
|
68
|
+
|
69
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
70
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
71
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
72
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
73
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/lib/matchy.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
require 'matchy/expectation'
|
8
|
+
require 'matchy/modals'
|
9
|
+
require 'matchy/version'
|
10
|
+
|
11
|
+
require 'matchy/built_in/enumerable_expectations'
|
12
|
+
require 'matchy/built_in/error_expectations'
|
13
|
+
require 'matchy/built_in/truth_expectations'
|
14
|
+
require 'matchy/built_in/operator_expectations'
|
15
|
+
|
16
|
+
Test::Unit::TestCase.send(:include, Matchy::Expectations::TestCaseExtensions)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Matchy
|
2
|
+
module Expectations
|
3
|
+
class IncludeExpectation < Base
|
4
|
+
def matches?(receiver)
|
5
|
+
@receiver = receiver
|
6
|
+
@expected.each do |o|
|
7
|
+
return false unless receiver.include?(o)
|
8
|
+
end
|
9
|
+
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure_message
|
14
|
+
"Expected #{@receiver.inspect} to include #{@expected.inspect}."
|
15
|
+
end
|
16
|
+
|
17
|
+
def negative_failure_message
|
18
|
+
"Expected #{@receiver.inspect} to not include #{@expected.inspect}."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ExcludeExpectation < Base
|
23
|
+
def matches?(receiver)
|
24
|
+
@receiver = receiver
|
25
|
+
@expected.each do |o|
|
26
|
+
return false unless !receiver.include?(o)
|
27
|
+
end
|
28
|
+
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure_message
|
33
|
+
"Expected #{@receiver.inspect} to exclude #{@expected.inspect}."
|
34
|
+
end
|
35
|
+
|
36
|
+
def negative_failure_message
|
37
|
+
"Expected #{@receiver.inspect} to not exclude #{@expected.inspect}."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module TestCaseExtensions
|
42
|
+
# Calls +include?+ on the receiver for any object. You can also provide
|
43
|
+
# multiple arguments to see if all of them are included.
|
44
|
+
#
|
45
|
+
# ==== Examples
|
46
|
+
#
|
47
|
+
# [1,2,3].should include(1)
|
48
|
+
# [7,8,8].should_not include(3)
|
49
|
+
# ['a', 'b', 'c'].should include('a', 'c')
|
50
|
+
#
|
51
|
+
def include(*obj)
|
52
|
+
Matchy::Expectations::IncludeExpectation.new(obj, self)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Expects the receiver to exclude the given object(s). You can provide
|
56
|
+
# multiple arguments to see if all of them are included.
|
57
|
+
#
|
58
|
+
# ==== Examples
|
59
|
+
#
|
60
|
+
# [1,2,3].should exclude(16)
|
61
|
+
# [7,8,8].should_not exclude(7)
|
62
|
+
# ['a', 'b', 'c'].should exclude('e', 'f', 'g')
|
63
|
+
#
|
64
|
+
def exclude(*obj)
|
65
|
+
Matchy::Expectations::ExcludeExpectation.new(obj, self)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Matchy
|
2
|
+
module Expectations
|
3
|
+
class RaiseErrorExpectation < Base
|
4
|
+
def matches?(receiver)
|
5
|
+
@receiver = receiver
|
6
|
+
begin
|
7
|
+
receiver.call
|
8
|
+
return false
|
9
|
+
rescue StandardError => e
|
10
|
+
@error = e
|
11
|
+
return false unless e.class.ancestors.include?(@expected)
|
12
|
+
|
13
|
+
return true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
extra = ""
|
19
|
+
if @error
|
20
|
+
extra = "but #{@error.class.name} was raised instead"
|
21
|
+
else
|
22
|
+
extra = "but none was raised"
|
23
|
+
end
|
24
|
+
|
25
|
+
"Expected #{@receiver.inspect} to raise #{@expected.name}, #{extra}."
|
26
|
+
end
|
27
|
+
|
28
|
+
def negative_failure_message
|
29
|
+
"Expected #{@receiver.inspect} to not raise #{@expected.name}."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class ThrowSymbolExpectation < Base
|
34
|
+
def matches?(receiver)
|
35
|
+
@receiver = receiver
|
36
|
+
begin
|
37
|
+
receiver.call
|
38
|
+
rescue NameError => e
|
39
|
+
raise e unless e.message =~ /uncaught throw/
|
40
|
+
@thrown_symbol = e.name.to_sym
|
41
|
+
ensure
|
42
|
+
return @expected == @thrown_symbol
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def failure_message
|
47
|
+
"Expected #{@receiver.inspect} to throw :#{@expected}, but #{@thrown_symbol ? ':' + @thrown_symbol.to_s + ' was thrown instead' : 'no symbol was thrown'}."
|
48
|
+
end
|
49
|
+
|
50
|
+
def negative_failure_message
|
51
|
+
"Expected #{@receiver.inspect} to not throw :#{@expected}."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module TestCaseExtensions
|
56
|
+
# Expects a lambda to raise an error. You can specify the error or leave it blank to encompass
|
57
|
+
# any error.
|
58
|
+
#
|
59
|
+
# ==== Examples
|
60
|
+
#
|
61
|
+
# lambda { raise "FAILURE." }.should raise_error
|
62
|
+
# lambda { puts i_dont_exist }.should raise_error(NameError)
|
63
|
+
#
|
64
|
+
def raise_error(obj = StandardError)
|
65
|
+
Matchy::Expectations::RaiseErrorExpectation.new(obj, self)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Expects a lambda to throw an error.
|
69
|
+
#
|
70
|
+
# ==== Examples
|
71
|
+
#
|
72
|
+
# lambda { throw :thing }.should throw_symbol(:thing)
|
73
|
+
# lambda { "not this time" }.should_not throw_symbol(:hello)
|
74
|
+
#
|
75
|
+
def throw_symbol(obj)
|
76
|
+
Matchy::Expectations::ThrowSymbolExpectation.new(obj, self)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Matchy
|
2
|
+
module Expectations
|
3
|
+
# Class to handle operator expectations.
|
4
|
+
#
|
5
|
+
# ==== Examples
|
6
|
+
#
|
7
|
+
# 13.should == 13
|
8
|
+
# "hello".length.should_not == 2
|
9
|
+
#
|
10
|
+
class OperatorExpectation < Base
|
11
|
+
def initialize(receiver, match)
|
12
|
+
@receiver = receiver
|
13
|
+
@match = match
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(expected)
|
17
|
+
@expected = expected
|
18
|
+
if @receiver.send(:==, expected) == @match
|
19
|
+
pass!
|
20
|
+
else
|
21
|
+
fail!("==")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def ===(expected)
|
26
|
+
@expected = expected
|
27
|
+
if @receiver.send(:===, expected) == @match
|
28
|
+
pass!
|
29
|
+
else
|
30
|
+
fail!("===")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def =~(expected)
|
35
|
+
@expected = expected
|
36
|
+
if @receiver.send(:=~, expected).nil? != @match
|
37
|
+
pass!
|
38
|
+
else
|
39
|
+
fail!("=~")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def >(expected)
|
44
|
+
@expected = expected
|
45
|
+
if @receiver.send(:>, expected) == @match
|
46
|
+
pass!
|
47
|
+
else
|
48
|
+
fail!(">")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def <(expected)
|
53
|
+
@expected = expected
|
54
|
+
if @receiver.send(:<, expected) == @match
|
55
|
+
pass!
|
56
|
+
else
|
57
|
+
fail!("<")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def >=(expected)
|
62
|
+
@expected = expected
|
63
|
+
if @receiver.send(:>=, expected) == @match
|
64
|
+
pass!
|
65
|
+
else
|
66
|
+
fail!(">=")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def <=(expected)
|
71
|
+
@expected = expected
|
72
|
+
if @receiver.send(:<=, expected) == @match
|
73
|
+
pass!
|
74
|
+
else
|
75
|
+
fail!("<=")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
def pass!
|
81
|
+
assert true
|
82
|
+
end
|
83
|
+
|
84
|
+
def fail!(operator)
|
85
|
+
flunk failure_message(@match ? failure_message(operator) : negative_failure_message(operator))
|
86
|
+
end
|
87
|
+
|
88
|
+
def failure_message(operator)
|
89
|
+
"Expected #{@receiver.inspect} to #{operator} #{@expected.inspect}."
|
90
|
+
end
|
91
|
+
|
92
|
+
def negative_failure_message(operator)
|
93
|
+
"Expected #{@receiver.inspect} to not #{operator} #{@expected.inspect}."
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|