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
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify dependencies in assert.gemspec
4
4
  gemspec
File without changes
data/Rakefile CHANGED
@@ -1,3 +1 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
1
+ require "bundler/gem_tasks"
@@ -1,22 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "assert/version"
4
5
 
5
- Gem::Specification.new do |s|
6
- s.name = "assert"
7
- s.version = Assert::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Kelly Redding", "Collin Redding"]
10
- s.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
11
- s.homepage = "http://github.com/redding/assert"
12
- s.summary = %q{Test::Unit style testing framework, just better than Test::Unit.}
13
- s.description = %q{Test::Unit style testing framework, just better than Test::Unit.}
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "assert"
8
+ gem.version = Assert::VERSION
9
+ gem.authors = ["Kelly Redding", "Collin Redding"]
10
+ gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
11
+ gem.description = %q{Test::Unit style testing framework, just better than Test::Unit.}
12
+ gem.summary = %q{Test::Unit style testing framework, just better than Test::Unit.}
13
+ gem.homepage = "http://github.com/redding/assert"
14
14
 
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
19
 
20
- s.add_dependency("ansi", ["~> 1.3"])
20
+ gem.add_dependency("ansi", ["~> 1.3"])
21
21
 
22
22
  end
@@ -1,6 +1,5 @@
1
1
  require 'singleton'
2
-
3
- module Assert; end
2
+ require 'assert/version'
4
3
 
5
4
  require 'assert/view'
6
5
  require 'assert/suite'
@@ -47,7 +47,8 @@ module Assert
47
47
 
48
48
  def test_files(test_paths)
49
49
  test_paths.inject(Set.new) do |paths, path|
50
- paths += Dir.glob("#{path}*") + Dir.glob("#{path}*/**/*")
50
+ p = File.expand_path(path, Dir.pwd)
51
+ paths += Dir.glob("#{p}*") + Dir.glob("#{p}*/**/*")
51
52
  end.select{ |p| is_test_file?(p) }.sort
52
53
  end
53
54
 
@@ -1,267 +1,231 @@
1
1
  module Assert
2
2
  module Assertions
3
3
 
4
- def assert_block(fail_desc=nil)
5
- what_failed_msg ||= "Expected block to return true value."
6
- assert(yield, fail_desc, what_failed_msg)
4
+ def assert_block(desc=nil)
5
+ msg ||= "Expected block to return a true value."
6
+ assert(yield, desc, msg)
7
7
  end
8
8
 
9
- def assert_not_block(fail_desc=nil)
10
- what_failed_msg ||= "Expected block to return false value."
11
- assert(!yield, fail_desc, what_failed_msg)
9
+ def assert_not_block(desc=nil)
10
+ msg ||= "Expected block to return a false value."
11
+ assert(!yield, desc, msg)
12
12
  end
13
13
  alias_method :refute_block, :assert_not_block
14
14
 
15
-
16
-
17
- def assert_raises(*args, &block)
18
- assertion, what_failed_msg = check_exception(args, :raises, &block)
19
- assert(assertion, nil, what_failed_msg)
15
+ def assert_empty(collection, desc=nil)
16
+ msg = "Expected #{collection.inspect} to be empty."
17
+ assert(collection.empty?, desc, msg)
20
18
  end
21
- alias_method :assert_raise, :assert_raises
22
19
 
23
- def assert_nothing_raised(*args, &block)
24
- assertion, what_failed_msg = check_exception(args, :not_raises, &block)
25
- assert(!assertion, nil, what_failed_msg)
20
+ def assert_not_empty(collection, desc=nil)
21
+ msg = "Expected #{collection.inspect} to not be empty."
22
+ assert(!collection.empty?, desc, msg)
26
23
  end
27
- alias_method :assert_not_raises, :assert_nothing_raised
28
- alias_method :assert_not_raise, :assert_nothing_raised
29
-
30
-
24
+ alias_method :refute_empty, :assert_not_empty
31
25
 
32
- def assert_kind_of(klass, instance, fail_desc=nil)
33
- what_failed_msg = [
34
- "Expected #{instance.inspect} to be a kind ",
35
- "of #{klass}, not #{instance.class}."
36
- ].join
37
- assert(instance.kind_of?(klass), fail_desc, what_failed_msg)
26
+ def assert_equal(expected, actual, desc=nil)
27
+ msg = "Expected #{expected.inspect}, not #{actual.inspect}."
28
+ assert(actual == expected, desc, msg)
38
29
  end
39
30
 
40
- def assert_not_kind_of(klass, instance, fail_desc=nil)
41
- what_failed_msg = [
42
- "#{instance.inspect} was not expected to be a ",
43
- "kind of #{klass}."
44
- ].join
45
- assert(!instance.kind_of?(klass), fail_desc, what_failed_msg)
31
+ def assert_not_equal(expected, actual, desc=nil)
32
+ msg = "#{actual.inspect} not expected to equal #{expected.inspect}."
33
+ assert(actual != expected, desc, msg)
46
34
  end
47
- alias_method :refute_kind_of, :assert_not_kind_of
48
-
49
-
35
+ alias_method :refute_equal, :assert_not_equal
50
36
 
51
- def assert_instance_of(klass, instance, fail_desc=nil)
52
- what_failed_msg = [
53
- "Expected #{instance.inspect} to be an instance ",
54
- "of #{klass}, not #{instance.class}."
55
- ].join
56
- assert(instance.instance_of?(klass), fail_desc, what_failed_msg)
37
+ def assert_file_exists(file_path, desc=nil)
38
+ msg = "Expected #{file_path.inspect} to exist."
39
+ assert(File.exists?(File.expand_path(file_path)), desc, msg)
57
40
  end
58
41
 
59
- def assert_not_instance_of(klass, instance, fail_desc=nil)
60
- what_failed_msg = [
61
- "#{instance.inspect} was not expected to be an ",
62
- "instance of #{klass}."
63
- ].join
64
- assert(!instance.instance_of?(klass), fail_desc, what_failed_msg)
42
+ def assert_not_file_exists(file_path, desc=nil)
43
+ msg = "Expected #{file_path.inspect} to not exist."
44
+ assert(!File.exists?(File.expand_path(file_path)), desc, msg)
65
45
  end
66
- alias_method :refute_instance_of, :assert_not_instance_of
67
-
68
-
46
+ alias_method :refute_file_exists, :assert_not_file_exists
69
47
 
70
- def assert_respond_to(method, object, fail_desc=nil)
71
- what_failed_msg = [
72
- "Expected #{object.inspect} (#{object.class}) to ",
73
- "respond to ##{method}."
74
- ].join
75
- assert(object.respond_to?(method), fail_desc, what_failed_msg)
48
+ def assert_includes(object, collection, desc=nil)
49
+ msg = "Expected #{collection.inspect} to include #{object.inspect}."
50
+ assert(collection.include?(object), desc, msg)
76
51
  end
77
- alias_method :assert_responds_to, :assert_respond_to
52
+ alias_method :assert_included, :assert_includes
78
53
 
79
- def assert_not_respond_to(method, object, fail_desc=nil)
80
- what_failed_msg = [
81
- "#{object.inspect} (#{object.class}) not expected to ",
82
- "respond to ##{method}."
83
- ].join
84
- assert(!object.respond_to?(method), fail_desc, what_failed_msg)
54
+ def assert_not_includes(object, collection, desc=nil)
55
+ msg = "Expected #{collection.inspect} to not include #{object.inspect}."
56
+ assert(!collection.include?(object), desc, msg)
85
57
  end
86
- alias_method :assert_not_responds_to, :assert_not_respond_to
87
- alias_method :refute_respond_to, :assert_not_respond_to
88
- alias_method :refute_responds_to, :assert_not_respond_to
89
-
90
-
58
+ alias_method :assert_not_included, :assert_not_includes
59
+ alias_method :refute_includes, :assert_not_includes
60
+ alias_method :refute_included, :assert_not_includes
91
61
 
92
- def assert_same(expected, actual, fail_desc=nil)
93
- what_failed_msg = [
94
- "Expected #{expected} (#{expected.object_id}) to be the same ",
95
- "as #{actual} (#{actual.object_id})."
96
- ].join
97
- assert(actual.equal?(expected), fail_desc, what_failed_msg)
62
+ def assert_instance_of(klass, instance, desc=nil)
63
+ msg = "Expected #{instance.inspect} (#{instance.class}) to"\
64
+ " be an instance of #{klass}."
65
+ assert(instance.instance_of?(klass), desc, msg)
98
66
  end
99
67
 
100
- def assert_not_same(expected, actual, fail_desc=nil)
101
- what_failed_msg = [
102
- "#{expected} (#{expected.object_id}) not expected to be the same ",
103
- "as #{actual} (#{actual.object_id})."
104
- ].join
105
- assert(!actual.equal?(expected), fail_desc, what_failed_msg)
68
+ def assert_not_instance_of(klass, instance, desc=nil)
69
+ msg = "#{instance.inspect} not expected to be an instance of #{klass}."
70
+ assert(!instance.instance_of?(klass), desc, msg)
106
71
  end
107
- alias_method :refute_same, :assert_not_same
108
-
109
-
72
+ alias_method :refute_instance_of, :assert_not_instance_of
110
73
 
111
- def assert_equal(expected, actual, fail_desc=nil)
112
- what_failed_msg = "Expected #{expected.inspect}, not #{actual.inspect}."
113
- assert(actual == expected, fail_desc, what_failed_msg)
74
+ def assert_kind_of(klass, instance, desc=nil)
75
+ msg = "Expected #{instance.inspect} (#{instance.class}) to"\
76
+ " be a kind of #{klass}."
77
+ assert(instance.kind_of?(klass), desc, msg)
114
78
  end
115
79
 
116
- def assert_not_equal(expected, actual, fail_desc=nil)
117
- what_failed_msg = [
118
- "#{expected.inspect} not expected to be equal ", "to #{actual.inspect}."
119
- ].join
120
- assert(actual != expected, fail_desc, what_failed_msg)
80
+ def assert_not_kind_of(klass, instance, desc=nil)
81
+ msg = "#{instance.inspect} not expected to be a kind of #{klass}."
82
+ assert(!instance.kind_of?(klass), desc, msg)
121
83
  end
122
- alias_method :refute_equal, :assert_not_equal
123
-
124
-
84
+ alias_method :refute_kind_of, :assert_not_kind_of
125
85
 
126
- def assert_match(expected, actual, fail_desc=nil)
127
- what_failed_msg = "Expected #{actual.inspect} to match #{expected.inspect}."
86
+ def assert_match(expected, actual, desc=nil)
87
+ msg = "Expected #{actual.inspect} to match #{expected.inspect}."
128
88
  expected = /#{Regexp.escape(expected)}/ if String === expected && String === actual
129
- assert(actual =~ expected, fail_desc, what_failed_msg)
89
+ assert(actual =~ expected, desc, msg)
130
90
  end
131
91
 
132
- def assert_not_match(expected, actual, fail_desc=nil)
133
- what_failed_msg = [
134
- "#{actual.inspect} not expected to ", "match #{expected.inspect}."
135
- ].join
92
+ def assert_not_match(expected, actual, desc=nil)
93
+ msg = "#{actual.inspect} not expected to match #{expected.inspect}."
136
94
  expected = /#{Regexp.escape(expected)}/ if String === expected && String === actual
137
- assert(actual !~ expected, fail_desc, what_failed_msg)
95
+ assert(actual !~ expected, desc, msg)
138
96
  end
139
97
  alias_method :refute_match, :assert_not_match
140
98
  alias_method :assert_no_match, :assert_not_match
141
99
 
142
-
143
-
144
- def assert_empty(collection, fail_desc=nil)
145
- what_failed_msg = "Expected #{collection.inspect} to be empty."
146
- assert(collection.empty?, fail_desc, what_failed_msg)
100
+ def assert_nil(object, desc=nil)
101
+ msg = "Expected nil, not #{object.inspect}."
102
+ assert(object.nil?, desc, msg)
147
103
  end
148
104
 
149
- def assert_not_empty(collection, fail_desc=nil)
150
- what_failed_msg = "Expected #{collection.inspect} to not be empty."
151
- assert(!collection.empty?, fail_desc, what_failed_msg)
105
+ def assert_not_nil(object, desc=nil)
106
+ msg = "Expected #{object.inspect} to not be nil."
107
+ assert(!object.nil?, desc, msg)
152
108
  end
153
- alias_method :refute_empty, :assert_not_empty
154
-
155
-
109
+ alias_method :refute_nil, :assert_not_nil
156
110
 
157
- def assert_includes(object, collection, fail_desc=nil)
158
- what_failed_msg = "Expected #{collection.inspect} to include #{object.inspect}."
159
- assert(collection.include?(object), fail_desc, what_failed_msg)
111
+ def assert_raises(*exceptions, &block)
112
+ desc = exceptions.last.kind_of?(String) ? exceptions.pop : nil
113
+ err = RaisedException.new(exceptions, &block)
114
+ assert(err.raised?, desc, err.msg)
160
115
  end
161
- alias_method :assert_included, :assert_includes
116
+ alias_method :assert_raise, :assert_raises
162
117
 
163
- def assert_not_includes(object, collection, fail_desc=nil)
164
- what_failed_msg = "Expected #{collection.inspect} to not include #{object.inspect}."
165
- assert(!collection.include?(object), fail_desc, what_failed_msg)
118
+ def assert_nothing_raised(*exceptions, &block)
119
+ desc = exceptions.last.kind_of?(String) ? exceptions.pop : nil
120
+ err = NoRaisedException.new(exceptions, &block)
121
+ assert(!err.raised?, desc, err.msg)
166
122
  end
167
- alias_method :assert_not_included, :assert_not_includes
168
- alias_method :refute_includes, :assert_not_includes
169
- alias_method :refute_included, :assert_not_includes
170
-
171
-
123
+ alias_method :assert_not_raises, :assert_nothing_raised
124
+ alias_method :assert_not_raise, :assert_nothing_raised
172
125
 
173
- def assert_nil(object, fail_desc=nil)
174
- what_failed_msg = "Expected nil, not #{object.inspect}."
175
- assert(object.nil?, fail_desc, what_failed_msg)
126
+ def assert_respond_to(method, object, desc=nil)
127
+ msg = "Expected #{object.inspect} (#{object.class}) to"\
128
+ " respond to `#{method}`."
129
+ assert(object.respond_to?(method), desc, msg)
176
130
  end
131
+ alias_method :assert_responds_to, :assert_respond_to
177
132
 
178
- def assert_not_nil(object, fail_desc=nil)
179
- what_failed_msg = "Expected #{object.inspect} to not be nil."
180
- assert(!object.nil?, fail_desc, what_failed_msg)
133
+ def assert_not_respond_to(method, object, desc=nil)
134
+ msg = "#{object.inspect} (#{object.class}) not expected to"\
135
+ " respond to `#{method}`."
136
+ assert(!object.respond_to?(method), desc, msg)
181
137
  end
182
- alias_method :refute_nil, :assert_not_nil
183
-
184
-
138
+ alias_method :assert_not_responds_to, :assert_not_respond_to
139
+ alias_method :refute_respond_to, :assert_not_respond_to
140
+ alias_method :refute_responds_to, :assert_not_respond_to
185
141
 
186
- def assert_file_exists(file_path, fail_desc=nil)
187
- what_failed_msg = "Expected #{file_path.inspect} to exist."
188
- assert(File.exists?(File.expand_path(file_path)), fail_desc, what_failed_msg)
142
+ def assert_same(expected, actual, desc=nil)
143
+ msg = "Expected #{actual} (#{actual.object_id}) to"\
144
+ " be the same as #{expected} (#{expected.object_id})."
145
+ assert(actual.equal?(expected), desc, msg)
189
146
  end
190
147
 
191
- def assert_not_file_exists(file_path, fail_desc=nil)
192
- what_failed_msg = "Expected #{file_path.inspect} to not exist."
193
- assert(!File.exists?(File.expand_path(file_path)), fail_desc, what_failed_msg)
148
+ def assert_not_same(expected, actual, desc=nil)
149
+ msg = "#{actual} (#{actual.object_id}) not expected to"\
150
+ " be the same as #{expected} (#{expected.object_id})."
151
+ assert(!actual.equal?(expected), desc, msg)
194
152
  end
195
- alias_method :refute_file_exists, :assert_not_file_exists
196
-
153
+ alias_method :refute_same, :assert_not_same
197
154
 
155
+ # ignored assertion helpers
198
156
 
199
- IGNORED_ASSERTION_HELPERS = [ :assert_throws, :assert_nothing_thrown, :assert_send,
200
- :assert_operator, :refute_operator, :assert_in_epsilon, :refute_in_epsilon,
201
- :assert_in_delta, :refute_in_delta
157
+ IGNORED_ASSERTION_HELPERS = [
158
+ :assert_throws, :assert_nothing_thrown,
159
+ :assert_operator, :refute_operator,
160
+ :assert_in_epsilon, :refute_in_epsilon,
161
+ :assert_in_delta, :refute_in_delta,
162
+ :assert_send
202
163
  ]
203
164
  def method_missing(method, *args, &block)
204
165
  if IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
205
- ignore([
206
- "The assertion helper '#{method}' is not supported. Please use ",
207
- "another helper or the basic assert."
208
- ].join)
166
+ ignore "The assertion `#{method}` is not supported."\
167
+ " Please use another assertion or the basic `assert`."
209
168
  else
210
169
  super
211
170
  end
212
171
  end
213
172
 
214
- private
173
+ # exception raised utility classes
174
+
175
+ class CheckException
176
+ attr_reader :msg, :exception
215
177
 
216
- def check_exception(args, which, &block)
217
- fail_desc = String === args.last ? args.pop : nil
218
- exceptions = args
219
- begin
220
- yield
221
- rescue Exception => exception
178
+ def initialize(exceptions, &block)
179
+ @exceptions = exceptions
180
+ begin; block.call; rescue Exception => @exception; end
181
+ @msg = "#{exceptions_sentence(@exceptions)} #{exception_details}"
222
182
  end
223
- assertion, what_failed_msg = if exception
224
- test = exceptions.empty? || exceptions.any? do |exp|
225
- exp.instance_of?(Module) ? exception.kind_of?(exp) : exp == exception.class
183
+
184
+ def raised?
185
+ !@exception.nil? && is_one_of?(@exception, @exceptions)
186
+ end
187
+
188
+ private
189
+
190
+ def is_one_of?(exception, exceptions)
191
+ exceptions.empty? || exceptions.any? do |exp|
192
+ exp.instance_of?(Module) ? exception.kind_of?(exp) : exception.class == exp
226
193
  end
227
- [ test, exception_details(exception, which) ]
228
- else
229
- [ false, exception_details(exception, which) ]
230
194
  end
231
- what_failed_msg = "#{exceptions_sentence(exceptions)} #{what_failed_msg}"
232
- fail_desc = [ fail_desc, what_failed_msg ].compact.join("\n")
233
- [ assertion, fail_desc ]
234
- end
235
195
 
236
- def exception_details(exception, which)
237
- if exception
238
- what_failed_msg = case(which)
239
- when :raises
240
- "exception expected, not:"
241
- when :not_raises
242
- "exception was not expected, but was raised:"
196
+ def exceptions_sentence(exceptions)
197
+ if exceptions.size <= 1
198
+ (exceptions.first || "An").to_s
199
+ else
200
+ "#{exceptions[0..-2].join(", ")} or #{exceptions[-1]}"
243
201
  end
244
- backtrace = Assert::Result::Backtrace.new(exception.backtrace)
245
- [ what_failed_msg,
246
- "Class: <#{exception.class}>",
247
- "Message: <#{exception.message.inspect}>",
248
- "---Backtrace---",
249
- backtrace.filtered.to_s,
250
- "---------------"
251
- ].compact.join("\n")
252
- else
253
- case(which)
254
- when :raises
255
- "exception expected but nothing was raised."
202
+ end
203
+
204
+ def exception_details(raised_msg=nil, no_raised_msg=nil)
205
+ if @exception
206
+ backtrace = Assert::Result::Backtrace.new(@exception.backtrace)
207
+ [ raised_msg,
208
+ "Class: <#{@exception.class}>",
209
+ "Message: <#{@exception.message.inspect}>",
210
+ "---Backtrace---",
211
+ backtrace.filtered.to_s,
212
+ "---------------"
213
+ ].compact.join("\n")
214
+ else
215
+ no_raised_msg
256
216
  end
257
217
  end
258
218
  end
259
219
 
260
- def exceptions_sentence(exceptions)
261
- if exceptions.size <= 1
262
- (exceptions.first || "An").to_s
263
- else
264
- "#{exceptions[0..-2].join(", ")} or #{exceptions[-1]}"
220
+ class RaisedException < CheckException
221
+ def exception_details
222
+ super("exception expected, not:", "exception expected but nothing raised.")
223
+ end
224
+ end
225
+
226
+ class NoRaisedException < CheckException
227
+ def exception_details
228
+ super("exception not expected, but raised:")
265
229
  end
266
230
  end
267
231