assert 2.0.0.rc.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/Gemfile +1 -1
  2. data/{LICENSE → LICENSE.txt} +0 -0
  3. data/Rakefile +1 -3
  4. data/assert.gemspec +15 -15
  5. data/lib/assert.rb +1 -2
  6. data/lib/assert/assert_runner.rb +2 -1
  7. data/lib/assert/assertions.rb +153 -189
  8. data/lib/assert/version.rb +1 -1
  9. data/test/helper.rb +74 -51
  10. data/test/{fixtures → support}/inherited_stuff.rb +0 -0
  11. data/test/{test → system}/running_tests.rb +16 -43
  12. data/test/{assert_test.rb → unit/assert_tests.rb} +0 -0
  13. data/test/unit/assertions/assert_block_tests.rb +57 -0
  14. data/test/unit/assertions/assert_empty_tests.rb +58 -0
  15. data/test/unit/assertions/assert_equal_tests.rb +59 -0
  16. data/test/unit/assertions/assert_file_exists_tests.rb +59 -0
  17. data/test/unit/assertions/assert_includes_tests.rb +61 -0
  18. data/test/unit/assertions/assert_instance_of_tests.rb +61 -0
  19. data/test/unit/assertions/assert_kind_of_tests.rb +60 -0
  20. data/test/unit/assertions/assert_match_tests.rb +59 -0
  21. data/test/unit/assertions/assert_nil_tests.rb +59 -0
  22. data/test/unit/assertions/assert_raises_tests.rb +73 -0
  23. data/test/unit/assertions/assert_respond_to_tests.rb +63 -0
  24. data/test/unit/assertions/assert_same_tests.rb +65 -0
  25. data/test/unit/assertions_tests.rb +65 -0
  26. data/test/unit/context/basic_singleton_tests.rb +86 -0
  27. data/test/unit/context/setup_teardown_singleton_tests.rb +105 -0
  28. data/test/unit/context/test_should_singleton_tests.rb +134 -0
  29. data/test/{context_test.rb → unit/context_tests.rb} +53 -131
  30. data/test/{macro_test.rb → unit/macro_tests.rb} +15 -11
  31. data/test/{result_test.rb → unit/result_tests.rb} +27 -26
  32. data/test/{runner_test.rb → unit/runner_tests.rb} +1 -2
  33. data/test/{suite_test.rb → unit/suite_tests.rb} +63 -95
  34. data/test/{test_test.rb → unit/test_tests.rb} +45 -77
  35. data/test/{view/base_tests.rb → unit/view_tests.rb} +0 -1
  36. metadata +63 -104
  37. data/CHANGELOG.md +0 -33
  38. data/test/assertions/assert_block_test.rb +0 -39
  39. data/test/assertions/assert_empty_test.rb +0 -43
  40. data/test/assertions/assert_equal_test.rb +0 -43
  41. data/test/assertions/assert_file_exists_test.rb +0 -43
  42. data/test/assertions/assert_includes_test.rb +0 -44
  43. data/test/assertions/assert_instance_of_test.rb +0 -43
  44. data/test/assertions/assert_kind_of_test.rb +0 -43
  45. data/test/assertions/assert_match_test.rb +0 -43
  46. data/test/assertions/assert_nil_test.rb +0 -43
  47. data/test/assertions/assert_not_block_test.rb +0 -39
  48. data/test/assertions/assert_not_empty_test.rb +0 -43
  49. data/test/assertions/assert_not_equal_test.rb +0 -43
  50. data/test/assertions/assert_not_file_exists_test.rb +0 -43
  51. data/test/assertions/assert_not_included_test.rb +0 -44
  52. data/test/assertions/assert_not_instance_of_test.rb +0 -43
  53. data/test/assertions/assert_not_kind_of_test.rb +0 -43
  54. data/test/assertions/assert_not_match_test.rb +0 -43
  55. data/test/assertions/assert_not_nil_test.rb +0 -43
  56. data/test/assertions/assert_not_respond_to_test.rb +0 -43
  57. data/test/assertions/assert_not_same_test.rb +0 -45
  58. data/test/assertions/assert_nothing_raised_test.rb +0 -46
  59. data/test/assertions/assert_raises_test.rb +0 -49
  60. data/test/assertions/assert_respond_to_test.rb +0 -43
  61. data/test/assertions/assert_same_test.rb +0 -45
  62. data/test/assertions_test.rb +0 -60
  63. data/test/context/class_methods_test.rb +0 -531
  64. data/test/fixtures/sample_context.rb +0 -13
  65. data/test/fixtures/test_root/one_test.rb +0 -0
  66. data/test/fixtures/test_root/parent/area_one/area_test.rb +0 -0
  67. data/test/fixtures/test_root/shallow/deeply/nested_test.rb +0 -0
  68. data/test/fixtures/test_root/shallow/nested_test.rb +0 -0
  69. data/test/fixtures/test_root/shallow_test.rb +0 -0
  70. data/test/fixtures/test_root/two_test.rb +0 -0
  71. data/test/suite/context_info_test.rb +0 -42
@@ -1,43 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertNotMatchTest < Assert::Context
4
- desc "the assert_not_match helper run in a test"
5
- setup do
6
- fail_desc = @fail_desc = "assert not match fail desc"
7
- fail_args = @fail_args = [ /a/, "a string", fail_desc ]
8
- @test = Factory.test do
9
- assert_not_match(*fail_args) # fail
10
- assert_not_match("not", "a string") # pass
11
- end
12
- @test.run
13
- end
14
- subject{ @test }
15
-
16
- should "have 2 total results" do
17
- assert_equal 2, subject.result_count
18
- end
19
- should "have 1 pass result" do
20
- assert_equal 1, subject.result_count(:pass)
21
- end
22
- should "have 1 fail result" do
23
- assert_equal 1, subject.result_count(:fail)
24
- end
25
-
26
- class FailMessageTest < AssertNotMatchTest
27
- desc "with a failed result"
28
- setup do
29
- @expected = [
30
- @fail_args[2],
31
- "#{@fail_args[1].inspect} not expected to match #{@fail_args[0].inspect}.",
32
- ].join("\n")
33
- @fail_message = @test.fail_results.first.message
34
- end
35
- subject{ @fail_message }
36
-
37
- should "have a fail message with an explanation of what failed and my fail description" do
38
- assert_equal @expected, subject
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,43 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertNotNilTest < Assert::Context
4
- desc "the assert_not_nil helper run in a test"
5
- setup do
6
- fail_desc = @fail_desc = "assert not nil empty fail desc"
7
- fail_args = @fail_args = [ nil, fail_desc ]
8
- @test = Factory.test do
9
- assert_not_nil(1) # pass
10
- assert_not_nil(*fail_args) # fail
11
- end
12
- @test.run
13
- end
14
- subject{ @test }
15
-
16
- should "have 2 total results" do
17
- assert_equal 2, subject.result_count
18
- end
19
- should "have 1 pass result" do
20
- assert_equal 1, subject.result_count(:pass)
21
- end
22
- should "have 1 fail result" do
23
- assert_equal 1, subject.result_count(:fail)
24
- end
25
-
26
- class FailMessageTest < AssertNotNilTest
27
- desc "with a failed result"
28
- setup do
29
- @expected = [
30
- @fail_args[1],
31
- "Expected #{@fail_args[0].inspect} to not be nil.",
32
- ].join("\n")
33
- @fail_message = @test.fail_results.first.message
34
- end
35
- subject{ @fail_message }
36
-
37
- should "have a fail message with an explanation of what failed and my fail description" do
38
- assert_equal @expected, subject
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,43 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertNotRespondToTest < Assert::Context
4
- desc "the assert_not_respond_to helper run in a test"
5
- setup do
6
- fail_desc = @fail_desc = "assert not respond to fail desc"
7
- fail_args = @fail_args = [ :abs, 1, fail_desc ]
8
- @test = Factory.test do
9
- assert_not_respond_to(*fail_args) # fail
10
- assert_not_respond_to(:abs, "1") # pass
11
- end
12
- @test.run
13
- end
14
- subject{ @test }
15
-
16
- should "have 2 total results" do
17
- assert_equal 2, subject.result_count
18
- end
19
- should "have 1 pass result" do
20
- assert_equal 1, subject.result_count(:pass)
21
- end
22
- should "have 1 fail result" do
23
- assert_equal 1, subject.result_count(:fail)
24
- end
25
-
26
- class FailMessageTest < AssertNotRespondToTest
27
- desc "with a failed result"
28
- setup do
29
- @expected = [
30
- @fail_args[2],
31
- "#{@fail_args[1].inspect} (#{@fail_args[1].class}) not expected to respond to ##{@fail_args[0]}."
32
- ].join("\n")
33
- @fail_message = @test.fail_results.first.message
34
- end
35
- subject{ @fail_message }
36
-
37
- should "have a fail message with an explanation of what failed and my fail description" do
38
- assert_equal @expected, subject
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,45 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertNotSameTest < Assert::Context
4
- desc "the assert_not_same helper run in a test"
5
- setup do
6
- klass = Class.new
7
- object = klass.new
8
- fail_desc = @fail_desc = "assert not same fail desc"
9
- fail_args = @fail_args = [ object, object, fail_desc ]
10
- @test = Factory.test do
11
- assert_not_same(*fail_args) # fail
12
- assert_not_same(object, klass.new) # pass
13
- end
14
- @test.run
15
- end
16
- subject{ @test }
17
-
18
- should "have 2 total results" do
19
- assert_equal 2, subject.result_count
20
- end
21
- should "have 1 pass result" do
22
- assert_equal 1, subject.result_count(:pass)
23
- end
24
- should "have 1 fail result" do
25
- assert_equal 1, subject.result_count(:fail)
26
- end
27
-
28
- class FailMessageTest < AssertNotSameTest
29
- desc "with a failed result"
30
- setup do
31
- @expected = [
32
- @fail_args[2],
33
- "#{@fail_args[0].inspect} (#{@fail_args[0].object_id}) not expected to be the same as #{@fail_args[1].inspect} (#{@fail_args[1].object_id}).",
34
- ].join("\n")
35
- @fail_message = @test.fail_results.first.message
36
- end
37
- subject{ @fail_message }
38
-
39
- should "have a fail message with an explanation of what failed and my fail description" do
40
- assert_equal @expected, subject
41
- end
42
-
43
- end
44
-
45
- end
@@ -1,46 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertNothingRaisedTest < Assert::Context
4
- desc "the assert_nothing_raised helper run in a test"
5
- setup do
6
- fail_desc = @fail_desc = "assert nothing raised fail desc"
7
- @test = Factory.test do
8
- assert_nothing_raised(StandardError, RuntimeError, fail_desc){ raise(StandardError) } # fail
9
- assert_nothing_raised(RuntimeError){ raise(StandardError) } # pass
10
- assert_nothing_raised(fail_desc){ raise(RuntimeError) } # fail
11
- assert_nothing_raised{ true } # pass
12
- end
13
- @test.run
14
- end
15
- subject{ @test }
16
-
17
- should "have 4 total results" do
18
- assert_equal 4, subject.result_count
19
- end
20
- should "have 2 pass result" do
21
- assert_equal 2, subject.result_count(:pass)
22
- end
23
- should "have 2 fail result" do
24
- assert_equal 2, subject.result_count(:fail)
25
- end
26
-
27
- class FailMessageTest < AssertNothingRaisedTest
28
- desc "with a failed result"
29
- setup do
30
- @expected = [
31
- "#{@fail_desc}\nStandardError or RuntimeError exception was not expected, but was raised:",
32
- "#{@fail_desc}\nAn exception was not expected, but was raised:"
33
- ]
34
- @fail_messages = @test.fail_results.collect(&:message)
35
- end
36
- subject{ @fail_messages }
37
-
38
- should "have a fail message with an explanation of what failed and my fail description" do
39
- subject.each_with_index do |message, n|
40
- assert_match /^#{@expected[n]}/, message
41
- end
42
- end
43
-
44
- end
45
-
46
- end
@@ -1,49 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertRaisesTest < Assert::Context
4
- desc "the assert_raises helper run in a test"
5
- setup do
6
- fail_desc = @fail_desc = "assert raises fail desc"
7
- @test = Factory.test do
8
- assert_raises(StandardError, RuntimeError){ raise(StandardError) } # pass
9
- assert_raises(StandardError, RuntimeError, fail_desc){ raise(Exception) } # fail
10
- assert_raises(RuntimeError, fail_desc){ raise(StandardError) } # fail
11
- assert_raises(RuntimeError, fail_desc){ true } # fail
12
- assert_raises(fail_desc){ true } # fail
13
- end
14
- @test.run
15
- end
16
- subject{ @test }
17
-
18
- should "have 3 total results" do
19
- assert_equal 5, subject.result_count
20
- end
21
- should "have 1 pass result" do
22
- assert_equal 1, subject.result_count(:pass)
23
- end
24
- should "have 4 fail results" do
25
- assert_equal 4, subject.result_count(:fail)
26
- end
27
-
28
- class FailMessageTest < AssertRaisesTest
29
- desc "with a failed result"
30
- setup do
31
- @expected = [
32
- "#{@fail_desc}\nStandardError or RuntimeError exception expected, not:",
33
- "#{@fail_desc}\nRuntimeError exception expected, not:",
34
- "#{@fail_desc}\nRuntimeError exception expected but nothing was raised.",
35
- "#{@fail_desc}\nAn exception expected but nothing was raised."
36
- ]
37
- @fail_messages = @test.fail_results.collect(&:message)
38
- end
39
- subject{ @fail_messages }
40
-
41
- should "have a fail message with an explanation of what failed and my fail description" do
42
- subject.each_with_index do |message, n|
43
- assert_match /^#{@expected[n]}/, message
44
- end
45
- end
46
-
47
- end
48
-
49
- end
@@ -1,43 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertRespondToTest < Assert::Context
4
- desc "the assert_respond_to helper run in a test"
5
- setup do
6
- fail_desc = @fail_desc = "assert respond to fail desc"
7
- fail_args = @fail_args = [ :abs, "1", fail_desc ]
8
- @test = Factory.test do
9
- assert_respond_to(:abs, 1) # pass
10
- assert_respond_to(*fail_args) # fail
11
- end
12
- @test.run
13
- end
14
- subject{ @test }
15
-
16
- should "have 2 total results" do
17
- assert_equal 2, subject.result_count
18
- end
19
- should "have 1 pass result" do
20
- assert_equal 1, subject.result_count(:pass)
21
- end
22
- should "have 1 fail result" do
23
- assert_equal 1, subject.result_count(:fail)
24
- end
25
-
26
- class FailMessageTest < AssertRespondToTest
27
- desc "with a failed result"
28
- setup do
29
- @expected = [
30
- @fail_args[2],
31
- "Expected #{@fail_args[1].inspect} (#{@fail_args[1].class}) to respond to ##{@fail_args[0]}."
32
- ].join("\n")
33
- @fail_message = @test.fail_results.first.message
34
- end
35
- subject{ @fail_message }
36
-
37
- should "have a fail message with an explanation of what failed and my fail description" do
38
- assert_equal @expected, subject
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,45 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Assertions::AssertSameTest < Assert::Context
4
- desc "the assert_same helper run in a test"
5
- setup do
6
- klass = Class.new
7
- object = klass.new
8
- fail_desc = @fail_desc = "assert same fail desc"
9
- fail_args = @fail_args = [ object, klass.new, fail_desc ]
10
- @test = Factory.test do
11
- assert_same(object, object) # pass
12
- assert_same(*fail_args) # fail
13
- end
14
- @test.run
15
- end
16
- subject{ @test }
17
-
18
- should "have 2 total results" do
19
- assert_equal 2, subject.result_count
20
- end
21
- should "have 1 pass result" do
22
- assert_equal 1, subject.result_count(:pass)
23
- end
24
- should "have 1 fail result" do
25
- assert_equal 1, subject.result_count(:fail)
26
- end
27
-
28
- class FailMessageTest < AssertSameTest
29
- desc "with a failed result"
30
- setup do
31
- @expected = [
32
- @fail_args[2],
33
- "Expected #{@fail_args[0].inspect} (#{@fail_args[0].object_id}) to be the same as #{@fail_args[1].inspect} (#{@fail_args[1].object_id}).",
34
- ].join("\n")
35
- @fail_message = @test.fail_results.first.message
36
- end
37
- subject{ @fail_message }
38
-
39
- should "have a fail message with an explanation of what failed and my fail description" do
40
- assert_equal @expected, subject
41
- end
42
-
43
- end
44
-
45
- end
@@ -1,60 +0,0 @@
1
- require 'assert'
2
-
3
- module Assert::Assertions
4
- class BasicTest < Assert::Context
5
-
6
- desc "An assert context"
7
- setup do
8
- @context_class = Factory.context_class
9
- @context = @context_class.new
10
- end
11
- subject{ @context }
12
-
13
- should have_instance_methods :assert_block, :assert_not_block, :refute_block
14
- should have_instance_methods :assert_raises, :assert_raise, :assert_nothing_raised, :assert_not_raises, :assert_not_raise
15
- should have_instance_methods :assert_kind_of, :assert_not_kind_of, :refute_kind_of
16
- should have_instance_methods :assert_instance_of, :assert_not_instance_of, :refute_instance_of
17
- should have_instance_methods :assert_respond_to, :assert_responds_to
18
- should have_instance_methods :assert_not_respond_to, :assert_not_responds_to
19
- should have_instance_methods :refute_respond_to, :refute_responds_to
20
- should have_instance_methods :assert_same, :assert_not_same, :refute_same
21
- should have_instance_methods :assert_equal, :assert_not_equal, :refute_equal
22
- should have_instance_methods :assert_match, :assert_not_match, :assert_no_match, :refute_match
23
- should have_instance_methods :assert_empty, :assert_not_empty, :refute_empty
24
- should have_instance_methods :assert_includes, :assert_included
25
- should have_instance_methods :assert_not_includes, :assert_not_included, :refute_includes, :refute_included
26
- should have_instance_methods :assert_nil, :assert_not_nil, :refute_nil
27
- should have_instance_methods :assert_file_exists, :assert_not_file_exists, :refute_file_exists
28
- end
29
-
30
- class IgnoredTest < BasicTest
31
- desc "ignored assertions helpers"
32
- setup do
33
- @tests = Assert::Assertions::IGNORED_ASSERTION_HELPERS.collect do |helper|
34
- Factory.test("ignored assertion helper #{helper}", Factory.context_info(@context_class)) do
35
- self.send(helper, "doesn't matter")
36
- end
37
- end
38
- @expected_messages = Assert::Assertions::IGNORED_ASSERTION_HELPERS.collect do |helper|
39
- [ "The assertion helper '#{helper}' is not supported. Please use ",
40
- "another helper or the basic assert."
41
- ].join
42
- end
43
- @results = @tests.collect(&:run).flatten
44
- end
45
- subject{ @results }
46
-
47
- should "have an ignored result for each helper in the constant" do
48
- subject.each do |result|
49
- assert_kind_of Assert::Result::Ignore, result
50
- end
51
- assert_equal(Assert::Assertions::IGNORED_ASSERTION_HELPERS.size, subject.size)
52
- end
53
-
54
- should "have a custom ignore message for each helper in the constant" do
55
- assert_equal(@expected_messages, subject.collect(&:message))
56
- end
57
-
58
- end
59
-
60
- end
@@ -1,531 +0,0 @@
1
- require 'assert'
2
-
3
- class Assert::Context
4
-
5
- class ClassMethodsTest < Assert::Context
6
- desc "Assert context class"
7
- setup do
8
- @orig_assert_suite = Assert.suite
9
- Assert.config.suite TEST_ASSERT_SUITE
10
- @test = Factory.test
11
- @context_class = @test.context_class
12
- end
13
- teardown do
14
- TEST_ASSERT_SUITE.tests.clear
15
- Assert.config.suite @orig_assert_suite
16
- end
17
- subject{ @context_class }
18
-
19
- should have_instance_methods :setup_once, :before_once, :startup
20
- should have_instance_methods :teardown_once, :after_once, :shutdown
21
- should have_instance_methods :setup, :before, :setups
22
- should have_instance_methods :teardown, :after, :teardowns
23
- should have_instance_methods :description, :desc, :describe, :subject
24
- should have_instance_methods :test, :test_eventually, :test_skip
25
- should have_instance_methods :should, :should_eventually, :should_skip
26
- end
27
-
28
-
29
-
30
- class SetupOnceTest < ClassMethodsTest
31
- desc "setup_once method"
32
- setup do
33
- setup_block = @setup_block = ::Proc.new{ something_once = true }
34
- @context_class = Factory.context_class do
35
- setup_once(&setup_block)
36
- end
37
- @setup_blocks = Assert.suite.send(:setups)
38
- end
39
- teardown do
40
- Assert.suite.send(:setups).reject!{|b| b == @setup_block }
41
- end
42
- subject{ @setup_blocks }
43
-
44
- should "add the block to the suite's collection of setup blocks" do
45
- assert_includes @setup_block, subject
46
- end
47
-
48
- end
49
-
50
-
51
-
52
- class TeardownOnceTest < ClassMethodsTest
53
- desc "teardown_once method"
54
- setup do
55
- teardown_block = @teardown_block = ::Proc.new{ something_once = true }
56
- @context_class = Factory.context_class do
57
- teardown_once(&teardown_block)
58
- end
59
- @teardown_blocks = Assert.suite.send(:teardowns)
60
- end
61
- teardown do
62
- Assert.suite.send(:teardowns).reject!{|b| b == @teardown_block }
63
- end
64
- subject{ @teardown_blocks }
65
-
66
- should "add the block to the suite's collection of teardown blocks" do
67
- assert_includes @teardown_block, subject
68
- end
69
-
70
- end
71
-
72
-
73
-
74
- class SetupTest < ClassMethodsTest
75
- desc "setup method"
76
- setup do
77
- setup_block = @setup_block = ::Proc.new{ @something = true }
78
- @context_class = Factory.context_class do
79
- setup(&setup_block)
80
- end
81
- @setup_blocks = @context_class.send(:setups)
82
- end
83
- subject{ @setup_blocks }
84
-
85
- should "add the block to the context's collection of setup blocks" do
86
- assert_includes @setup_block, subject
87
- end
88
-
89
- end
90
-
91
-
92
-
93
- class SetupWithMethodNameTest < ClassMethodsTest
94
- desc "setup with method name"
95
- setup do
96
- method_name = @method_name = :setup_something_amazing
97
- @context_class = Factory.context_class do
98
- setup(method_name)
99
- end
100
- @setups = @context_class.send(:setups)
101
- end
102
- subject{ @setups }
103
-
104
- should "add the method name to the context setups" do
105
- assert_includes @method_name, subject
106
- end
107
- end
108
-
109
-
110
- class MultipleSetupsTest < ClassMethodsTest
111
- desc "a context class with multiple setups"
112
- setup do
113
- method_name = :setup_something_amazing
114
- klass = Class.new do
115
- attr_accessor :status
116
-
117
- define_method(method_name) do
118
- self.status += " with something amazing"
119
- end
120
- end
121
- @object = klass.new
122
- setup_block = @setup_block = ::Proc.new{ self.status = "the setup" }
123
- @parent_class = Factory.context_class do
124
- setup(&setup_block)
125
- end
126
- setup_block = @setup_block = ::Proc.new{ self.status += " has been run" }
127
- @context_class = Factory.context_class(@parent_class) do
128
- setup(&setup_block)
129
- setup(method_name)
130
- end
131
- @context_class.setup(@object)
132
- @expected = "the setup has been run with something amazing"
133
- end
134
- subject{ @object }
135
-
136
- should "run it's parent and it's own setup blocks in the correct order" do
137
- assert_equal @expected, subject.status
138
- end
139
-
140
- end
141
-
142
-
143
-
144
- class TeardownTest < ClassMethodsTest
145
- desc "teardown method"
146
- setup do
147
- teardown_block = @teardown_block = ::Proc.new{ @something = false }
148
- @context_class = Factory.context_class do
149
- teardown(&teardown_block)
150
- end
151
- @teardown_blocks = @context_class.send(:teardowns)
152
- end
153
- subject{ @teardown_blocks }
154
-
155
- should "add the block to the context's collection of teardown blocks" do
156
- assert_includes @teardown_block, subject
157
- end
158
-
159
- end
160
-
161
-
162
-
163
- class TeardownWithMethodNameTest < ClassMethodsTest
164
- desc "teardown with method name"
165
- setup do
166
- method_name = @method_name = "teardown_something_amazing"
167
- @context_class = Factory.context_class do
168
- teardown(method_name)
169
- end
170
- @teardowns = @context_class.send(:teardowns)
171
- end
172
- subject{ @teardowns }
173
-
174
- should "add the method name to the context teardowns" do
175
- assert_includes @method_name, subject
176
- end
177
- end
178
-
179
-
180
-
181
- class MultipleTeardownsTest < ClassMethodsTest
182
- desc "a context class with multiple teardowns"
183
- setup do
184
- method_name = :teardown_something_amazing
185
- klass = Class.new do
186
- attr_accessor :status
187
-
188
- define_method(method_name) do
189
- self.status += " with something amazing"
190
- end
191
- end
192
- @object = klass.new
193
- teardown_block = @teardown_block = ::Proc.new{ self.status += " has been run" }
194
- @parent_class = Factory.context_class do
195
- teardown(&teardown_block)
196
- teardown(method_name)
197
- end
198
- teardown_block = @teardown_block = ::Proc.new{ self.status = "the teardown" }
199
- @context_class = Factory.context_class(@parent_class) do
200
- teardown(&teardown_block)
201
- end
202
- @context_class.teardown(@object)
203
- @expected = "the teardown has been run with something amazing"
204
- end
205
- subject{ @object }
206
-
207
- should "run it's parent and it's own teardown blocks in the correct order" do
208
- assert_equal @expected, subject.status
209
- end
210
-
211
- end
212
-
213
-
214
-
215
- class DescTest < ClassMethodsTest
216
- desc "desc method with an arg"
217
- setup do
218
- descs = @descs = [ "something amazing", "it really is" ]
219
- @context_class = Factory.context_class do
220
- descs.each do |text|
221
- desc text
222
- end
223
- end
224
- end
225
- subject{ @context_class.send(:descriptions) }
226
-
227
- should "return a collection containing any descriptions defined on the class" do
228
- assert_kind_of Array, subject
229
- @descs.each do |text|
230
- assert_includes text, subject
231
- end
232
- end
233
-
234
- end
235
-
236
-
237
-
238
- class FullDescriptionTest < ClassMethodsTest
239
- desc "description method without an arg"
240
- setup do
241
- parent_text = @parent_desc = "parent description"
242
- @parent_class = Factory.context_class do
243
- desc parent_text
244
- end
245
- text = @desc = "and the description for this context"
246
- @context_class = Factory.context_class(@parent_class) do
247
- desc text
248
- end
249
- @full_description = @context_class.description
250
- end
251
- subject{ @full_description }
252
-
253
- should "return a string of all the inherited descriptions" do
254
- assert_kind_of String, subject
255
- assert_match @parent_desc, subject
256
- assert_match @desc, subject
257
- end
258
-
259
- end
260
-
261
-
262
-
263
- class SubjectFromLocalTest < ClassMethodsTest
264
- desc "subject method using local context"
265
- setup do
266
- subject_block = @subject_block = ::Proc.new{ @something }
267
- @context_class = Factory.context_class do
268
- subject(&subject_block)
269
- end
270
- end
271
- subject{ @subject_block }
272
-
273
- should "set the subject block on the context class" do
274
- assert_equal @context_class.subject, subject
275
- end
276
-
277
- end
278
-
279
-
280
-
281
- class SubjectFromParentTest < ClassMethodsTest
282
- desc "subject method using parent context"
283
- setup do
284
- parent_block = @parent_block = ::Proc.new{ @something }
285
- @parent_class = Factory.context_class do
286
- subject(&parent_block)
287
- end
288
- @context_class = Factory.context_class(@parent_class)
289
- end
290
- subject{ @parent_block }
291
-
292
- should "default to it's parents subject block" do
293
- assert_equal subject, @context_class.subject
294
- end
295
- end
296
-
297
-
298
-
299
- class TestMethTest < ClassMethodsTest
300
- desc "test method"
301
- setup do
302
- @test_count_before = Assert.suite.tests.size
303
-
304
- @test_desc = "be true"
305
- @test_block = ::Proc.new{ assert(true) }
306
- @test_name = @test_desc
307
-
308
- d, b = @test_desc, @test_block
309
- @context_class = Factory.context_class { test(d, &b) }
310
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
311
- end
312
- subject{ @context }
313
-
314
- should "build a test with a given desc and code block" do
315
- assert_equal @test_count_before+1, Assert.suite.tests.size
316
- built_test = Assert.suite.tests.last
317
-
318
- assert_kind_of Assert::Test, built_test
319
- assert_equal @test_name, built_test.name
320
-
321
- assert_equal @test_block, built_test.code
322
- end
323
-
324
- end
325
-
326
- class TestMacroTest < TestMethTest
327
- desc "on a macro"
328
- setup do
329
- @test_count_before = Assert.suite.tests.size
330
- d, b = @test_desc, @test_block
331
- m = Assert::Macro.new do
332
- test(d, &b)
333
- test(d, &b)
334
- end
335
- @context_class = Factory.context_class { test(m) }
336
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
337
- end
338
- subject{ @context }
339
-
340
- should "build tests from the macro" do
341
- assert_equal @test_count_before+2, Assert.suite.tests.size
342
- built_test = Assert.suite.tests.last
343
-
344
- assert_kind_of Assert::Test, built_test
345
- assert_equal @test_name, built_test.name
346
-
347
- assert_equal @test_block, built_test.code
348
- end
349
-
350
- end
351
-
352
- class NoBlockTestMethTest < TestMethTest
353
- desc "called with no block"
354
- setup do
355
- @test_count_before = Assert.suite.tests.size
356
- d = @test_desc
357
- @context_class = Factory.context_class { test(d) }
358
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
359
- end
360
- subject{ @context }
361
-
362
- should "build a test that skips" do
363
- assert_equal @test_count_before+1, Assert.suite.tests.size
364
- assert_raises(Assert::Result::TestSkipped) do
365
- subject.instance_eval(&Assert.suite.tests.last.code)
366
- end
367
- end
368
-
369
- end
370
-
371
- class TestEventuallyTest < TestMethTest
372
- desc "called with '_eventually'"
373
- setup do
374
- @test_count_before = Assert.suite.tests.size
375
- d, b = @test_desc, @test_block
376
- @context_class = Factory.context_class do
377
- test_eventually(d, &b)
378
- end
379
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
380
- end
381
- subject{ @context }
382
-
383
- should "build a test that skips" do
384
- assert_equal @test_count_before+1, Assert.suite.tests.size
385
- assert_raises(Assert::Result::TestSkipped) do
386
- subject.instance_eval(&Assert.suite.tests.last.code)
387
- end
388
- end
389
-
390
- end
391
-
392
- class TestEventuallyMacroTest < TestEventuallyTest
393
- desc "on a macro"
394
- setup do
395
- @test_count_before = Assert.suite.tests.size
396
- d, b = @test_desc, @test_block
397
- m = Assert::Macro.new do
398
- test(d, &b)
399
- test(d, &b)
400
- end
401
- @context_class = Factory.context_class { test_eventually(m) }
402
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
403
- end
404
- subject{ @context }
405
-
406
- should "build a test that skips" do
407
- assert_equal @test_count_before+1, Assert.suite.tests.size
408
- assert_raises(Assert::Result::TestSkipped) do
409
- subject.instance_eval(&Assert.suite.tests.last.code)
410
- end
411
- end
412
-
413
- end
414
-
415
-
416
-
417
- class ShouldTest < ClassMethodsTest
418
- desc "'should' method"
419
- setup do
420
- @test_count_before = Assert.suite.tests.size
421
-
422
- @should_desc = "be true"
423
- @should_block = ::Proc.new{ assert(true) }
424
- @test_name = "should #{@should_desc}"
425
-
426
- d, b = @should_desc, @should_block
427
- @context_class = Factory.context_class { should(d, &b) }
428
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
429
- end
430
- subject{ @context }
431
-
432
- should "build a test with a given should desc and code block" do
433
- assert_equal @test_count_before+1, Assert.suite.tests.size
434
- built_test = Assert.suite.tests.last
435
-
436
- assert_kind_of Assert::Test, built_test
437
- assert_equal @test_name, built_test.name
438
-
439
- assert_equal @should_block, built_test.code
440
- end
441
-
442
- end
443
-
444
- class ShouldMacroTest < ShouldTest
445
- desc "on a macro"
446
- setup do
447
- @test_count_before = Assert.suite.tests.size
448
- d, b = @should_desc, @should_block
449
- m = Assert::Macro.new do
450
- should(d, &b)
451
- should(d, &b)
452
- end
453
- @context_class = Factory.context_class { should m }
454
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
455
- end
456
- subject{ @context }
457
-
458
- should "build tests from the macro" do
459
- assert_equal @test_count_before+2, Assert.suite.tests.size
460
- built_test = Assert.suite.tests.last
461
-
462
- assert_kind_of Assert::Test, built_test
463
- assert_equal @test_name, built_test.name
464
-
465
- assert_equal @should_block, built_test.code
466
- end
467
-
468
- end
469
-
470
- class NoBlockShouldTest < ShouldTest
471
- desc "called with no block"
472
- setup do
473
- @test_count_before = Assert.suite.tests.size
474
- d = @should_desc
475
- @context_class = Factory.context_class { should(d) }
476
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
477
- end
478
- subject{ @context }
479
-
480
- should "build a test that skips" do
481
- assert_equal @test_count_before+1, Assert.suite.tests.size
482
- assert_raises(Assert::Result::TestSkipped) do
483
- subject.instance_eval(&Assert.suite.tests.last.code)
484
- end
485
- end
486
-
487
- end
488
-
489
- class ShouldEventuallyTest < ShouldTest
490
- desc "called with '_eventually'"
491
- setup do
492
- @test_count_before = Assert.suite.tests.size
493
- d, b = @should_desc, @should_block
494
- @context_class = Factory.context_class { should_eventually(d, &b) }
495
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
496
- end
497
- subject{ @context }
498
-
499
- should "build a test that skips" do
500
- assert_equal @test_count_before+1, Assert.suite.tests.size
501
- assert_raises(Assert::Result::TestSkipped) do
502
- subject.instance_eval(&Assert.suite.tests.last.code)
503
- end
504
- end
505
-
506
- end
507
-
508
- class ShouldEventuallyMacroTest < ShouldEventuallyTest
509
- desc "on a macro"
510
- setup do
511
- @test_count_before = Assert.suite.tests.size
512
- d, b = @should_desc, @should_block
513
- m = Assert::Macro.new do
514
- should(d, &b)
515
- should(d, &b)
516
- end
517
- @context_class = Factory.context_class { should_eventually(m) }
518
- @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
519
- end
520
- subject{ @context }
521
-
522
- should "build a test that skips" do
523
- assert_equal @test_count_before+1, Assert.suite.tests.size
524
- assert_raises(Assert::Result::TestSkipped) do
525
- subject.instance_eval(&Assert.suite.tests.last.code)
526
- end
527
- end
528
-
529
- end
530
-
531
- end