assert 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/README.rdoc +6 -6
- data/Rakefile +2 -3
- data/assert.gemspec +1 -0
- data/lib/assert/assertions.rb +30 -30
- data/lib/assert/context.rb +71 -66
- data/lib/assert/macro.rb +14 -0
- data/lib/assert/macros/methods.rb +52 -0
- data/lib/assert/rake_tasks.rb +31 -13
- data/lib/assert/result.rb +12 -4
- data/lib/assert/result_set.rb +2 -2
- data/lib/assert/runner.rb +2 -6
- data/lib/assert/setup/autorun.rb +0 -1
- data/lib/assert/suite.rb +19 -15
- data/lib/assert/test.rb +6 -17
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view/base.rb +1 -1
- data/lib/assert/view/terminal.rb +8 -30
- data/test/assertions/assert_block_test.rb +1 -1
- data/test/assertions/assert_empty_test.rb +43 -0
- data/test/assertions/assert_equal_test.rb +43 -0
- data/test/assertions/assert_includes_test.rb +44 -0
- data/test/assertions/assert_instance_of_test.rb +4 -4
- data/test/assertions/assert_kind_of_test.rb +3 -3
- data/test/assertions/assert_match_test.rb +43 -0
- data/test/assertions/assert_nil_test.rb +43 -0
- data/test/assertions/assert_not_block_test.rb +1 -1
- data/test/assertions/assert_not_empty_test.rb +43 -0
- data/test/assertions/assert_not_equal_test.rb +43 -0
- data/test/assertions/assert_not_included_test.rb +44 -0
- data/test/assertions/assert_not_instance_of_test.rb +4 -4
- data/test/assertions/assert_not_kind_of_test.rb +2 -2
- data/test/assertions/assert_not_match_test.rb +43 -0
- data/test/assertions/assert_not_nil_test.rb +43 -0
- data/test/assertions/assert_not_respond_to_test.rb +6 -6
- data/test/assertions/assert_not_same_test.rb +45 -0
- data/test/assertions/assert_respond_to_test.rb +6 -6
- data/test/assertions/assert_same_test.rb +45 -0
- data/test/assertions_test.rb +21 -298
- data/test/context/class_methods_test.rb +81 -112
- data/test/context_test.rb +35 -40
- data/test/helper.rb +5 -2
- data/test/irb.rb +2 -5
- data/test/macro_test.rb +99 -0
- data/test/options_test.rb +2 -2
- data/test/result_set_test.rb +47 -54
- data/test/result_test.rb +4 -17
- data/test/runner_test.rb +2 -10
- data/test/suite_test.rb +85 -13
- data/test/test/running_test.rb +19 -28
- data/test/test_test.rb +130 -128
- data/test/view_test.rb +3 -17
- metadata +50 -7
data/test/helper.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
|
+
# test/.. (root dir for gem)
|
7
|
+
$LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
|
8
|
+
|
6
9
|
# This is the suite intended to be used in the tests, this is seperate from Assert.suite which is
|
7
10
|
# the actual suite being used to run the tests, confused? Don't use Assert.suite in your tests,
|
8
11
|
# use TEST_ASSERT_SUITE
|
@@ -38,9 +41,9 @@ module Factory
|
|
38
41
|
def test(*args, &block)
|
39
42
|
name = (args[0] || "a test").to_s
|
40
43
|
context_class = args[1] || self.context_class
|
41
|
-
block
|
44
|
+
test_block = (block || args[2] || ::Proc.new{})
|
42
45
|
|
43
|
-
Assert::Test.new(name, context_class, &
|
46
|
+
Assert::Test.new(name, context_class, &test_block)
|
44
47
|
end
|
45
48
|
|
46
49
|
# Common interface for generating a new skip result
|
data/test/irb.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'assert'
|
2
2
|
|
3
3
|
# this file is required in when the 'irb' rake test is run.
|
4
|
-
# b/c '
|
5
|
-
# be added to the LOAD_PATH and the test helper will be
|
4
|
+
# b/c 'assert' is required above, the test helper will be
|
6
5
|
# required in.
|
7
6
|
|
8
7
|
# put any IRB setup code here
|
9
|
-
|
10
|
-
require 'assert'
|
data/test/macro_test.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'assert'
|
2
|
+
|
3
|
+
require 'assert/macro'
|
4
|
+
|
5
|
+
class Assert::Macro
|
6
|
+
|
7
|
+
class BaseTest < Assert::Context
|
8
|
+
desc "a macro"
|
9
|
+
subject { Assert::Macro.new {} }
|
10
|
+
|
11
|
+
should "be a Proc" do
|
12
|
+
assert_kind_of ::Proc, subject
|
13
|
+
end
|
14
|
+
|
15
|
+
should "complain if you create a macro without a block" do
|
16
|
+
assert_raises ArgumentError do
|
17
|
+
Assert::Macro.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class InstanceMethodsTest < Assert::Context
|
23
|
+
desc "a class with instance methods"
|
24
|
+
subject do
|
25
|
+
class ::InstExample
|
26
|
+
(1..6).each {|i| define_method("method_#{i}") {}}
|
27
|
+
end
|
28
|
+
::InstExample.new
|
29
|
+
end
|
30
|
+
|
31
|
+
should have_instance_method :method_1
|
32
|
+
should have_instance_method :method_2, :method_3
|
33
|
+
should have_instance_methods :method_4
|
34
|
+
should have_instance_methods :method_5, :method_6
|
35
|
+
end
|
36
|
+
|
37
|
+
class ClassMethodsTest < Assert::Context
|
38
|
+
desc "a class with class methods"
|
39
|
+
subject do
|
40
|
+
class ::ClassExample
|
41
|
+
class << self
|
42
|
+
(1..6).each {|i| define_method("method_#{i}") {}}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
::ClassExample.new
|
46
|
+
end
|
47
|
+
|
48
|
+
should have_class_method :method_1
|
49
|
+
should have_class_method :method_2, :method_3
|
50
|
+
should have_class_methods :method_4
|
51
|
+
should have_class_methods :method_5, :method_6
|
52
|
+
end
|
53
|
+
|
54
|
+
class ReadersTest < Assert::Context
|
55
|
+
desc "a class with readers"
|
56
|
+
subject do
|
57
|
+
class ::ReaderExample
|
58
|
+
(1..6).each {|i| attr_reader "method_#{i}"}
|
59
|
+
end
|
60
|
+
::ReaderExample.new
|
61
|
+
end
|
62
|
+
|
63
|
+
should have_reader :method_1
|
64
|
+
should have_reader :method_2, :method_3
|
65
|
+
should have_readers :method_4
|
66
|
+
should have_readers :method_5, :method_6
|
67
|
+
end
|
68
|
+
|
69
|
+
class WritersTest < Assert::Context
|
70
|
+
desc "a class with writers"
|
71
|
+
subject do
|
72
|
+
class ::WriterExample
|
73
|
+
(1..6).each {|i| attr_writer "method_#{i}"}
|
74
|
+
end
|
75
|
+
::WriterExample.new
|
76
|
+
end
|
77
|
+
|
78
|
+
should have_writer :method_1
|
79
|
+
should have_writer :method_2, :method_3
|
80
|
+
should have_writers :method_4
|
81
|
+
should have_writers :method_5, :method_6
|
82
|
+
end
|
83
|
+
|
84
|
+
class AccessorsTest < Assert::Context
|
85
|
+
desc "a class with accessors"
|
86
|
+
subject do
|
87
|
+
class ::AccessorExample
|
88
|
+
(1..6).each {|i| attr_accessor "method_#{i}"}
|
89
|
+
end
|
90
|
+
::AccessorExample.new
|
91
|
+
end
|
92
|
+
|
93
|
+
should have_accessor :method_1
|
94
|
+
should have_accessor :method_2, :method_3
|
95
|
+
should have_accessors :method_4
|
96
|
+
should have_accessors :method_5, :method_6
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/test/options_test.rb
CHANGED
@@ -37,8 +37,8 @@ module Assert::Options
|
|
37
37
|
end
|
38
38
|
|
39
39
|
should "be provided for the terminal view" do
|
40
|
-
assert_respond_to Assert::View::Terminal
|
41
|
-
assert_respond_to Assert::View::Terminal.new("suite", "io")
|
40
|
+
assert_respond_to :options, Assert::View::Terminal
|
41
|
+
assert_respond_to :options, Assert::View::Terminal.new("suite", "io")
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
data/test/result_set_test.rb
CHANGED
@@ -12,13 +12,14 @@ class FakeView < Assert::View::Base
|
|
12
12
|
self.printed = []
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def handle_runtime_result(result)
|
16
16
|
self.printed.push(result)
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class Assert::ResultSet
|
22
|
+
|
22
23
|
class BasicTest < Assert::Context
|
23
24
|
desc "Assert result set"
|
24
25
|
setup do
|
@@ -26,64 +27,56 @@ class Assert::ResultSet
|
|
26
27
|
end
|
27
28
|
subject { @result_set }
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
]
|
32
|
-
INSTANCE_METHODS.each do |method|
|
33
|
-
should "respond to the instance method ##{method}" do
|
34
|
-
assert_respond_to subject, method
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
30
|
+
should have_accessor :view
|
31
|
+
end
|
39
32
|
|
40
|
-
class ViewTest < BasicTest
|
41
|
-
desc "view"
|
42
|
-
setup do
|
43
|
-
@view_s = ""
|
44
|
-
@view = @result_set.view = FakeView.new(nil, StringIO.new(@view_s, "w+"))
|
45
33
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@result_set << @skip_result
|
52
|
-
@error_result = Assert::Result::Error.new("test", RuntimeError.new)
|
53
|
-
@result_set << @error_result
|
54
|
-
end
|
55
|
-
subject{ @view }
|
34
|
+
class ViewTest < BasicTest
|
35
|
+
desc "view"
|
36
|
+
setup do
|
37
|
+
@view_s = ""
|
38
|
+
@view = @result_set.view = FakeView.new(nil, StringIO.new(@view_s, "w+"))
|
56
39
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
assert_kind_of Assert::Result::Fail, fail_results.first
|
68
|
-
assert_equal @fail_result.test_name, fail_results.first.test_name
|
69
|
-
assert_equal @fail_result.message, fail_results.first.message
|
70
|
-
end
|
71
|
-
should "have 'printed' 1 skip result" do
|
72
|
-
skip_results = @view.printed.reject{|r| !r.skip? }
|
73
|
-
assert_equal 1, skip_results.size
|
74
|
-
assert_kind_of Assert::Result::Skip, skip_results.first
|
75
|
-
assert_equal @skip_result.test_name, skip_results.first.test_name
|
76
|
-
assert_equal @skip_result.message, skip_results.first.message
|
77
|
-
end
|
78
|
-
should "have 'printed' 1 error result" do
|
79
|
-
error_results = @view.printed.reject{|r| !r.error? }
|
80
|
-
assert_equal 1, error_results.size
|
81
|
-
assert_kind_of Assert::Result::Error, error_results.first
|
82
|
-
assert_equal @error_result.test_name, error_results.first.test_name
|
83
|
-
assert_equal @error_result.message, error_results.first.message
|
84
|
-
end
|
40
|
+
@pass_result = Assert::Result::Pass.new("test", "pass", [])
|
41
|
+
@result_set << @pass_result
|
42
|
+
@fail_result = Assert::Result::Fail.new("test", "fail", [])
|
43
|
+
@result_set << @fail_result
|
44
|
+
@skip_result = Assert::Result::Skip.new("test", RuntimeError.new)
|
45
|
+
@result_set << @skip_result
|
46
|
+
@error_result = Assert::Result::Error.new("test", RuntimeError.new)
|
47
|
+
@result_set << @error_result
|
48
|
+
end
|
49
|
+
subject{ @view }
|
85
50
|
|
51
|
+
should "have 'printed' 1 pass result" do
|
52
|
+
pass_results = @view.printed.reject{|r| !r.pass? }
|
53
|
+
assert_equal 1, pass_results.size
|
54
|
+
assert_kind_of Assert::Result::Pass, pass_results.first
|
55
|
+
assert_equal @pass_result.test_name, pass_results.first.test_name
|
56
|
+
assert_equal @pass_result.message, pass_results.first.message
|
57
|
+
end
|
58
|
+
should "have 'printed' 1 fail result" do
|
59
|
+
fail_results = @view.printed.reject{|r| !r.fail? }
|
60
|
+
assert_equal 1, fail_results.size
|
61
|
+
assert_kind_of Assert::Result::Fail, fail_results.first
|
62
|
+
assert_equal @fail_result.test_name, fail_results.first.test_name
|
63
|
+
assert_equal @fail_result.message, fail_results.first.message
|
64
|
+
end
|
65
|
+
should "have 'printed' 1 skip result" do
|
66
|
+
skip_results = @view.printed.reject{|r| !r.skip? }
|
67
|
+
assert_equal 1, skip_results.size
|
68
|
+
assert_kind_of Assert::Result::Skip, skip_results.first
|
69
|
+
assert_equal @skip_result.test_name, skip_results.first.test_name
|
70
|
+
assert_equal @skip_result.message, skip_results.first.message
|
71
|
+
end
|
72
|
+
should "have 'printed' 1 error result" do
|
73
|
+
error_results = @view.printed.reject{|r| !r.error? }
|
74
|
+
assert_equal 1, error_results.size
|
75
|
+
assert_kind_of Assert::Result::Error, error_results.first
|
76
|
+
assert_equal @error_result.test_name, error_results.first.test_name
|
77
|
+
assert_equal @error_result.message, error_results.first.message
|
86
78
|
end
|
87
79
|
|
88
80
|
end
|
81
|
+
|
89
82
|
end
|
data/test/result_test.rb
CHANGED
@@ -9,14 +9,7 @@ module Assert::Result
|
|
9
9
|
setup{ @backtrace = Backtrace.new(caller) }
|
10
10
|
subject { @backtrace }
|
11
11
|
|
12
|
-
|
13
|
-
:to_s, :filtered
|
14
|
-
]
|
15
|
-
INSTANCE_METHODS.each do |method|
|
16
|
-
should "respond to the instance method ##{method}" do
|
17
|
-
assert_respond_to subject, method
|
18
|
-
end
|
19
|
-
end
|
12
|
+
should have_instance_methods :to_s, :filtered
|
20
13
|
|
21
14
|
should "be an Array" do
|
22
15
|
assert_kind_of ::Array, subject
|
@@ -42,18 +35,12 @@ module Assert::Result
|
|
42
35
|
end
|
43
36
|
subject{ @result }
|
44
37
|
|
45
|
-
|
46
|
-
|
47
|
-
]
|
48
|
-
INSTANCE_METHODS.each do |method|
|
49
|
-
should "respond to the instance method ##{method}" do
|
50
|
-
assert_respond_to subject, method
|
51
|
-
end
|
52
|
-
end
|
38
|
+
should have_readers :test_name, :message, :backtrace
|
39
|
+
should have_instance_methods :to_sym, :to_s, :trace
|
53
40
|
|
54
41
|
Assert::Result.types.keys.each do |type|
|
55
42
|
should "respond to the instance method ##{type}?" do
|
56
|
-
assert_respond_to
|
43
|
+
assert_respond_to "#{type}?", subject
|
57
44
|
end
|
58
45
|
|
59
46
|
should "not be #{type}" do
|
data/test/runner_test.rb
CHANGED
@@ -11,18 +11,10 @@ class Assert::Runner
|
|
11
11
|
setup do
|
12
12
|
@suite = Assert::Suite.new
|
13
13
|
@view = Assert::View::Base.new(@suite, StringIO.new("", "w+"))
|
14
|
-
@runner = Assert::Runner.new(@suite, @view)
|
15
14
|
end
|
16
|
-
subject { @
|
15
|
+
subject { Assert::Runner.new(@suite, @view) }
|
17
16
|
|
18
|
-
|
19
|
-
:run, :count
|
20
|
-
]
|
21
|
-
INSTANCE_METHODS.each do |method|
|
22
|
-
should "respond to the instance method ##{method}" do
|
23
|
-
assert_respond_to subject, method
|
24
|
-
end
|
25
|
-
end
|
17
|
+
should have_instance_methods :run, :count
|
26
18
|
|
27
19
|
should "return an integer exit code" do
|
28
20
|
assert_equal 0, subject.run
|
data/test/suite_test.rb
CHANGED
@@ -16,18 +16,11 @@ class Assert::Suite
|
|
16
16
|
end
|
17
17
|
subject { @suite }
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
:run_time
|
25
|
-
]
|
26
|
-
INSTANCE_METHODS.each do |method|
|
27
|
-
should "respond to the instance method ##{method}" do
|
28
|
-
assert_respond_to subject, method
|
29
|
-
end
|
30
|
-
end
|
19
|
+
should have_accessors :start_time, :end_time
|
20
|
+
should have_instance_method :<<
|
21
|
+
should have_instance_methods :contexts, :tests, :ordered_tests, :ordered_results
|
22
|
+
should have_instance_methods :count, :test_count, :result_count
|
23
|
+
should have_instance_method :run_time
|
31
24
|
|
32
25
|
should "be a hash" do
|
33
26
|
assert_kind_of ::Hash, subject
|
@@ -43,7 +36,7 @@ class Assert::Suite
|
|
43
36
|
should "determine a klass' local public test methods" do
|
44
37
|
assert_equal(
|
45
38
|
["test_subclass_stuff", "test_mixin_stuff"].sort,
|
46
|
-
subject.send(:local_public_test_methods, SubStuff).sort
|
39
|
+
subject.send(:local_public_test_methods, SubStuff).sort.collect(&:to_s)
|
47
40
|
)
|
48
41
|
end
|
49
42
|
|
@@ -197,4 +190,83 @@ class Assert::Suite
|
|
197
190
|
|
198
191
|
end
|
199
192
|
|
193
|
+
|
194
|
+
|
195
|
+
class SetupTest < Assert::Context
|
196
|
+
desc "a suite with a setup"
|
197
|
+
setup do
|
198
|
+
@setup_status = nil
|
199
|
+
@suite = Assert::Suite.new
|
200
|
+
@setup_blocks = []
|
201
|
+
@setup_blocks << ::Proc.new{ @setup_status = "setup" }
|
202
|
+
@setup_blocks << ::Proc.new{ @setup_status += " has been run" }
|
203
|
+
@setup_blocks.each do |setup_block|
|
204
|
+
@suite.setup(&setup_block)
|
205
|
+
end
|
206
|
+
@expected = "setup has been run"
|
207
|
+
end
|
208
|
+
subject{ @setup_status }
|
209
|
+
|
210
|
+
should "set the setup status to the correct message" do
|
211
|
+
@suite.setup
|
212
|
+
assert_equal @expected, subject
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
class SetupsTest < SetupTest
|
220
|
+
desc "when calling the setups method"
|
221
|
+
setup do
|
222
|
+
@setups = @suite.send(:setups)
|
223
|
+
end
|
224
|
+
subject{ @setups }
|
225
|
+
|
226
|
+
should "include the setup we defined on the suite" do
|
227
|
+
@setup_blocks.each do |setup_block|
|
228
|
+
assert_includes setup_block, subject
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
class TeardownTest < Assert::Context
|
236
|
+
desc "a suite with a teardown"
|
237
|
+
setup do
|
238
|
+
@teardown_status = nil
|
239
|
+
@suite = Assert::Suite.new
|
240
|
+
@teardown_blocks = []
|
241
|
+
@teardown_blocks << ::Proc.new{ @teardown_status += " has been run" }
|
242
|
+
@teardown_blocks << ::Proc.new{ @teardown_status = "teardown" }
|
243
|
+
@teardown_blocks.each do |teardown_block|
|
244
|
+
@suite.teardown(&teardown_block)
|
245
|
+
end
|
246
|
+
@expected = "teardown has been run"
|
247
|
+
end
|
248
|
+
|
249
|
+
should "set the teardown status to the correct message" do
|
250
|
+
@suite.teardown
|
251
|
+
assert_equal "teardown has been run", @teardown_status
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
class TeardownsTest < TeardownTest
|
259
|
+
desc "when calling the teardowns method"
|
260
|
+
setup do
|
261
|
+
@teardowns = @suite.send(:teardowns)
|
262
|
+
end
|
263
|
+
subject{ @teardowns }
|
264
|
+
|
265
|
+
should "include the teardown we defined on the suite" do
|
266
|
+
@teardown_blocks.each do |teardown_block|
|
267
|
+
assert_includes teardown_block, subject
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
200
272
|
end
|