assert 2.0.0.rc.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.0.0.rc.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,19 +1,51 @@
1
- # this file is automatically required in when you require 'assert'
2
- # put test helpers here
1
+ # this file is automatically required when you run `assert`
2
+ # put any test helpers here
3
3
 
4
- require 'stringio'
5
-
6
- # test/.. (root dir for gem)
4
+ # add the root dir to the load path
7
5
  $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
10
- # the actual suite being used to run the tests, confused? Don't use Assert.suite in your tests,
11
- # use TEST_ASSERT_SUITE
7
+ # Force tests to run without halting on failures (needed so all tests will run
8
+ # properly). For halt on fail behavior testing, the context of those tests
9
+ # configures Assert temporarily as needed.
10
+
11
+ class Assert::Context
12
+ def setup
13
+ Assert.config.halt_on_fail false
14
+ # Note: don't mess with the `show_output` setting in this setup block. Doing
15
+ # so will break the capture output tests. If you really need to set it one
16
+ # way or the other, do so in the `.assert.rb` local settings file.
17
+ end
18
+
19
+ # a context for use in testing all the different context singleton methods
20
+ class ContextSingletonTests < Assert::Context
21
+ desc "Assert context singleton"
22
+ setup do
23
+ @orig_assert_suite = Assert.suite
24
+ Assert.config.suite TEST_ASSERT_SUITE
25
+ @test = Factory.test
26
+ @context_class = @test.context_class
27
+ end
28
+ teardown do
29
+ TEST_ASSERT_SUITE.tests.clear
30
+ Assert.config.suite @orig_assert_suite
31
+ end
32
+ subject{ @context_class }
33
+
34
+ end
35
+
36
+ end
37
+
38
+
39
+ # A Suite for use in the tests. It is seperate from `Assert.suite`
40
+ # (which is the actual suite being used to run the tests). Don't use
41
+ # `Assert.suite` in your tests, use TEST_ASSERT_SUITE
42
+
12
43
  TEST_ASSERT_SUITE = Assert::Suite.new
13
44
 
14
- # This is the test context intended to be used in the tests, and is also used in the context_class
15
- # factory by default. This will ensure any contexts you define in your tests will not be shoved
16
- # onto the the suite running the tests.
45
+ # A context for use in the tests and also in the `context_class` factory. This
46
+ # will ensure any contexts defined as part of the tests will add their methods
47
+ # to `TEST_ASSERT_SUITE`
48
+
17
49
  class TestContext < Assert::Context
18
50
  def self.method_added(meth)
19
51
  if meth.to_s =~ Assert::Suite::TEST_METHOD_REGEX
@@ -23,54 +55,45 @@ class TestContext < Assert::Context
23
55
  end
24
56
  end
25
57
 
26
- # force tests to run without halting on fail (needed for tests to run)
27
- # anywhere we test halt on fail behavior, we take care of it in the specific context
28
- class Assert::Context
29
- def setup
30
- Assert.config.halt_on_fail false
31
- # Note: don't mess with `Assert.config.output` in this setup block - it will
32
- # break the capture output tests. If you really need to set it one way or
33
- # another, do it in the `.assert.rb` local settings file.
58
+ module Factory
59
+
60
+ def self.context_info_called_from
61
+ "/path/to_file.rb:1234"
34
62
  end
35
- end
36
63
 
37
- module Factory
38
- class << self
64
+ def self.context_info(context_class)
65
+ Assert::Suite::ContextInfo.new(context_class, context_info_called_from)
66
+ end
39
67
 
40
- def context_info_called_from
41
- "/path/to_file.rb:1234"
42
- end
68
+ # Generate an anonymous `Context` inherited from `TestContext` by default.
69
+ # This provides a common interface for all contexts used in testing.
43
70
 
44
- def context_info(context_class)
45
- Assert::Suite::ContextInfo.new(context_class, context_info_called_from)
46
- end
47
- # Generates an anonymous class inherited from whatever you pass or TextContext by default. This
48
- # provides a common interface for all context classes to be generated in the tests.
49
- def context_class(inherit_from = nil, &block)
50
- inherit_from ||= TestContext
51
- klass = Class.new(inherit_from, &block)
52
- default = (const_name = "FactoryAssertContext").dup
53
- while(Object.const_defined?(const_name)) do
54
- const_name = "FactoryAssertContext#{rand(Time.now.to_i)}"
55
- end
56
- Object.const_set(const_name, klass)
57
- klass
71
+ def self.context_class(inherit_from=nil, &block)
72
+ inherit_from ||= TestContext
73
+ klass = Class.new(inherit_from, &block)
74
+ default = (const_name = "FactoryAssertContext").dup
75
+
76
+ while(Object.const_defined?(const_name)) do
77
+ const_name = "FactoryAssertContext#{rand(Time.now.to_i)}"
58
78
  end
79
+ Object.const_set(const_name, klass)
80
+ klass
81
+ end
59
82
 
60
- # Common interface for generating a new test, takes args and a block, will default everything
61
- # if you need a no-op test.
62
- def test(*args, &block)
63
- name = (args[0] || "a test").to_s
64
- context_info = args[1] || self.context_info(self.context_class)
65
- test_block = (block || args[2] || ::Proc.new{})
83
+ # Generate a no-op test for use in testing.
66
84
 
67
- Assert::Test.new(name, context_info, &test_block)
68
- end
85
+ def self.test(*args, &block)
86
+ name = (args[0] || "a test").to_s
87
+ context_info = args[1] || self.context_info(self.context_class)
88
+ test_block = (block || args[2] || ::Proc.new{})
69
89
 
70
- # Common interface for generating a new skip result
71
- def skip_result(name, exception)
72
- Assert::Result::Skip.new(Factory.test(name), exception)
73
- end
90
+ Assert::Test.new(name, context_info, &test_block)
91
+ end
74
92
 
93
+ # Generate a skip result for use in testing.
94
+
95
+ def self.skip_result(name, exception)
96
+ Assert::Result::Skip.new(Factory.test(name), exception)
75
97
  end
98
+
76
99
  end
@@ -1,13 +1,10 @@
1
1
  require 'assert'
2
2
 
3
- class Assert::Test
3
+ class RunningTheTestsTests < Assert::Context
4
+ desc "Assert tests that are run"
5
+ subject{ @test }
4
6
 
5
- class RunningTests < Assert::Context
6
- desc "Assert tests that are run"
7
- subject{ @test }
8
- end
9
-
10
- class NothingTests < RunningTests
7
+ class NothingTests < RunningTheTestsTests
11
8
  desc "and does nothing"
12
9
  setup do
13
10
  @test = Factory.test
@@ -20,9 +17,7 @@ class Assert::Test
20
17
 
21
18
  end
22
19
 
23
-
24
-
25
- class PassTests < RunningTests
20
+ class PassTests < RunningTheTestsTests
26
21
  desc "and passes a single assertion"
27
22
  setup do
28
23
  @test = Factory.test{ assert(1 == 1) }
@@ -38,9 +33,7 @@ class Assert::Test
38
33
 
39
34
  end
40
35
 
41
-
42
-
43
- class FailTests < RunningTests
36
+ class FailTests < RunningTheTestsTests
44
37
  desc "and fails a single assertion"
45
38
  setup do
46
39
  @test = Factory.test{ assert(1 == 0) }
@@ -56,9 +49,7 @@ class Assert::Test
56
49
 
57
50
  end
58
51
 
59
-
60
-
61
- class SkipTests < RunningTests
52
+ class SkipTests < RunningTheTestsTests
62
53
  desc "and skips"
63
54
  setup do
64
55
  @test = Factory.test{ skip }
@@ -74,9 +65,7 @@ class Assert::Test
74
65
 
75
66
  end
76
67
 
77
-
78
-
79
- class ErrorTests < RunningTests
68
+ class ErrorTests < RunningTheTestsTests
80
69
  desc "and errors"
81
70
  setup do
82
71
  @test = Factory.test{ raise("WHAT") }
@@ -92,9 +81,7 @@ class Assert::Test
92
81
 
93
82
  end
94
83
 
95
-
96
-
97
- class MixedTests < RunningTests
84
+ class MixedTests < RunningTheTestsTests
98
85
  desc "and has 1 pass and 1 fail assertion"
99
86
  setup do
100
87
  @test = Factory.test do
@@ -116,9 +103,7 @@ class Assert::Test
116
103
 
117
104
  end
118
105
 
119
-
120
-
121
- class MixedSkipTests < RunningTests
106
+ class MixedSkipTests < RunningTheTestsTests
122
107
  desc "and has 1 pass and 1 fail assertion with a skip call in between"
123
108
  setup do
124
109
  @test = Factory.test do
@@ -147,9 +132,7 @@ class Assert::Test
147
132
 
148
133
  end
149
134
 
150
-
151
-
152
- class MixedErrorTests < RunningTests
135
+ class MixedErrorTests < RunningTheTestsTests
153
136
  desc "and has 1 pass and 1 fail assertion with an exception raised in between"
154
137
  setup do
155
138
  @test = Factory.test do
@@ -178,9 +161,7 @@ class Assert::Test
178
161
 
179
162
  end
180
163
 
181
-
182
-
183
- class MixedPassTests < RunningTests
164
+ class MixedPassTests < RunningTheTestsTests
184
165
  desc "and has 1 pass and 1 fail assertion with a pass call in between"
185
166
  setup do
186
167
  @test = Factory.test do
@@ -206,9 +187,7 @@ class Assert::Test
206
187
 
207
188
  end
208
189
 
209
-
210
-
211
- class MixedFailTests < RunningTests
190
+ class MixedFailTests < RunningTheTestsTests
212
191
  desc "and has 1 pass and 1 fail assertion with a fail call in between"
213
192
  setup do
214
193
  @test = Factory.test do
@@ -234,9 +213,7 @@ class Assert::Test
234
213
 
235
214
  end
236
215
 
237
-
238
-
239
- class MixedFlunkTests < RunningTests
216
+ class MixedFlunkTests < RunningTheTestsTests
240
217
  desc "and has 1 pass and 1 fail assertion with a flunk call in between"
241
218
  setup do
242
219
  @test = Factory.test do
@@ -262,9 +239,7 @@ class Assert::Test
262
239
 
263
240
  end
264
241
 
265
-
266
-
267
- class WithSetupTests < RunningTests
242
+ class WithSetupTests < RunningTheTestsTests
268
243
  desc "a Test that runs and has assertions that depend on setups"
269
244
  setup do
270
245
  assert_style_msg = @asm = "set by assert style setup"
@@ -307,9 +282,7 @@ class Assert::Test
307
282
 
308
283
  end
309
284
 
310
-
311
-
312
- class WithTeardownTests < RunningTests
285
+ class WithTeardownTests < RunningTheTestsTests
313
286
  desc "a Test that runs and has assertions with teardowns"
314
287
  setup do
315
288
  assert_style_msg = @asm = "set by assert style teardown"
@@ -0,0 +1,57 @@
1
+ require 'assert'
2
+ require 'assert/assertions'
3
+
4
+ module Assert::Assertions
5
+
6
+ class AssertBlockTests < Assert::Context
7
+ desc "the `assert_block` helper"
8
+ setup do
9
+ desc = @desc = "assert block fail desc"
10
+ @test = Factory.test do
11
+ assert_block{ true } # pass
12
+ assert_block(desc){ false } # fail
13
+ end
14
+ @test.run
15
+ end
16
+ subject{ @test }
17
+
18
+ should "produce results as expected" do
19
+ assert_equal 2, subject.result_count
20
+ assert_equal 1, subject.result_count(:pass)
21
+ assert_equal 1, subject.result_count(:fail)
22
+ end
23
+
24
+ should "have a fail message with custom and generic explanations" do
25
+ exp = "#{@desc}\nExpected block to return a true value."
26
+ assert_equal exp, subject.fail_results.first.message
27
+ end
28
+
29
+ end
30
+
31
+ class AssertNotBlockTests < Assert::Context
32
+ desc "the assert_not_block helper"
33
+ setup do
34
+ desc = @desc = "assert not block fail desc"
35
+ @test = Factory.test do
36
+ assert_not_block(desc){ true } # fail
37
+ assert_not_block{ false } # pass
38
+ end
39
+ @test.run
40
+ end
41
+ subject{ @test }
42
+
43
+ should "produce results as expected" do
44
+ assert_equal 2, subject.result_count
45
+ assert_equal 1, subject.result_count(:pass)
46
+ assert_equal 1, subject.result_count(:fail)
47
+ end
48
+
49
+ should "have a fail message with custom and generic explanations" do
50
+ exp = "#{@desc}\nExpected block to return a false value."
51
+ assert_equal exp, subject.fail_results.first.message
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,58 @@
1
+ require 'assert'
2
+ require 'assert/assertions'
3
+
4
+ module Assert::Assertions
5
+
6
+ class AssertEmptyTests < Assert::Context
7
+ desc "the assert_empty helper"
8
+ setup do
9
+ desc = @desc = "assert empty fail desc"
10
+ args = @args = [ [ 1 ], desc ]
11
+ @test = Factory.test do
12
+ assert_empty([]) # pass
13
+ assert_empty(*args) # fail
14
+ end
15
+ @test.run
16
+ end
17
+ subject{ @test }
18
+
19
+ should "produce results as expected" do
20
+ assert_equal 2, subject.result_count
21
+ assert_equal 1, subject.result_count(:pass)
22
+ assert_equal 1, subject.result_count(:fail)
23
+ end
24
+
25
+ should "have a fail message with custom and generic explanations" do
26
+ exp = "#{@args[1]}\nExpected #{@args[0].inspect} to be empty."
27
+ assert_equal exp, subject.fail_results.first.message
28
+ end
29
+
30
+ end
31
+
32
+ class AssertNotEmptyTests < Assert::Context
33
+ desc "the assert_not_empty helper"
34
+ setup do
35
+ desc = @desc = "assert not empty fail desc"
36
+ args = @args = [ [], desc ]
37
+ @test = Factory.test do
38
+ assert_not_empty([ 1 ]) # pass
39
+ assert_not_empty(*args) # fail
40
+ end
41
+ @test.run
42
+ end
43
+ subject{ @test }
44
+
45
+ should "produce results as expected" do
46
+ assert_equal 2, subject.result_count
47
+ assert_equal 1, subject.result_count(:pass)
48
+ assert_equal 1, subject.result_count(:fail)
49
+ end
50
+
51
+ should "have a fail message with custom and generic explanations" do
52
+ exp = "#{@args[1]}\nExpected #{@args[0].inspect} to not be empty."
53
+ assert_equal exp, subject.fail_results.first.message
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,59 @@
1
+ require 'assert'
2
+ require 'assert/assertions'
3
+
4
+ module Assert::Assertions
5
+
6
+ class AssertEqualTests < Assert::Context
7
+ desc "the assert_equal helper"
8
+ setup do
9
+ desc = @desc = "assert equal fail desc"
10
+ args = @args = [ '1', '2', desc ]
11
+ @test = Factory.test do
12
+ assert_equal(1, 1) # pass
13
+ assert_equal(*args) # fail
14
+ end
15
+ @test.run
16
+ end
17
+ subject{ @test }
18
+
19
+ should "produce results as expected" do
20
+ assert_equal 2, subject.result_count
21
+ assert_equal 1, subject.result_count(:pass)
22
+ assert_equal 1, subject.result_count(:fail)
23
+ end
24
+
25
+ should "have a fail message with custom and generic explanations" do
26
+ exp = "#{@args[2]}\nExpected #{@args[0].inspect}, not #{@args[1].inspect}."
27
+ assert_equal exp, subject.fail_results.first.message
28
+ end
29
+
30
+ end
31
+
32
+ class AssertNotEqualTests < Assert::Context
33
+ desc "the assert_not_equal helper"
34
+ setup do
35
+ desc = @desc = "assert not equal fail desc"
36
+ args = @args = [ '1', '1', desc ]
37
+ @test = Factory.test do
38
+ assert_not_equal(*args) # fail
39
+ assert_not_equal(1, 2) # pass
40
+ end
41
+ @test.run
42
+ end
43
+ subject{ @test }
44
+
45
+ should "produce results as expected" do
46
+ assert_equal 2, subject.result_count
47
+ assert_equal 1, subject.result_count(:pass)
48
+ assert_equal 1, subject.result_count(:fail)
49
+ end
50
+
51
+ should "have a fail message with custom and generic explanations" do
52
+ exp = "#{@args[2]}\n"\
53
+ "#{@args[1].inspect} not expected to equal #{@args[0].inspect}."
54
+ assert_equal exp, subject.fail_results.first.message
55
+ end
56
+
57
+ end
58
+
59
+ end