assert 2.14.0 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/assert.gemspec +0 -2
  4. data/lib/assert/assert_runner.rb +1 -1
  5. data/lib/assert/assertions.rb +1 -1
  6. data/lib/assert/config.rb +6 -1
  7. data/lib/assert/config_helpers.rb +75 -0
  8. data/lib/assert/context.rb +20 -14
  9. data/lib/assert/context/test_dsl.rb +17 -13
  10. data/lib/assert/{view/default_view.rb → default_view.rb} +9 -17
  11. data/lib/assert/factory.rb +2 -7
  12. data/lib/assert/file_line.rb +7 -3
  13. data/lib/assert/macro.rb +1 -1
  14. data/lib/assert/macros/methods.rb +1 -1
  15. data/lib/assert/result.rb +84 -90
  16. data/lib/assert/runner.rb +8 -2
  17. data/lib/assert/suite.rb +15 -5
  18. data/lib/assert/test.rb +112 -75
  19. data/lib/assert/version.rb +1 -1
  20. data/lib/assert/view.rb +108 -21
  21. data/lib/assert/view_helpers.rb +238 -0
  22. data/test/support/factory.rb +23 -6
  23. data/test/system/test_tests.rb +359 -0
  24. data/test/unit/assertions_tests.rb +1 -1
  25. data/test/unit/config_helpers_tests.rb +95 -0
  26. data/test/unit/config_tests.rb +5 -1
  27. data/test/unit/context/test_dsl_tests.rb +25 -17
  28. data/test/unit/context_tests.rb +45 -10
  29. data/test/unit/factory_tests.rb +9 -11
  30. data/test/unit/file_line_tests.rb +22 -0
  31. data/test/unit/result_tests.rb +219 -160
  32. data/test/unit/runner_tests.rb +19 -5
  33. data/test/unit/suite_tests.rb +23 -4
  34. data/test/unit/test_tests.rb +167 -33
  35. data/test/unit/view_helpers_tests.rb +210 -0
  36. data/test/unit/view_tests.rb +66 -26
  37. metadata +12 -23
  38. data/lib/assert/view/base.rb +0 -91
  39. data/lib/assert/view/helpers/ansi_styles.rb +0 -25
  40. data/lib/assert/view/helpers/common.rb +0 -209
  41. data/test/system/running_tests.rb +0 -404
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.14.0"
2
+ VERSION = "2.15.0"
3
3
  end
@@ -1,25 +1,112 @@
1
- require 'assert/view/default_view'
2
-
3
- module Assert::View
4
-
5
- # this method is used to bring in custom user-specific views
6
- # require views by passing either a full path to the view ruby file
7
- # or passing the name of a view installed in ~/.assert/views
8
-
9
- def self.require_user_view(view_name)
10
- views_file = File.expand_path(
11
- File.join("#{ENV['HOME']}/.assert/views", view_name, 'lib', view_name)
12
- )
13
-
14
- if File.exists?(view_name) || File.exists?(view_name + '.rb')
15
- require view_name
16
- elsif File.exists?(views_file + '.rb')
17
- require views_file
18
- else
19
- msg = "[WARN] Can't find or require #{view_name.inspect} view."
20
- msg << " Did you install it in `~/.assert/views`?" if !view_name.match(/\A\//)
21
- warn msg
1
+ require 'assert/config'
2
+ require 'assert/suite'
3
+ require 'assert/view_helpers'
4
+
5
+ module Assert
6
+
7
+ module View
8
+
9
+ # this method is used to bring in custom user-specific views
10
+ # require views by passing either a full path to the view ruby file
11
+ # or passing the name of a view installed in ~/.assert/views
12
+
13
+ def self.require_user_view(view_name)
14
+ views_file = File.expand_path(
15
+ File.join("#{ENV['HOME']}/.assert/views", view_name, 'lib', view_name)
16
+ )
17
+
18
+ if File.exists?(view_name) || File.exists?(view_name + '.rb')
19
+ require view_name
20
+ elsif File.exists?(views_file + '.rb')
21
+ require views_file
22
+ else
23
+ msg = "[WARN] Can't find or require #{view_name.inspect} view."
24
+ msg << " Did you install it in `~/.assert/views`?" if !view_name.match(/\A\//)
25
+ warn msg
26
+ end
27
+ end
28
+
29
+ class Base
30
+ include Assert::ViewHelpers
31
+
32
+ # setup options and their default values
33
+
34
+ option 'styled', false
35
+ option 'pass_styles' # none
36
+ option 'fail_styles' # none
37
+ option 'error_styles' # none
38
+ option 'skip_styles' # none
39
+ option 'ignore_styles' # none
40
+
41
+ option 'pass_abbrev', '.'
42
+ option 'fail_abbrev', 'F'
43
+ option 'ignore_abbrev', 'I'
44
+ option 'skip_abbrev', 'S'
45
+ option 'error_abbrev', 'E'
46
+
47
+ attr_reader :config
48
+
49
+ def initialize(config, output_io)
50
+ @config , @output_io, = config, output_io
51
+ @output_io.sync = true if @output_io.respond_to?(:sync=)
52
+ end
53
+
54
+ def view
55
+ self
56
+ end
57
+
58
+ def is_tty?
59
+ !!@output_io.isatty
60
+ end
61
+
62
+ def ansi_styled_msg(msg, result_or_sym)
63
+ return msg if !self.is_tty? || !self.styled
64
+ code = Assert::ViewHelpers::Ansi.code_for(*self.send("#{result_or_sym.to_sym}_styles"))
65
+ return msg if code.empty?
66
+ code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
67
+ end
68
+
69
+ # Callbacks
70
+
71
+ # define callback handlers to output information. handlers are
72
+ # instance_eval'd in the scope of the view instance. any stdout is captured
73
+ # and sent to the io stream.
74
+
75
+ def fire(callback, *args)
76
+ self.send(callback, *args)
77
+ end
78
+
79
+ # available callbacks from the runner:
80
+ # * `before_load`: called at the beginning, before the suite is loaded
81
+ # * `after_load`: called after the suite is loaded, just before `on_start`
82
+ # functionally equivalent to `on_start`
83
+ # * `on_start`: called when a loaded test suite starts running
84
+ # * `before_test`: called before a test starts running
85
+ # the test is passed as an arg
86
+ # * `on_result`: called when a running tests generates a result
87
+ # the result is passed as an arg
88
+ # * `after_test`: called after a test finishes running
89
+ # the test is passed as an arg
90
+ # * `on_finish`: called when the test suite is finished running
91
+ # * `on_interrupt`: called when the test suite is interrupted while running
92
+ # the interrupt exception is passed as an arg
93
+
94
+ def before_load(test_files); end
95
+ def after_load; end
96
+ def on_start; end
97
+ def before_test(test); end
98
+ def on_result(result); end
99
+ def after_test(test); end
100
+ def on_finish; end
101
+ def on_interrupt(err); end
102
+
103
+ # IO capture
104
+
105
+ def puts(*args); @output_io.puts(*args); end
106
+ def print(*args); @output_io.print(*args); end
107
+
22
108
  end
109
+
23
110
  end
24
111
 
25
112
  end
@@ -0,0 +1,238 @@
1
+ require 'assert/config_helpers'
2
+
3
+ module Assert
4
+
5
+ module ViewHelpers
6
+
7
+ def self.included(receiver)
8
+ receiver.class_eval do
9
+ include Assert::ConfigHelpers
10
+ extend ClassMethods
11
+ include InstanceMethods
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ def option(name, *default_vals)
18
+ default = default_vals.size > 1 ? default_vals : default_vals.first
19
+ define_method(name) do |*args|
20
+ if !(value = args.size > 1 ? args : args.first).nil?
21
+ instance_variable_set("@#{name}", value)
22
+ end
23
+ (val = instance_variable_get("@#{name}")).nil? ? default : val
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ module InstanceMethods
30
+
31
+ # get the formatted run time for an idividual test
32
+ def test_run_time(test, format = '%.6f')
33
+ format % test.run_time
34
+ end
35
+
36
+ # get the formatted result rate for an individual test
37
+ def test_result_rate(test, format = '%.6f')
38
+ format % test.result_rate
39
+ end
40
+
41
+ # get all the result details for a set of tests
42
+ def result_details_for(tests, result_order = :normal)
43
+ test_index = 0
44
+ tests.collect do |test|
45
+ test_index += 1
46
+
47
+ details = test.results.collect do |result|
48
+ ResultDetails.new(result, test, test_index)
49
+ end
50
+ details.reverse! if result_order == :reversed
51
+ details
52
+ end.compact.flatten
53
+ end
54
+
55
+ # get all the result details for a set of tests matching a file or context
56
+ def matched_result_details_for(match, tests, result_order = :normal)
57
+ context_match = match.kind_of?(Class) && match.ancestors.include?(Assert::Context)
58
+ file_match = match.kind_of?(String)
59
+
60
+ matching_tests = if context_match
61
+ tests.select {|test| test.context_info.klass == match}
62
+ elsif file_match
63
+ tests.select {|test| test.context_info.file == match}
64
+ else
65
+ tests
66
+ end
67
+
68
+ result_details_for(matching_tests, result_order)
69
+ end
70
+
71
+ # only show result details for failed or errored results
72
+ # show result details if a skip or passed result was issues w/ a message
73
+ def show_result_details?(result)
74
+ [:fail, :error].include?(result.to_sym) ||
75
+ !!([:skip, :ignore].include?(result.to_sym) && result.message)
76
+ end
77
+
78
+ # show any captured output
79
+ def captured_output(output)
80
+ "--- stdout ---\n"\
81
+ "#{output}"\
82
+ "--------------"
83
+ end
84
+
85
+ def test_count_statement
86
+ "#{self.count(:tests)} test#{'s' if self.count(:tests) != 1}"
87
+ end
88
+
89
+ def result_count_statement
90
+ "#{self.count(:results)} result#{'s' if self.count(:results) != 1}"
91
+ end
92
+
93
+ # generate a comma-seperated sentence fragment given a list of items
94
+ def to_sentence(items)
95
+ if items.size <= 2
96
+ items.join(items.size == 2 ? ' and ' : '')
97
+ else
98
+ [items[0..-2].join(", "), items.last].join(", and ")
99
+ end
100
+ end
101
+
102
+ # generate an appropriate result summary msg for all tests passing
103
+ def all_pass_result_summary_msg
104
+ if self.count(:results) < 1
105
+ "uhh..."
106
+ elsif self.count(:results) == 1
107
+ "pass"
108
+ else
109
+ "all pass"
110
+ end
111
+ end
112
+
113
+ # print a result summary message for a given result type
114
+ def result_summary_msg(result_type)
115
+ if result_type == :pass && self.all_pass?
116
+ self.all_pass_result_summary_msg
117
+ else
118
+ "#{self.count(result_type)} #{result_type.to_s}"
119
+ end
120
+ end
121
+
122
+ # generate a sentence fragment describing the breakdown of test results
123
+ # if a block is given, yield each msg in the breakdown for custom formatting
124
+ def results_summary_sentence
125
+ summaries = self.ocurring_result_types.map do |result_sym|
126
+ summary_msg = self.result_summary_msg(result_sym)
127
+ block_given? ? yield(summary_msg, result_sym) : summary_msg
128
+ end
129
+ self.to_sentence(summaries)
130
+ end
131
+
132
+ end
133
+
134
+ module Ansi
135
+
136
+ # Table of supported styles/codes (http://en.wikipedia.org/wiki/ANSI_escape_code)
137
+
138
+ CODES = {
139
+ :clear => 0,
140
+ :reset => 0,
141
+ :bright => 1,
142
+ :bold => 1,
143
+ :faint => 2,
144
+ :dark => 2,
145
+ :italic => 3,
146
+ :underline => 4,
147
+ :underscore => 4,
148
+ :blink => 5,
149
+ :slow_blink => 5,
150
+ :rapid => 6,
151
+ :rapid_blink => 6,
152
+ :invert => 7,
153
+ :inverse => 7,
154
+ :reverse => 7,
155
+ :negative => 7,
156
+ :swap => 7,
157
+ :conceal => 8,
158
+ :concealed => 8,
159
+ :hide => 9,
160
+ :strike => 9,
161
+
162
+ :default_font => 10,
163
+ :font_default => 10,
164
+ :font0 => 10,
165
+ :font1 => 11,
166
+ :font2 => 12,
167
+ :font3 => 13,
168
+ :font4 => 14,
169
+ :font5 => 15,
170
+ :font6 => 16,
171
+ :font7 => 17,
172
+ :font8 => 18,
173
+ :font9 => 19,
174
+ :fraktur => 20,
175
+ :bright_off => 21,
176
+ :bold_off => 21,
177
+ :double_underline => 21,
178
+ :clean => 22,
179
+ :italic_off => 23,
180
+ :fraktur_off => 23,
181
+ :underline_off => 24,
182
+ :blink_off => 25,
183
+ :inverse_off => 26,
184
+ :positive => 26,
185
+ :conceal_off => 27,
186
+ :show => 27,
187
+ :reveal => 27,
188
+ :crossed_off => 29,
189
+ :crossed_out_off => 29,
190
+
191
+ :black => 30,
192
+ :red => 31,
193
+ :green => 32,
194
+ :yellow => 33,
195
+ :blue => 34,
196
+ :magenta => 35,
197
+ :cyan => 36,
198
+ :white => 37,
199
+
200
+ :on_black => 40,
201
+ :on_red => 41,
202
+ :on_green => 42,
203
+ :on_yellow => 43,
204
+ :on_blue => 44,
205
+ :on_magenta => 45,
206
+ :on_cyan => 46,
207
+ :on_white => 47,
208
+
209
+ :frame => 51,
210
+ :encircle => 52,
211
+ :overline => 53,
212
+ :frame_off => 54,
213
+ :encircle_off => 54,
214
+ :overline_off => 55,
215
+ }
216
+
217
+ def self.code_for(*style_names)
218
+ style_names.map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }.compact.join('')
219
+ end
220
+
221
+ end
222
+
223
+ class ResultDetails
224
+
225
+ attr_reader :result, :test_index, :test, :output
226
+
227
+ def initialize(result, test, test_index)
228
+ @result = result
229
+ @test = test
230
+ @test_index = test_index
231
+ @output = test.output
232
+ end
233
+
234
+ end
235
+
236
+ end
237
+
238
+ end
@@ -32,19 +32,36 @@ module Factory
32
32
  # Generate a no-op test for use in testing.
33
33
 
34
34
  def self.test(*args, &block)
35
- opts, config, context_info, name = [
36
- args.last.kind_of?(::Hash) ? args.pop.dup : {},
35
+ config, context_info, name = [
37
36
  args.last.kind_of?(Assert::Config) ? args.pop : self.modes_off_config,
38
37
  args.last.kind_of?(Assert::Suite::ContextInfo) ? args.pop : self.context_info,
39
38
  args.last.kind_of?(::String) ? args.pop : 'a test'
40
39
  ]
41
- Assert::Test.new(name, context_info, config, opts, &block)
40
+ Assert::Test.for_block(name, context_info, config, &block)
42
41
  end
43
42
 
44
- # Generate a skip result for use in testing.
43
+ # Generate results for use in testing.
45
44
 
46
- def self.skip_result(name, exception)
47
- Assert::Result::Skip.new(Factory.test(name), exception)
45
+ def self.pass_result(msg = nil)
46
+ Assert::Result::Pass.for_test(Factory.test(Factory.string), msg || Factory.string, [])
47
+ end
48
+
49
+ def self.ignore_result(msg = nil)
50
+ Assert::Result::Ignore.for_test(Factory.test(Factory.string), msg || Factory.string, [])
51
+ end
52
+
53
+ def self.fail_result(msg = nil)
54
+ Assert::Result::Fail.for_test(Factory.test(Factory.string), msg || Factory.string, [])
55
+ end
56
+
57
+ def self.skip_result(exception = nil)
58
+ exception ||= Assert::Result::TestSkipped.new
59
+ Assert::Result::Skip.for_test(Factory.test(Factory.string), exception)
60
+ end
61
+
62
+ def self.error_result(exception = nil)
63
+ exception ||= StandardError.new
64
+ Assert::Result::Error.for_test(Factory.test(Factory.string), exception)
48
65
  end
49
66
 
50
67
  def self.modes_off_config
@@ -0,0 +1,359 @@
1
+ require 'assert'
2
+
3
+ class Assert::Test
4
+
5
+ class SystemTests < Assert::Context
6
+ desc "Assert::Test"
7
+ subject{ @test }
8
+
9
+ end
10
+
11
+ class NoResultsTests < SystemTests
12
+ desc "when producing no results"
13
+ setup do
14
+ @test = Factory.test
15
+ @test.run
16
+ end
17
+
18
+ should "have 0 results" do
19
+ assert_equal 0, subject.result_count
20
+ end
21
+
22
+ end
23
+
24
+ class PassTests < SystemTests
25
+ desc "when passing a single assertion"
26
+ setup do
27
+ @test = Factory.test{ assert(1 == 1) }
28
+ @test.run
29
+ end
30
+
31
+ should "have 1 result" do
32
+ assert_equal 1, subject.result_count
33
+ end
34
+
35
+ should "have 1 pass result" do
36
+ assert_equal 1, subject.result_count(:pass)
37
+ end
38
+
39
+ end
40
+
41
+ class FailTests < SystemTests
42
+ desc "when failing a single assertion"
43
+ setup do
44
+ @test = Factory.test{ assert(1 == 0) }
45
+ @test.run
46
+ end
47
+
48
+ should "have 1 result" do
49
+ assert_equal 1, subject.result_count
50
+ end
51
+
52
+ should "have 1 fail result" do
53
+ assert_equal 1, subject.result_count(:fail)
54
+ end
55
+
56
+ end
57
+
58
+ class SkipTests < SystemTests
59
+ desc "when skipping once"
60
+ setup do
61
+ @test = Factory.test{ skip }
62
+ @test.run
63
+ end
64
+
65
+ should "have 1 result" do
66
+ assert_equal 1, subject.result_count
67
+ end
68
+
69
+ should "have 1 skip result" do
70
+ assert_equal 1, subject.result_count(:skip)
71
+ end
72
+
73
+ end
74
+
75
+ class ErrorTests < SystemTests
76
+ desc "when erroring once"
77
+ setup do
78
+ @test = Factory.test{ raise("WHAT") }
79
+ @test.run
80
+ end
81
+
82
+ should "have 1 result" do
83
+ assert_equal 1, subject.result_count
84
+ end
85
+
86
+ should "have 1 error result" do
87
+ assert_equal 1, subject.result_count(:error)
88
+ end
89
+
90
+ end
91
+
92
+ class MixedTests < SystemTests
93
+ desc "when passing 1 assertion and failing 1 assertion"
94
+ setup do
95
+ @test = Factory.test do
96
+ assert(1 == 1)
97
+ assert(1 == 0)
98
+ end
99
+ @test.run
100
+ end
101
+
102
+ should "have 2 total results" do
103
+ assert_equal 2, subject.result_count
104
+ end
105
+
106
+ should "have 1 pass result" do
107
+ assert_equal 1, subject.result_count(:pass)
108
+ end
109
+
110
+ should "have 1 fail result" do
111
+ assert_equal 1, subject.result_count(:fail)
112
+ end
113
+
114
+ end
115
+
116
+ class MixedSkipTests < SystemTests
117
+ desc "when passing 1 assertion and failing 1 assertion with a skip call in between"
118
+ setup do
119
+ @test = Factory.test do
120
+ assert(1 == 1)
121
+ skip
122
+ assert(1 == 0)
123
+ end
124
+ @test.run
125
+ end
126
+
127
+ should "have 2 total results" do
128
+ assert_equal 2, subject.result_count
129
+ end
130
+
131
+ should "have a skip for its last result" do
132
+ assert_kind_of Assert::Result::Skip, subject.results.last
133
+ end
134
+
135
+ should "have 1 pass result" do
136
+ assert_equal 1, subject.result_count(:pass)
137
+ end
138
+
139
+ should "have 1 skip result" do
140
+ assert_equal 1, subject.result_count(:skip)
141
+ end
142
+
143
+ should "have 0 fail results" do
144
+ assert_equal 0, subject.result_count(:fail)
145
+ end
146
+
147
+ end
148
+
149
+ class MixedErrorTests < SystemTests
150
+ desc "when passing 1 assertion and failing 1 assertion with an exception raised in between"
151
+ setup do
152
+ @test = Factory.test do
153
+ assert(1 == 1)
154
+ raise Exception, "something errored"
155
+ assert(1 == 0)
156
+ end
157
+ @test.run
158
+ end
159
+
160
+ should "have 2 total results" do
161
+ assert_equal 2, subject.result_count
162
+ end
163
+
164
+ should "have an error for its last result" do
165
+ assert_kind_of Assert::Result::Error, subject.results.last
166
+ end
167
+
168
+ should "have 1 pass result" do
169
+ assert_equal 1, subject.result_count(:pass)
170
+ end
171
+
172
+ should "have 1 error result" do
173
+ assert_equal 1, subject.result_count(:error)
174
+ end
175
+
176
+ should "have 0 fail results" do
177
+ assert_equal 0, subject.result_count(:fail)
178
+ end
179
+
180
+ end
181
+
182
+ class MixedPassTests < SystemTests
183
+ desc "when passing 1 assertion and failing 1 assertion with a pass call in between"
184
+ setup do
185
+ @test = Factory.test do
186
+ assert(1 == 1)
187
+ pass
188
+ assert(1 == 0)
189
+ end
190
+ @test.run
191
+ end
192
+
193
+ should "have 3 total results" do
194
+ assert_equal 3, subject.result_count
195
+ end
196
+
197
+ should "have a fail for its last result" do
198
+ assert_kind_of Assert::Result::Fail, subject.results.last
199
+ end
200
+
201
+ should "have 2 pass results" do
202
+ assert_equal 2, subject.result_count(:pass)
203
+ end
204
+
205
+ should "have 1 fail result" do
206
+ assert_equal 1, subject.result_count(:fail)
207
+ end
208
+
209
+ end
210
+
211
+ class MixedFailTests < SystemTests
212
+ desc "when failing 1 assertion and passing 1 assertion with a fail call in between"
213
+ setup do
214
+ @test = Factory.test do
215
+ assert(1 == 0)
216
+ fail
217
+ assert(1 == 1)
218
+ end
219
+ @test.run
220
+ end
221
+
222
+ should "have 3 total results" do
223
+ assert_equal 3, subject.result_count
224
+ end
225
+
226
+ should "have a pass for its last result" do
227
+ assert_kind_of Assert::Result::Pass, subject.results.last
228
+ end
229
+
230
+ should "have 1 pass result" do
231
+ assert_equal 1, subject.result_count(:pass)
232
+ end
233
+
234
+ should "have 2 fail results" do
235
+ assert_equal 2, subject.result_count(:fail)
236
+ end
237
+
238
+ end
239
+
240
+ class MixedFlunkTests < SystemTests
241
+ desc "has failing 1 assertion and passing 1 assertion with a flunk call in between"
242
+ setup do
243
+ @test = Factory.test do
244
+ assert(1 == 0)
245
+ flunk
246
+ assert(1 == 1)
247
+ end
248
+ @test.run
249
+ end
250
+
251
+ should "have 3 total results" do
252
+ assert_equal 3, subject.result_count
253
+ end
254
+
255
+ should "have a pass for its last result" do
256
+ assert_kind_of Assert::Result::Pass, subject.results.last
257
+ end
258
+
259
+ should "have 1 pass results" do
260
+ assert_equal 1, subject.result_count(:pass)
261
+ end
262
+
263
+ should "have 2 fail results" do
264
+ assert_equal 2, subject.result_count(:fail)
265
+ end
266
+
267
+ end
268
+
269
+ class WithSetupsTests < SystemTests
270
+ desc "that has setup logic"
271
+ setup do
272
+ @context_class = Factory.context_class do
273
+ # assert style
274
+ setup{ pass 'assert style setup' }
275
+ # test/unit style
276
+ def setup; pass 'test/unit style setup'; end
277
+ end
278
+ @test = Factory.test("t", Factory.context_info(@context_class)){ pass 'TEST' }
279
+ @test.run
280
+ end
281
+
282
+ should "execute all setup logic when run" do
283
+ assert_equal 3, subject.result_count(:pass)
284
+
285
+ exp = ['assert style setup', 'test/unit style setup', 'TEST']
286
+ assert_equal exp, subject.results.map(&:message)
287
+ end
288
+
289
+ end
290
+
291
+ class WithTeardownsTests < SystemTests
292
+ desc "that has teardown logic"
293
+ setup do
294
+ @context_class = Factory.context_class do
295
+ # assert style
296
+ teardown{ pass 'assert style teardown' }
297
+ # test/unit style
298
+ def teardown; pass 'test/unit style teardown'; end
299
+ end
300
+ @test = Factory.test("t", Factory.context_info(@context_class)){ pass 'TEST' }
301
+ @test.run
302
+ end
303
+
304
+ should "execute all teardown logic when run" do
305
+ assert_equal 3, subject.result_count(:pass)
306
+
307
+ exp = ['TEST', 'assert style teardown', 'test/unit style teardown']
308
+ assert_equal exp, subject.results.map(&:message)
309
+ end
310
+
311
+ end
312
+
313
+ class WithAroundsTests < SystemTests
314
+ desc "that has around logic (in addition to setups/teardowns)"
315
+ setup do
316
+ @parent_context_class = Factory.modes_off_context_class do
317
+ around do |block|
318
+ pass "parent around start"
319
+ block.call
320
+ pass "parent around end"
321
+ end
322
+ setup{ pass "parent setup" }
323
+ teardown{ pass "parent teardown" }
324
+ end
325
+ @context_class = Factory.modes_off_context_class(@parent_context_class) do
326
+ setup{ pass "child setup1" }
327
+ around do |block|
328
+ pass "child around1 start"
329
+ block.call
330
+ pass "child around1 end"
331
+ end
332
+ teardown{ pass "child teardown1" }
333
+ setup{ pass "child setup2" }
334
+ around do |block|
335
+ pass "child around2 start"
336
+ block.call
337
+ pass "child around2 end"
338
+ end
339
+ teardown{ pass "child teardown2" }
340
+ end
341
+ @test = Factory.test("t", Factory.context_info(@context_class)){ pass "TEST" }
342
+ @test.run
343
+ end
344
+
345
+ should "run the arounds outside of the setups/teardowns/test" do
346
+ assert_equal 13, subject.result_count(:pass)
347
+
348
+ exp = [
349
+ 'parent around start', 'child around1 start', 'child around2 start',
350
+ 'parent setup', 'child setup1', 'child setup2', 'TEST',
351
+ 'child teardown1', 'child teardown2', 'parent teardown',
352
+ 'child around2 end', 'child around1 end', 'parent around end'
353
+ ]
354
+ assert_equal exp, subject.results.map(&:message)
355
+ end
356
+
357
+ end
358
+
359
+ end