mofo 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/microformat.rb +11 -1
- data/lib/microformat/simple.rb +21 -17
- data/lib/mofo/hentry.rb +1 -1
- data/lib/mofo/hreview.rb +0 -2
- data/lib/mofo/rel_tag.rb +0 -1
- data/tests/fixtures/bob.html +69 -0
- data/tests/fixtures/chowhound.html +1052 -0
- data/tests/fixtures/corkd.html +403 -0
- data/tests/fixtures/events.html +39 -0
- data/tests/fixtures/fake.html +1 -0
- data/tests/fixtures/fauxtank.html +535 -0
- data/tests/fixtures/hatom.html +1101 -0
- data/tests/fixtures/simple.html +5 -0
- data/tests/fixtures/upcoming.html +335 -0
- data/tests/format_test.rb +230 -0
- data/tests/hatom_test.rb +39 -0
- data/tests/test_helper.rb +6 -0
- data/tests/xoxo_test.rb +49 -0
- data/vendor/testspec-0.2.0/ChangeLog +120 -0
- data/vendor/testspec-0.2.0/README +206 -0
- data/vendor/testspec-0.2.0/ROADMAP +3 -0
- data/vendor/testspec-0.2.0/Rakefile +86 -0
- data/vendor/testspec-0.2.0/SPECS +101 -0
- data/vendor/testspec-0.2.0/TODO +1 -0
- data/vendor/testspec-0.2.0/bin/specrb +103 -0
- data/vendor/testspec-0.2.0/examples/stack.rb +38 -0
- data/vendor/testspec-0.2.0/examples/stack_spec.rb +119 -0
- data/vendor/testspec-0.2.0/lib/test/spec.rb +366 -0
- data/vendor/testspec-0.2.0/lib/test/spec/dox.rb +114 -0
- data/vendor/testspec-0.2.0/lib/test/spec/rdox.rb +25 -0
- data/vendor/testspec-0.2.0/lib/test/spec/should-output.rb +48 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Kernel.html +105 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Object.html +154 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Spec.html +132 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Spec/DefinitionError.html +111 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Spec/Should.html +863 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Spec/ShouldNot.html +411 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Spec/TestCase.html +220 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Spec/TestCase/ClassMethods.html +290 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Spec/TestCase/InstanceMethods.html +195 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Unit/UI/RDox/TestRunner.html +222 -0
- data/vendor/testspec-0.2.0/rdoc/classes/Test/Unit/UI/SpecDox/TestRunner.html +468 -0
- data/vendor/testspec-0.2.0/rdoc/created.rid +1 -0
- data/vendor/testspec-0.2.0/rdoc/files/README.html +409 -0
- data/vendor/testspec-0.2.0/rdoc/files/ROADMAP.html +112 -0
- data/vendor/testspec-0.2.0/rdoc/files/SPECS.html +365 -0
- data/vendor/testspec-0.2.0/rdoc/files/lib/test/spec/dox_rb.html +108 -0
- data/vendor/testspec-0.2.0/rdoc/files/lib/test/spec/rdox_rb.html +108 -0
- data/vendor/testspec-0.2.0/rdoc/files/lib/test/spec/should-output_rb.html +114 -0
- data/vendor/testspec-0.2.0/rdoc/files/lib/test/spec_rb.html +123 -0
- data/vendor/testspec-0.2.0/rdoc/fr_class_index.html +37 -0
- data/vendor/testspec-0.2.0/rdoc/fr_file_index.html +33 -0
- data/vendor/testspec-0.2.0/rdoc/fr_method_index.html +95 -0
- data/vendor/testspec-0.2.0/rdoc/index.html +24 -0
- data/vendor/testspec-0.2.0/rdoc/rdoc-style.css +208 -0
- data/vendor/testspec-0.2.0/test/spec_dox.rb +39 -0
- data/vendor/testspec-0.2.0/test/spec_flexmock.rb +210 -0
- data/vendor/testspec-0.2.0/test/spec_mocha.rb +118 -0
- data/vendor/testspec-0.2.0/test/spec_nestedcontexts.rb +26 -0
- data/vendor/testspec-0.2.0/test/spec_should-output.rb +26 -0
- data/vendor/testspec-0.2.0/test/spec_testspec.rb +311 -0
- data/vendor/testspec-0.2.0/test/spec_testspec_order.rb +26 -0
- data/vendor/testspec-0.2.0/test/test_testunit.rb +21 -0
- metadata +81 -2
@@ -0,0 +1,101 @@
|
|
1
|
+
|
2
|
+
== TestUnit
|
3
|
+
* still works on its own
|
4
|
+
* supports should good enough
|
5
|
+
* works inside test/spec
|
6
|
+
|
7
|
+
== SpecDox
|
8
|
+
* can unmangle Test::Unit names correctly
|
9
|
+
* can unmangle Test::Spec names correctly
|
10
|
+
* has sensible fallbacks
|
11
|
+
|
12
|
+
== flexmock
|
13
|
+
* should handle
|
14
|
+
* should handle without a block
|
15
|
+
* should handle with a block
|
16
|
+
* should have a return value
|
17
|
+
* should handle missing methods
|
18
|
+
* should ignore missing methods
|
19
|
+
* should count correctly
|
20
|
+
* should raise on bad counts
|
21
|
+
* should handle undetermined counts
|
22
|
+
* should handle zero counts
|
23
|
+
* should have file IO with use
|
24
|
+
* should have use
|
25
|
+
* should handle failures during use
|
26
|
+
* should deal with sequential values
|
27
|
+
* respond_to? should return false for non handled methods
|
28
|
+
* respond_to? should return true for explicit methods
|
29
|
+
* respond_to? should return true when ignoring_missing
|
30
|
+
* respond_to? should return true for missing_methods when should_ignore_missing
|
31
|
+
* should raise error on unknown method proc
|
32
|
+
* should return callable proc on method
|
33
|
+
* should return do nothing proc for missing methods
|
34
|
+
* works with test/spec
|
35
|
+
|
36
|
+
== mocha
|
37
|
+
* works with test/spec
|
38
|
+
* works with test/spec and Enterprise example
|
39
|
+
|
40
|
+
== stubba
|
41
|
+
* works with test/spec and instance method stubbing
|
42
|
+
* works with test/spec and class method stubbing
|
43
|
+
* works with test/spec and global instance method stubbing
|
44
|
+
|
45
|
+
== Outer context
|
46
|
+
=== Inner context
|
47
|
+
* is nested
|
48
|
+
* has multiple empty specifications
|
49
|
+
=== Second Inner context
|
50
|
+
* is indented properly
|
51
|
+
* still runs in order of definition
|
52
|
+
==== Inmost context
|
53
|
+
* works too!
|
54
|
+
* whoo!
|
55
|
+
|
56
|
+
== should.output
|
57
|
+
* works for print
|
58
|
+
* works for puts
|
59
|
+
* works with readline
|
60
|
+
|
61
|
+
== test/spec
|
62
|
+
* has should.satisfy
|
63
|
+
* has should.equal
|
64
|
+
* has should.raise
|
65
|
+
* should.raise should return the exception
|
66
|
+
* has should.be_an_instance_of
|
67
|
+
* has should.be_nil
|
68
|
+
* has should.include
|
69
|
+
* has should.be_a_kind_of
|
70
|
+
* has should.match
|
71
|
+
* has should.be
|
72
|
+
* has should.not.raise
|
73
|
+
* has should.not.be
|
74
|
+
* has should.not.equal
|
75
|
+
* has should.not.match
|
76
|
+
* has should.throw
|
77
|
+
* has should.not.throw
|
78
|
+
* has should.respond_to
|
79
|
+
* has should.be_close
|
80
|
+
* multiple negation works
|
81
|
+
* has should.<predicate>
|
82
|
+
* has should <operator> (>, >=, <, <=, ===)
|
83
|
+
* is robust against careless users
|
84
|
+
|
85
|
+
== setup/teardown
|
86
|
+
* run in the right order
|
87
|
+
|
88
|
+
== contexts
|
89
|
+
* are defined in class scope
|
90
|
+
* can include modules
|
91
|
+
|
92
|
+
== Context First
|
93
|
+
* runs before Second
|
94
|
+
|
95
|
+
== Context Second
|
96
|
+
* runs before Last
|
97
|
+
|
98
|
+
== Context Last
|
99
|
+
* runs last
|
100
|
+
|
101
|
+
70 specifications (267 requirements), 0 failures
|
@@ -0,0 +1 @@
|
|
1
|
+
- see ROADMAP
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
testrbargv = []
|
7
|
+
automatic = false
|
8
|
+
|
9
|
+
opts = OptionParser.new("", 24, ' ') { |opts|
|
10
|
+
opts.banner = "Usage: specrb [options] [files | -a] [-- untouched arguments]"
|
11
|
+
|
12
|
+
opts.separator ""
|
13
|
+
opts.separator "Ruby options:"
|
14
|
+
|
15
|
+
lineno = 1
|
16
|
+
opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
|
17
|
+
eval line, TOPLEVEL_BINDING, "-e", lineno
|
18
|
+
lineno += 1
|
19
|
+
}
|
20
|
+
|
21
|
+
opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
|
22
|
+
$DEBUG = true
|
23
|
+
}
|
24
|
+
opts.on("-w", "--warn", "turn warnings on for your script") {
|
25
|
+
$-w = true
|
26
|
+
}
|
27
|
+
|
28
|
+
opts.on("-I", "--include PATH",
|
29
|
+
"specify $LOAD_PATH (may be used more than once)") { |path|
|
30
|
+
$LOAD_PATH.concat path.split(":")
|
31
|
+
}
|
32
|
+
|
33
|
+
opts.on("-r", "--require LIBRARY",
|
34
|
+
"require the library, before executing your script") { |library|
|
35
|
+
require library
|
36
|
+
}
|
37
|
+
|
38
|
+
opts.separator ""
|
39
|
+
opts.separator "test/spec options:"
|
40
|
+
|
41
|
+
opts.on("-s", "--specdox", "do AgileDox-like output") {
|
42
|
+
testrbargv << "--runner=specdox"
|
43
|
+
}
|
44
|
+
opts.on("--rdox", "do AgileDox-like output with RDoc formatting") {
|
45
|
+
testrbargv << "--runner=rdox"
|
46
|
+
}
|
47
|
+
|
48
|
+
opts.on("-a", "--automatic", "gather tests from ./test/") {
|
49
|
+
automatic = true
|
50
|
+
}
|
51
|
+
|
52
|
+
opts.separator ""
|
53
|
+
opts.separator "test/unit options:"
|
54
|
+
|
55
|
+
opts.on('-n', '--name NAME', String,
|
56
|
+
"runs tests matching regexp NAME") { |n|
|
57
|
+
testrbargv << "-n" << "/#{n}/"
|
58
|
+
}
|
59
|
+
|
60
|
+
opts.on('-t', '--testcase TESTCASE', String,
|
61
|
+
"runs tests in TestCases matching regexp TESTCASE") { |t|
|
62
|
+
testrbargv << "-t" << "/#{t}/"
|
63
|
+
}
|
64
|
+
|
65
|
+
opts.separator ""
|
66
|
+
opts.separator "Common options:"
|
67
|
+
|
68
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
69
|
+
puts opts
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on_tail("--version", "Show version") do
|
74
|
+
require 'test/spec'
|
75
|
+
puts "specrb #{Test::Spec::VERSION}"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
opts.parse! ARGV
|
80
|
+
}
|
81
|
+
|
82
|
+
files = ARGV
|
83
|
+
|
84
|
+
if automatic
|
85
|
+
files.concat Dir["test/test_*.rb"]
|
86
|
+
files.concat Dir["test/spec_*.rb"]
|
87
|
+
files.concat Dir["spec/spec_*.rb"]
|
88
|
+
end
|
89
|
+
|
90
|
+
if files.empty?
|
91
|
+
puts opts.banner
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
argv = testrbargv + ["--"] + files
|
96
|
+
|
97
|
+
require 'test/spec'
|
98
|
+
|
99
|
+
Test::Unit.run = false
|
100
|
+
runner = Test::Unit::AutoRunner.new true
|
101
|
+
runner.process_args(argv) ||
|
102
|
+
abort("internal error calling Test::Unit, please report a bug")
|
103
|
+
exit runner.run
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copied without code changes from RSpec.
|
2
|
+
|
3
|
+
class StackUnderflowError < RuntimeError
|
4
|
+
end
|
5
|
+
|
6
|
+
class StackOverflowError < RuntimeError
|
7
|
+
end
|
8
|
+
|
9
|
+
class Stack
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@items = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def push object
|
16
|
+
raise StackOverflowError if @items.length == 10
|
17
|
+
@items.push object
|
18
|
+
end
|
19
|
+
|
20
|
+
def pop
|
21
|
+
raise StackUnderflowError if @items.empty?
|
22
|
+
@items.delete @items.last
|
23
|
+
end
|
24
|
+
|
25
|
+
def peek
|
26
|
+
raise StackUnderflowError if @items.empty?
|
27
|
+
@items.last
|
28
|
+
end
|
29
|
+
|
30
|
+
def empty?
|
31
|
+
@items.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def full?
|
35
|
+
@items.length == 10
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Copied with minor code changes (should_xxx -> should.xxx) from RSpec.
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/test/spec'
|
4
|
+
require File.dirname(__FILE__) + "/stack"
|
5
|
+
|
6
|
+
context "A stack (in general)" do
|
7
|
+
setup do
|
8
|
+
@stack = Stack.new
|
9
|
+
["a","b","c"].each { |x| @stack.push x }
|
10
|
+
end
|
11
|
+
|
12
|
+
specify "should add to the top when sent 'push'" do
|
13
|
+
@stack.push "d"
|
14
|
+
@stack.peek.should.equal "d"
|
15
|
+
end
|
16
|
+
|
17
|
+
specify "should return the top item when sent 'peek'" do
|
18
|
+
@stack.peek.should.equal "c"
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should NOT remove the top item when sent 'peek'" do
|
22
|
+
@stack.peek.should.equal "c"
|
23
|
+
@stack.peek.should.equal "c"
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "should return the top item when sent 'pop'" do
|
27
|
+
@stack.pop.should.equal "c"
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "should remove the top item when sent 'pop'" do
|
31
|
+
@stack.pop.should.equal "c"
|
32
|
+
@stack.pop.should.equal "b"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "An empty stack" do
|
37
|
+
setup do
|
38
|
+
@stack = Stack.new
|
39
|
+
end
|
40
|
+
|
41
|
+
specify "should be empty" do
|
42
|
+
@stack.should.be.empty
|
43
|
+
end
|
44
|
+
|
45
|
+
specify "should no longer be empty after 'push'" do
|
46
|
+
@stack.push "anything"
|
47
|
+
@stack.should.not.be.empty
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "should complain when sent 'peek'" do
|
51
|
+
lambda { @stack.peek }.should.raise StackUnderflowError
|
52
|
+
end
|
53
|
+
|
54
|
+
specify "should complain when sent 'pop'" do
|
55
|
+
lambda { @stack.pop }.should.raise StackUnderflowError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "An almost empty stack (with one item)" do
|
60
|
+
setup do
|
61
|
+
@stack = Stack.new
|
62
|
+
@stack.push 3
|
63
|
+
end
|
64
|
+
|
65
|
+
specify "should not be empty" do
|
66
|
+
@stack.should.not.be.empty
|
67
|
+
end
|
68
|
+
|
69
|
+
specify "should remain not empty after 'peek'" do
|
70
|
+
@stack.peek
|
71
|
+
@stack.should.not.be.empty
|
72
|
+
end
|
73
|
+
|
74
|
+
specify "should become empty after 'pop'" do
|
75
|
+
@stack.pop
|
76
|
+
@stack.should.be.empty
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "An almost full stack (with one item less than capacity)" do
|
81
|
+
setup do
|
82
|
+
@stack = Stack.new
|
83
|
+
(1..9).each { |i| @stack.push i }
|
84
|
+
end
|
85
|
+
|
86
|
+
specify "should not be full" do
|
87
|
+
@stack.should.not.be.full
|
88
|
+
end
|
89
|
+
|
90
|
+
specify "should become full when sent 'push'" do
|
91
|
+
@stack.push Object.new
|
92
|
+
@stack.should.be.full
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "A full stack" do
|
97
|
+
setup do
|
98
|
+
@stack = Stack.new
|
99
|
+
(1..10).each { |i| @stack.push i }
|
100
|
+
end
|
101
|
+
|
102
|
+
specify "should be full" do
|
103
|
+
@stack.should.be.full
|
104
|
+
end
|
105
|
+
|
106
|
+
specify "should remain full after 'peek'" do
|
107
|
+
@stack.peek
|
108
|
+
@stack.should.be.full
|
109
|
+
end
|
110
|
+
|
111
|
+
specify "should no longer be full after 'pop'" do
|
112
|
+
@stack.pop
|
113
|
+
@stack.should.not.be.full
|
114
|
+
end
|
115
|
+
|
116
|
+
specify "should complain on 'push'" do
|
117
|
+
lambda { @stack.push Object.new }.should.raise StackOverflowError
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,366 @@
|
|
1
|
+
#
|
2
|
+
# test/spec -- a BDD interface for Test::Unit
|
3
|
+
#
|
4
|
+
# Copyright (C) 2006 Christian Neukirchen <mailto:chneukirchen@gmail.com>
|
5
|
+
#
|
6
|
+
# This work is licensed under the same terms as Ruby itself.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
|
11
|
+
class Test::Unit::AutoRunner # :nodoc:
|
12
|
+
RUNNERS[:specdox] = lambda {
|
13
|
+
require 'test/spec/dox'
|
14
|
+
Test::Unit::UI::SpecDox::TestRunner
|
15
|
+
}
|
16
|
+
|
17
|
+
RUNNERS[:rdox] = lambda {
|
18
|
+
require 'test/spec/rdox'
|
19
|
+
Test::Unit::UI::RDox::TestRunner
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
module Test # :nodoc:
|
24
|
+
end
|
25
|
+
|
26
|
+
module Test::Spec
|
27
|
+
VERSION = "0.1"
|
28
|
+
|
29
|
+
CONTEXTS = {}
|
30
|
+
|
31
|
+
class DefinitionError < StandardError
|
32
|
+
end
|
33
|
+
|
34
|
+
class Should
|
35
|
+
include Test::Unit::Assertions
|
36
|
+
|
37
|
+
def initialize(object)
|
38
|
+
@object = object
|
39
|
+
end
|
40
|
+
|
41
|
+
$TEST_SPEC_TESTCASE = nil
|
42
|
+
def add_assertion
|
43
|
+
$TEST_SPEC_TESTCASE && $TEST_SPEC_TESTCASE.__send__(:add_assertion)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def an
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def a
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def not
|
56
|
+
ShouldNot.new(@object)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def satisfy(&block)
|
61
|
+
assert_block("satisfy block failed.") {
|
62
|
+
yield @object
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def equal(value)
|
67
|
+
assert_equal value, @object
|
68
|
+
end
|
69
|
+
alias == equal
|
70
|
+
|
71
|
+
def close(value, delta)
|
72
|
+
assert_in_delta value, @object, delta
|
73
|
+
end
|
74
|
+
alias be_close close
|
75
|
+
|
76
|
+
def be(*value)
|
77
|
+
case value.size
|
78
|
+
when 0
|
79
|
+
self
|
80
|
+
when 1
|
81
|
+
assert_same value.first, @object
|
82
|
+
else
|
83
|
+
raise ArgumentError, "should.be needs zero or one argument"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def match(value)
|
88
|
+
assert_match value, @object
|
89
|
+
end
|
90
|
+
alias =~ match
|
91
|
+
|
92
|
+
def instance_of(klass)
|
93
|
+
assert_instance_of klass, @object
|
94
|
+
end
|
95
|
+
alias be_an_instance_of instance_of
|
96
|
+
|
97
|
+
def kind_of(klass)
|
98
|
+
assert_kind_of klass, @object
|
99
|
+
end
|
100
|
+
alias be_a_kind_of kind_of
|
101
|
+
|
102
|
+
def respond_to(method)
|
103
|
+
assert_respond_to @object, method
|
104
|
+
end
|
105
|
+
|
106
|
+
def _raise(*args)
|
107
|
+
args = [RuntimeError] if args.empty?
|
108
|
+
assert_raise(*args, &@object)
|
109
|
+
end
|
110
|
+
|
111
|
+
def throw(*args)
|
112
|
+
assert_throws(*args, &@object)
|
113
|
+
end
|
114
|
+
|
115
|
+
def nil
|
116
|
+
assert_nil @object
|
117
|
+
end
|
118
|
+
alias be_nil nil
|
119
|
+
|
120
|
+
|
121
|
+
def include(value)
|
122
|
+
msg = build_message(nil, "<?> expected to include ?, but it didn't.",
|
123
|
+
@object, value)
|
124
|
+
assert_block(msg) { @object.include?(value) }
|
125
|
+
end
|
126
|
+
|
127
|
+
def >(value)
|
128
|
+
assert_operator @object, :>, value
|
129
|
+
end
|
130
|
+
|
131
|
+
def >=(value)
|
132
|
+
assert_operator @object, :>=, value
|
133
|
+
end
|
134
|
+
|
135
|
+
def <(value)
|
136
|
+
assert_operator @object, :<, value
|
137
|
+
end
|
138
|
+
|
139
|
+
def <=(value)
|
140
|
+
assert_operator @object, :<=, value
|
141
|
+
end
|
142
|
+
|
143
|
+
def ===(value)
|
144
|
+
assert_operator @object, :===, value
|
145
|
+
end
|
146
|
+
|
147
|
+
def method_missing(name, *args)
|
148
|
+
# This will make raise call Kernel.raise, and self.raise call _raise.
|
149
|
+
return _raise(*args) if name == :raise
|
150
|
+
|
151
|
+
if @object.respond_to?("#{name}?")
|
152
|
+
assert @object.__send__("#{name}?", *args),
|
153
|
+
"#{name}? expected to be true."
|
154
|
+
else
|
155
|
+
super
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class ShouldNot
|
161
|
+
include Test::Unit::Assertions
|
162
|
+
|
163
|
+
def initialize(object)
|
164
|
+
@object = object
|
165
|
+
end
|
166
|
+
|
167
|
+
def equal(value)
|
168
|
+
assert_not_equal value, @object
|
169
|
+
end
|
170
|
+
alias == equal
|
171
|
+
|
172
|
+
def be(*value)
|
173
|
+
case value.size
|
174
|
+
when 0
|
175
|
+
self
|
176
|
+
when 1
|
177
|
+
assert_not_same value.first, @object
|
178
|
+
else
|
179
|
+
Kernel.raise ArgumentError, "should.be needs zero or one argument"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def match(value)
|
184
|
+
# Icky Regexp check
|
185
|
+
assert_no_match value, @object
|
186
|
+
end
|
187
|
+
alias =~ match
|
188
|
+
|
189
|
+
def _raise(*args)
|
190
|
+
assert_nothing_raised(*args, &@object)
|
191
|
+
end
|
192
|
+
|
193
|
+
def throw
|
194
|
+
assert_nothing_thrown(&@object)
|
195
|
+
end
|
196
|
+
|
197
|
+
def nil
|
198
|
+
assert_not_nil @object
|
199
|
+
end
|
200
|
+
alias be_nil nil
|
201
|
+
|
202
|
+
|
203
|
+
def not
|
204
|
+
Should.new(@object)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def method_missing(name, *args)
|
209
|
+
# This will make raise call Kernel.raise, and self.raise call _raise.
|
210
|
+
return _raise(*args) if name == :raise
|
211
|
+
|
212
|
+
if @object.respond_to?("#{name}?")
|
213
|
+
assert_block("#{name}? expected to be false.") {
|
214
|
+
not @object.__send__("#{name}?", *args)
|
215
|
+
}
|
216
|
+
else
|
217
|
+
super
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
class Test::Spec::TestCase
|
225
|
+
attr_reader :testcase
|
226
|
+
attr_reader :name
|
227
|
+
attr_reader :position
|
228
|
+
|
229
|
+
module InstanceMethods
|
230
|
+
def setup # :nodoc:
|
231
|
+
$TEST_SPEC_TESTCASE = self
|
232
|
+
super
|
233
|
+
self.class.setups.each { |s| instance_eval(&s) }
|
234
|
+
end
|
235
|
+
|
236
|
+
def teardown # :nodoc:
|
237
|
+
super
|
238
|
+
self.class.teardowns.each { |t| instance_eval(&t) }
|
239
|
+
end
|
240
|
+
|
241
|
+
def initialize(name)
|
242
|
+
super name
|
243
|
+
|
244
|
+
# Don't let the default_test clutter up the results and don't
|
245
|
+
# flunk if no tests given, either.
|
246
|
+
throw :invalid_test if name == :default_test
|
247
|
+
end
|
248
|
+
|
249
|
+
def position
|
250
|
+
self.class.position
|
251
|
+
end
|
252
|
+
|
253
|
+
def context(*args)
|
254
|
+
raise Test::Spec::DefinitionError,
|
255
|
+
"context definition is not allowed inside a specify-block"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
module ClassMethods
|
260
|
+
attr_accessor :count
|
261
|
+
attr_accessor :name
|
262
|
+
attr_accessor :position
|
263
|
+
attr_accessor :parent
|
264
|
+
|
265
|
+
attr_accessor :setups
|
266
|
+
attr_accessor :teardowns
|
267
|
+
|
268
|
+
def context(name, &block)
|
269
|
+
(Test::Spec::CONTEXTS[self.name + "\t" + name] ||=
|
270
|
+
Test::Spec::TestCase.new(name, self)).add(&block)
|
271
|
+
end
|
272
|
+
|
273
|
+
def specify(specname, &block)
|
274
|
+
raise ArgumentError, "specify needs a block" if block.nil?
|
275
|
+
|
276
|
+
self.count += 1 # Let them run in order of definition
|
277
|
+
|
278
|
+
define_method("test_spec {%s} %03d [%s]" % [name, count, specname], &block)
|
279
|
+
end
|
280
|
+
|
281
|
+
def setup(&block)
|
282
|
+
setups << block
|
283
|
+
end
|
284
|
+
|
285
|
+
def teardown(&block)
|
286
|
+
teardowns << block
|
287
|
+
end
|
288
|
+
|
289
|
+
def init(name, position, parent)
|
290
|
+
self.position = position
|
291
|
+
self.parent = parent
|
292
|
+
|
293
|
+
if parent
|
294
|
+
self.name = parent.name + "\t" + name
|
295
|
+
else
|
296
|
+
self.name = name
|
297
|
+
end
|
298
|
+
|
299
|
+
self.count = 0
|
300
|
+
self.setups = []
|
301
|
+
self.teardowns = []
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
@@POSITION = 0
|
306
|
+
|
307
|
+
def initialize(name, parent=nil)
|
308
|
+
@testcase = Class.new(Test::Unit::TestCase) {
|
309
|
+
include InstanceMethods
|
310
|
+
extend ClassMethods
|
311
|
+
}
|
312
|
+
|
313
|
+
@@POSITION = @@POSITION + 1
|
314
|
+
@testcase.init(name, @@POSITION, parent)
|
315
|
+
end
|
316
|
+
|
317
|
+
def add(&block)
|
318
|
+
raise ArgumentError, "context needs a block" if block.nil?
|
319
|
+
|
320
|
+
@testcase.class_eval(&block)
|
321
|
+
self
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
# Monkey-patch test/unit to run tests in an optionally specified order.
|
327
|
+
module Test::Unit # :nodoc:
|
328
|
+
class TestSuite # :nodoc:
|
329
|
+
undef run
|
330
|
+
def run(result, &progress_block)
|
331
|
+
sort!
|
332
|
+
yield(STARTED, name)
|
333
|
+
@tests.each do |test|
|
334
|
+
test.run(result, &progress_block)
|
335
|
+
end
|
336
|
+
yield(FINISHED, name)
|
337
|
+
end
|
338
|
+
|
339
|
+
def sort!
|
340
|
+
@tests = @tests.sort_by { |test|
|
341
|
+
test.respond_to?(:position) ? test.position : 0
|
342
|
+
}
|
343
|
+
end
|
344
|
+
|
345
|
+
def position
|
346
|
+
@tests.first.respond_to?(:position) ? @tests.first.position : 0
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
|
352
|
+
# Global helpers
|
353
|
+
|
354
|
+
class Object
|
355
|
+
def should
|
356
|
+
Test::Spec::Should.new(self)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
module Kernel
|
361
|
+
def context(name, &block)
|
362
|
+
(Test::Spec::CONTEXTS[name] ||= Test::Spec::TestCase.new(name)).add(&block)
|
363
|
+
end
|
364
|
+
|
365
|
+
private :context
|
366
|
+
end
|