assert 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/assert/context.rb +4 -3
- data/lib/assert/result.rb +5 -0
- data/lib/assert/suite.rb +3 -8
- data/lib/assert/version.rb +1 -1
- data/test/unit/context/test_should_singleton_tests.rb +63 -33
- data/test/unit/suite_tests.rb +7 -3
- metadata +4 -4
data/lib/assert/context.rb
CHANGED
@@ -122,16 +122,17 @@ module Assert
|
|
122
122
|
# create a test from the given code block
|
123
123
|
Assert.suite.tests << Test.new(test_name, ci, &block)
|
124
124
|
else
|
125
|
-
test_eventually(desc_or_macro, called_from, first_caller, &block)
|
125
|
+
test_eventually(desc_or_macro, called_from, first_caller || caller.first, &block)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_eventually(desc_or_macro, called_from=nil, first_caller=nil, &block)
|
130
130
|
ci = Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
|
131
131
|
test_name = desc_or_macro.kind_of?(Macro) ? desc_or_macro.name : desc_or_macro
|
132
|
+
skip_block = block.nil? ? Proc.new { skip 'TODO' } : Proc.new { skip }
|
132
133
|
|
133
134
|
# create a test from a proc that just skips
|
134
|
-
Assert.suite.tests << Test.new(test_name, ci, &
|
135
|
+
Assert.suite.tests << Test.new(test_name, ci, &skip_block)
|
135
136
|
end
|
136
137
|
alias_method :test_skip, :test_eventually
|
137
138
|
|
@@ -146,7 +147,7 @@ module Assert
|
|
146
147
|
if !desc_or_macro.kind_of?(Macro)
|
147
148
|
desc_or_macro = "should #{desc_or_macro}"
|
148
149
|
end
|
149
|
-
test_eventually(desc_or_macro, called_from, first_caller || caller.first)
|
150
|
+
test_eventually(desc_or_macro, called_from, first_caller || caller.first, &block)
|
150
151
|
end
|
151
152
|
alias_method :should_skip, :should_eventually
|
152
153
|
|
data/lib/assert/result.rb
CHANGED
data/lib/assert/suite.rb
CHANGED
@@ -4,18 +4,13 @@ module Assert
|
|
4
4
|
class Suite
|
5
5
|
|
6
6
|
class ContextInfo
|
7
|
-
|
8
|
-
attr_reader :called_from, :first_caller, :klass, :file
|
7
|
+
attr_reader :called_from, :klass, :file
|
9
8
|
|
10
9
|
def initialize(klass, called_from=nil, first_caller=nil)
|
11
|
-
@
|
12
|
-
@called_from = called_from
|
10
|
+
@called_from = called_from || first_caller
|
13
11
|
@klass = klass
|
14
|
-
@file =
|
15
|
-
(@called_from || @first_caller).gsub(/\:[0-9]+.*$/, '')
|
16
|
-
end
|
12
|
+
@file = @called_from.gsub(/\:[0-9]+.*$/, '') if @called_from
|
17
13
|
end
|
18
|
-
|
19
14
|
end
|
20
15
|
|
21
16
|
TEST_METHOD_REGEX = /^test./
|
data/lib/assert/version.rb
CHANGED
@@ -38,52 +38,70 @@ class Assert::Context
|
|
38
38
|
assert_equal @test_block, built_test.code
|
39
39
|
end
|
40
40
|
|
41
|
-
should "build a test that skips when `
|
42
|
-
d = @test_desc
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
should "build a test that skips with no msg when `test_eventually` called" do
|
42
|
+
d, b = @test_desc, @test_block
|
43
|
+
context = build_eval_context{ test_eventually(d, &b) }
|
44
|
+
err = capture_err(Assert::Result::TestSkipped) do
|
45
|
+
context.instance_eval(&Assert.suite.tests.last.code)
|
46
|
+
end
|
46
47
|
|
47
48
|
assert_equal @test_count_before+1, Assert.suite.tests.size
|
48
|
-
|
49
|
+
assert_equal "", err.message
|
50
|
+
end
|
51
|
+
|
52
|
+
should "build a test that skips with no msg when `should_eventually` called" do
|
53
|
+
d, b = @test_desc, @test_block
|
54
|
+
context = build_eval_context{ should_eventually(d, &b) }
|
55
|
+
err = capture_err(Assert::Result::TestSkipped) do
|
49
56
|
context.instance_eval(&Assert.suite.tests.last.code)
|
50
57
|
end
|
58
|
+
|
59
|
+
assert_equal @test_count_before+1, Assert.suite.tests.size
|
60
|
+
assert_equal "", err.message
|
51
61
|
end
|
52
62
|
|
53
|
-
should "
|
63
|
+
should "skip with the msg \"TODO\" when `test` called with no block" do
|
54
64
|
d = @test_desc
|
55
|
-
|
56
|
-
|
57
|
-
context = context_class.new(Factory.test("whatever", context_info))
|
58
|
-
|
59
|
-
assert_equal @test_count_before+1, Assert.suite.tests.size
|
60
|
-
assert_raises(Assert::Result::TestSkipped) do
|
65
|
+
context = build_eval_context { test(d) } # no block passed
|
66
|
+
err = capture_err(Assert::Result::TestSkipped) do
|
61
67
|
context.instance_eval(&Assert.suite.tests.last.code)
|
62
68
|
end
|
63
|
-
end
|
64
|
-
|
65
|
-
should "build a test that skips when `test_eventually` called" do
|
66
|
-
d, b = @test_desc, @test_block
|
67
|
-
context_class = Factory.context_class { test_eventually(d, &b) }
|
68
|
-
context_info = Factory.context_info(context_class)
|
69
|
-
context = context_class.new(Factory.test("whatever", context_info))
|
70
69
|
|
71
70
|
assert_equal @test_count_before+1, Assert.suite.tests.size
|
72
|
-
|
71
|
+
assert_equal "TODO", err.message
|
72
|
+
end
|
73
|
+
|
74
|
+
should "skip with the msg \"TODO\" when `should` called with no block" do
|
75
|
+
d = @test_desc
|
76
|
+
context = build_eval_context { should(d) } # no block passed
|
77
|
+
err = capture_err(Assert::Result::TestSkipped) do
|
73
78
|
context.instance_eval(&Assert.suite.tests.last.code)
|
74
79
|
end
|
80
|
+
|
81
|
+
assert_equal @test_count_before+1, Assert.suite.tests.size
|
82
|
+
assert_equal "TODO", err.message
|
75
83
|
end
|
76
84
|
|
77
|
-
should "
|
78
|
-
d
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
should "skip with the msg \"TODO\" when `test_eventually` called with no block" do
|
86
|
+
d = @test_desc
|
87
|
+
context = build_eval_context{ test_eventually(d) } # no block given
|
88
|
+
err = capture_err(Assert::Result::TestSkipped) do
|
89
|
+
context.instance_eval(&Assert.suite.tests.last.code)
|
90
|
+
end
|
82
91
|
|
83
92
|
assert_equal @test_count_before+1, Assert.suite.tests.size
|
84
|
-
|
93
|
+
assert_equal "TODO", err.message
|
94
|
+
end
|
95
|
+
|
96
|
+
should "skip with the msg \"TODO\" when `should_eventually` called with no block" do
|
97
|
+
d = @test_desc
|
98
|
+
context = build_eval_context{ should_eventually(d) } # no block given
|
99
|
+
err = capture_err(Assert::Result::TestSkipped) do
|
85
100
|
context.instance_eval(&Assert.suite.tests.last.code)
|
86
101
|
end
|
102
|
+
|
103
|
+
assert_equal @test_count_before+1, Assert.suite.tests.size
|
104
|
+
assert_equal "TODO", err.message
|
87
105
|
end
|
88
106
|
|
89
107
|
should "build a test from a macro using `test`" do
|
@@ -105,9 +123,7 @@ class Assert::Context
|
|
105
123
|
should "build a test that skips from a macro using `test_eventually`" do
|
106
124
|
d, b = @test_desc, @test_block
|
107
125
|
m = Assert::Macro.new{ test(d, &b); test(d, &b) }
|
108
|
-
|
109
|
-
context_info = Factory.context_info(context_class)
|
110
|
-
context = context_class.new(Factory.test("whatever", context_info))
|
126
|
+
context = build_eval_context{ test_eventually(m) }
|
111
127
|
|
112
128
|
assert_equal @test_count_before+1, Assert.suite.tests.size
|
113
129
|
assert_raises(Assert::Result::TestSkipped) do
|
@@ -118,9 +134,7 @@ class Assert::Context
|
|
118
134
|
should "build a test that skips from a macro using `should_eventually`" do
|
119
135
|
d, b = @test_desc, @test_block
|
120
136
|
m = Assert::Macro.new{ should(d, &b); should(d, &b) }
|
121
|
-
|
122
|
-
context_info = Factory.context_info(context_class)
|
123
|
-
context = context_class.new(Factory.test("whatever", context_info))
|
137
|
+
context = build_eval_context{ should_eventually(m) }
|
124
138
|
|
125
139
|
assert_equal @test_count_before+1, Assert.suite.tests.size
|
126
140
|
assert_raises(Assert::Result::TestSkipped) do
|
@@ -129,6 +143,22 @@ class Assert::Context
|
|
129
143
|
|
130
144
|
end
|
131
145
|
|
146
|
+
private
|
147
|
+
|
148
|
+
def build_eval_context(&build_block)
|
149
|
+
context_class = Factory.context_class &build_block
|
150
|
+
context_info = Factory.context_info(context_class)
|
151
|
+
context_class.new(Factory.test("whatever", context_info))
|
152
|
+
end
|
153
|
+
|
154
|
+
def capture_err(err_class, &block)
|
155
|
+
begin
|
156
|
+
block.call
|
157
|
+
rescue err_class => e
|
158
|
+
e
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
132
162
|
end
|
133
163
|
|
134
164
|
end
|
data/test/unit/suite_tests.rb
CHANGED
@@ -181,14 +181,18 @@ class Assert::Suite
|
|
181
181
|
end
|
182
182
|
subject{ @info }
|
183
183
|
|
184
|
-
should have_readers :called_from, :
|
184
|
+
should have_readers :called_from, :klass, :file
|
185
185
|
|
186
186
|
should "set its klass on init" do
|
187
187
|
assert_equal @klass, subject.klass
|
188
188
|
end
|
189
189
|
|
190
|
-
should "set its called_from to the first caller on init" do
|
191
|
-
|
190
|
+
should "set its called_from to the called_from or first caller on init" do
|
191
|
+
info = Assert::Suite::ContextInfo.new(@klass, @caller.first, nil)
|
192
|
+
assert_equal @caller.first, info.called_from
|
193
|
+
|
194
|
+
info = Assert::Suite::ContextInfo.new(@klass, nil, @caller.first)
|
195
|
+
assert_equal @caller.first, info.called_from
|
192
196
|
end
|
193
197
|
|
194
198
|
should "set its file from caller info on init" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 2.1.
|
9
|
+
- 1
|
10
|
+
version: 2.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-04-
|
19
|
+
date: 2013-04-30 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: ansi
|