assert 0.5.0 → 0.6.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.
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assert (0.5.0)
5
- ansi (~> 1.3)
6
- assert-view
4
+ assert (0.6.0)
5
+ assert-view (~> 0.3)
7
6
 
8
7
  GEM
9
8
  remote: http://rubygems.org/
10
9
  specs:
11
10
  ansi (1.3.0)
12
- assert-view (0.2.0)
11
+ assert-view (0.3.0)
12
+ ansi (~> 1.3)
13
13
  undies (~> 1.1)
14
14
  rake (0.9.2)
15
15
  undies (1.1.0)
data/README.rdoc CHANGED
@@ -5,9 +5,9 @@ Test::Unit style testing framework, just better than Test::Unit.
5
5
  == What Assert is
6
6
 
7
7
  * *Framework*: you define tests and the context they run in - Assert runs them. Everything is pure ruby so use any 3rd party testing tools you like. Create 3rd party tools that extend Assert behavior.
8
- * *First Class*: everything is a first class object and can be extended to your liking (and should be)
8
+ * *First* *Class*: everything is a first class object and can be extended to your liking (and should be)
9
9
  * *MVC*: tests and how they are defined (M) and executed (C) are distinct from how you view the test results (V).
10
- * *Backwards compatible*: (assuming a few minor tweaks) with Test::Unit test suites
10
+ * *Backwards* *compatible*: (assuming a few minor tweaks) with Test::Unit test suites
11
11
 
12
12
  == What Assert is not
13
13
 
@@ -125,8 +125,8 @@ These are all tools that use and extend Assert. If you write your own, share it
125
125
  === assert-view
126
126
  Assert::View (https://github.com/teaminsight/assert-view) is a collection of views that can be used with Assert. Specify what view you want to use in your ~/.assert/options.rb settings file, ie:
127
127
 
128
- # default is Assert::View::Terminal.new(Assert.suite, $stdout)
129
- Assert.options.view Assert::View::DifferentView.new(Assert.suite, $stdout)
128
+ # default is Assert::View::DefaultView on $stdout
129
+ Assert.options.view Assert::View::SuperCoolView.new($stdout)
130
130
 
131
131
 
132
132
 
data/assert.gemspec CHANGED
@@ -18,6 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_development_dependency("bundler", ["~> 1.0"])
21
- s.add_dependency("assert-view")
22
- s.add_dependency("ansi", ["~> 1.3"])
21
+ s.add_dependency("assert-view", ["~> 0.3"])
23
22
  end
@@ -26,21 +26,27 @@ module Assert
26
26
  Assert.suite.setup(&block)
27
27
  end
28
28
  alias_method :before_once, :setup_once
29
+ alias_method :startup, :setup_once
29
30
 
30
31
  def teardown_once(&block)
31
32
  Assert.suite.teardown(&block)
32
33
  end
33
34
  alias_method :after_once, :teardown_once
35
+ alias_method :shutdown, :teardown_once
34
36
 
35
37
  # Add a setup block to run before each test or run the list of teardown blocks in given scope
36
38
  def setup(scope_or_method_name = nil, &block)
37
39
  is_method = scope_or_method_name.kind_of?(String) || scope_or_method_name.kind_of?(Symbol)
38
40
  if block_given? || is_method
41
+ # arg is a block or method that needs to be stored as a setup
39
42
  self.setups << (block || scope_or_method_name)
40
43
  elsif !is_method
44
+ # arg is an instance of this class (the scope for a test),
45
+ # run the setups for this context in the scope
41
46
  scope = scope_or_method_name
42
- # setup parent before child
47
+ # setup parent...
43
48
  self.superclass.setup(scope) if self.superclass.respond_to?(:setup)
49
+ # ... before child
44
50
  self.setups.each do |setup|
45
51
  setup.kind_of?(::Proc) ? scope.instance_eval(&setup) : scope.send(setup)
46
52
  end
@@ -52,13 +58,17 @@ module Assert
52
58
  def teardown(scope_or_method_name = nil, &block)
53
59
  is_method = scope_or_method_name.kind_of?(String) || scope_or_method_name.kind_of?(Symbol)
54
60
  if block_given? || is_method
61
+ # arg is a block or method that needs to be stored as a teardown
55
62
  self.teardowns << (block || scope_or_method_name)
56
63
  elsif !is_method
64
+ # arg is an instance of this class (the scope for a test),
65
+ # run the setups for this context in the scope
57
66
  scope = scope_or_method_name
58
- # teardown child before parent
67
+ # teardown child...
59
68
  self.teardowns.each do |teardown|
60
69
  teardown.kind_of?(::Proc) ? scope.instance_eval(&teardown) : scope.send(teardown)
61
70
  end
71
+ # ... before parent
62
72
  self.superclass.teardown(scope) if self.superclass.respond_to?(:teardown)
63
73
  end
64
74
  end
@@ -77,6 +87,7 @@ module Assert
77
87
  end
78
88
  end
79
89
  alias_method :desc, :description
90
+ alias_method :describe, :description
80
91
 
81
92
  def subject(&block)
82
93
  if block_given?
@@ -1,29 +1,11 @@
1
- require 'assert/view/terminal'
2
- require 'assert/view/helpers/ansi'
1
+ require 'assert/view/default_view'
3
2
 
4
3
  module Assert
5
4
 
6
- # define an Assert::View:Terminal view that renders ansi output using the
7
- # 'assert.ansi' template and setting up some styling defaults
8
- class AnsiTerminal < View::Terminal
9
-
10
- helper View::Helpers::AnsiStyles
11
- options do
12
- default_template 'assert.ansi'
13
- default_styled false
14
- default_passed_styles :green
15
- default_failed_styles :red, :bold
16
- default_errored_styles :yellow, :bold
17
- default_skipped_styles :cyan
18
- default_ignored_styles :magenta
19
- end
20
-
21
- end
22
-
23
- # Setup the above view, rendering on $stdout, as the default view for assert
5
+ # Setup the default view, rendering on $stdout
24
6
  # (override in user or package helpers)
25
7
  options do
26
- default_view AnsiTerminal.new($stdout)
8
+ default_view View::DefaultView.new($stdout)
27
9
  end
28
10
 
29
11
  # setup the global Assert.view method
data/lib/assert/suite.rb CHANGED
@@ -84,6 +84,7 @@ module Assert
84
84
  self.setups.each{|setup| setup.call}
85
85
  end
86
86
  end
87
+ alias_method :startup, :setup
87
88
 
88
89
  def teardown(&block)
89
90
  if block_given?
@@ -92,6 +93,7 @@ module Assert
92
93
  self.teardowns.reverse.each{|teardown| teardown.call}
93
94
  end
94
95
  end
96
+ alias_method :shutdown, :teardown
95
97
 
96
98
  protected
97
99
 
data/lib/assert/test.rb CHANGED
@@ -30,7 +30,14 @@ module Assert
30
30
  run_scope = @context_class.new(self)
31
31
  capture_output(StringIO.new(@output, "w+")) do
32
32
  begin
33
+ # run any assert style 'setup do' setups
33
34
  @context_class.setup(run_scope)
35
+ # run any classic test/unit style 'def setup' setups
36
+ if run_scope.respond_to?(:setup)
37
+ run_scope.setup
38
+ end
39
+
40
+ # run the actual test code
34
41
  if @code.kind_of?(::Proc)
35
42
  run_scope.instance_eval(&@code)
36
43
  elsif run_scope.respond_to?(@code.to_s)
@@ -42,6 +49,11 @@ module Assert
42
49
  @results << Result::Error.new(self.name, err)
43
50
  ensure
44
51
  begin
52
+ # run any classic test/unit style 'def teardown' teardowns
53
+ if run_scope.respond_to?(:teardown)
54
+ run_scope.teardown
55
+ end
56
+ # run any assert style 'teardown do' teardowns
45
57
  @context_class.teardown(run_scope)
46
58
  rescue Exception => teardown_err
47
59
  @results << Result::Error.new(self.name, teardown_err)
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/test/assert_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'assert'
2
2
 
3
3
  require 'assert/options'
4
- require 'assert/view/terminal'
4
+ require 'assert/view/default_view'
5
5
  require 'assert/runner'
6
6
  require 'assert/suite'
7
7
 
@@ -15,7 +15,7 @@ module Assert
15
15
  end
16
16
 
17
17
  should "default the view option" do
18
- assert_kind_of Assert::View::Terminal, subject.default_view
18
+ assert_kind_of Assert::View::DefaultView, subject.default_view
19
19
  end
20
20
 
21
21
  should "default the suite option" do
@@ -13,9 +13,11 @@ class Assert::Context
13
13
  end
14
14
  subject{ @context_class }
15
15
 
16
- should have_instance_methods :setup_once, :before_once, :setup, :before, :setups
17
- should have_instance_methods :teardown_once, :after_once, :teardown, :after, :teardowns
18
- should have_instance_methods :description, :desc, :subject
16
+ should have_instance_methods :setup_once, :before_once, :startup
17
+ should have_instance_methods :teardown_once, :after_once, :shutdown
18
+ should have_instance_methods :setup, :before, :setups
19
+ should have_instance_methods :teardown, :after, :teardowns
20
+ should have_instance_methods :description, :desc, :describe, :subject
19
21
  should have_instance_methods :test, :test_eventually, :test_skip
20
22
  should have_instance_methods :should, :should_eventually, :should_skip
21
23
  end
@@ -102,7 +104,6 @@ class Assert::Context
102
104
  end
103
105
 
104
106
 
105
-
106
107
  class MultipleSetupsTest < ClassMethodsTest
107
108
  desc "a context class with multiple setups"
108
109
  setup do
@@ -7,36 +7,8 @@ module Assert
7
7
  desc "assert's default view"
8
8
  subject { Assert.options.default_view }
9
9
 
10
- should "be the AnsiTerminal" do
11
- assert_kind_of AnsiTerminal, subject
12
- end
13
-
14
- end
15
-
16
- class OptionsTests < DefaultViewTests
17
- desc "options"
18
- subject do
19
- Assert.options.default_view.options
20
- end
21
-
22
- should "be an Options::Base object" do
23
- assert_kind_of Assert::Options::Base, subject
24
- end
25
-
26
- should "default the template" do
27
- assert_equal 'assert.ansi', subject.default_template
28
- end
29
-
30
- should "default the styled option" do
31
- assert_equal false, subject.default_styled
32
- end
33
-
34
- should "default its result styles" do
35
- assert_equal :green, subject.default_passed_styles
36
- assert_equal [:red, :bold], subject.default_failed_styles
37
- assert_equal :magenta, subject.default_ignored_styles
38
- assert_equal :cyan, subject.default_skipped_styles
39
- assert_equal [:yellow, :bold], subject.default_errored_styles
10
+ should "be the DefaultView" do
11
+ assert_kind_of View::DefaultView, subject
40
12
  end
41
13
 
42
14
  end
data/test/options_test.rb CHANGED
@@ -35,11 +35,6 @@ module Assert::Options
35
35
  assert_equal "changed", subject.a_value
36
36
  end
37
37
 
38
- should "be provided for the terminal view" do
39
- assert_respond_to :options, Assert::View::Terminal
40
- assert_respond_to :options, Assert::View::Terminal.new("suite", "io")
41
- end
42
-
43
38
  end
44
39
 
45
40
  end
data/test/suite_test.rb CHANGED
@@ -19,6 +19,7 @@ class Assert::Suite
19
19
  should have_instance_method :<<
20
20
  should have_instance_methods :contexts, :tests, :ordered_tests, :ordered_results
21
21
  should have_instance_methods :count, :test_count, :result_count
22
+ should have_instance_methods :setup, :startup, :teardown, :shutdown
22
23
 
23
24
  should have_accessors :start_time, :end_time
24
25
  should have_instance_method :run_time, :runner_seed
@@ -265,22 +265,44 @@ class Assert::Test
265
265
 
266
266
 
267
267
  class WithSetupTest < RunningTest
268
- desc "a Test that runs and has assertions that depend on a setup block"
268
+ desc "a Test that runs and has assertions that depend on setups"
269
269
  setup do
270
+ assert_style_msg = @asm = "set by assert style setup"
271
+ testunit_style_msg = @tusm = "set by test/unit style setup"
270
272
  @context_class = Factory.context_class do
271
- setup{ @needed = true }
273
+ # assert style setup
274
+ setup do
275
+ # get msgs into test scope
276
+ @assert_style_msg = assert_style_msg
277
+ @testunit_style_msg = testunit_style_msg
278
+
279
+ @setup_asm = @assert_style_msg
280
+ end
281
+ # classic test/unit style setup
282
+ def setup; @setup_tusm = @testunit_style_msg; end
272
283
  end
273
284
  @test = Factory.test("something", @context_class) do
274
- assert(@needed)
285
+ assert @assert_style_msg
286
+ assert @testunit_style_msg
287
+
288
+ @__running_test__.pass_results.first.
289
+ instance_variable_set("@message", @setup_asm)
290
+
291
+ @__running_test__.pass_results.last.
292
+ instance_variable_set("@message", @setup_tusm)
275
293
  end
276
294
  @test.run
277
295
  end
278
296
 
279
- should "have 1 total result" do
280
- assert_equal 1, subject.result_count
297
+ should "have a passing result for each setup type" do
298
+ assert_equal 2, subject.result_count
299
+ assert_equal 2, subject.result_count(:pass)
281
300
  end
282
- should "have 1 pass result" do
283
- assert_equal 1, subject.result_count(:pass)
301
+ should "have run the assert style setup" do
302
+ assert_equal @asm, subject.pass_results.first.message
303
+ end
304
+ should "have run the test/unit style setup" do
305
+ assert_equal @tusm, subject.pass_results.last.message
284
306
  end
285
307
 
286
308
  end
@@ -288,29 +310,44 @@ class Assert::Test
288
310
 
289
311
 
290
312
  class WithTeardownTest < RunningTest
291
- desc "a Test that runs and has assertions with a teardown block"
313
+ desc "a Test that runs and has assertions with teardowns"
292
314
  setup do
293
- new_message = @new_message = "HOLLA"
315
+ assert_style_msg = @asm = "set by assert style teardown"
316
+ testunit_style_msg = @tusm = "set by test/unit style teardown"
294
317
  @context_class = Factory.context_class do
318
+ setup do
319
+ # get msgs into test scope
320
+ @assert_style_msg = assert_style_msg
321
+ @testunit_style_msg = testunit_style_msg
322
+ end
323
+ # assert style teardown
295
324
  teardown do
296
- pass_result = @__running_test__.pass_results.first
297
- pass_result.instance_variable_set("@message", new_message)
325
+ @__running_test__.pass_results.first.
326
+ instance_variable_set("@message", @assert_style_msg)
327
+ end
328
+ # classic test/unit style teardown
329
+ def teardown
330
+ @__running_test__.pass_results.last.
331
+ instance_variable_set("@message", @testunit_style_msg)
298
332
  end
299
333
  end
300
334
  @test = Factory.test("something amazing", @context_class) do
301
- assert(true)
335
+ assert(true) # first pass result
336
+ assert(true) # last pass result
302
337
  end
303
338
  @test.run
304
339
  end
305
340
 
306
- should "have 1 total result" do
307
- assert_equal 1, subject.result_count
341
+ should "have a passing result for each teardown type" do
342
+ puts subject.results.inspect
343
+ assert_equal 2, subject.result_count
344
+ assert_equal 2, subject.result_count(:pass)
308
345
  end
309
- should "have 1 pass result" do
310
- assert_equal 1, subject.result_count(:pass)
346
+ should "have run the assert style teardown" do
347
+ assert_equal @asm, subject.pass_results.first.message
311
348
  end
312
- should "have modifed the message" do
313
- assert_equal @new_message, subject.pass_results.first.message
349
+ should "have run test/unit style teardown" do
350
+ assert_equal @tusm, subject.pass_results.last.message
314
351
  end
315
352
 
316
353
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-09-08 00:00:00 Z
19
+ date: 2011-09-09 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :development
@@ -39,29 +39,15 @@ dependencies:
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ">="
42
+ - - ~>
43
43
  - !ruby/object:Gem::Version
44
- hash: 3
44
+ hash: 13
45
45
  segments:
46
46
  - 0
47
- version: "0"
47
+ - 3
48
+ version: "0.3"
48
49
  version_requirements: *id002
49
50
  name: assert-view
50
- - !ruby/object:Gem::Dependency
51
- type: :runtime
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 9
59
- segments:
60
- - 1
61
- - 3
62
- version: "1.3"
63
- version_requirements: *id003
64
- name: ansi
65
51
  description: Test::Unit style testing framework, just better than Test::Unit.
66
52
  email:
67
53
  - kelly@kelredd.com