assert 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assert (0.3.0)
4
+ assert (0.4.0)
5
5
  ansi (~> 1.3)
6
+ assert-view
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
10
11
  ansi (1.3.0)
12
+ assert-view (0.1.0)
11
13
  rake (0.9.2)
12
14
 
13
15
  PLATFORMS
data/README.rdoc CHANGED
@@ -15,16 +15,22 @@ Test::Unit style testing framework, just better than Test::Unit.
15
15
  * *Unit/Functional/Integration/etc*: Assert is agnostic - you define whatever kinds of tests you like (one or more of the above) and assert runs them in context.
16
16
  * *Mock/Spec/BDD/Factories/etc*: Assert is the framework and there are a variety of 3rd party tools to do such things - feel free to use whatever you like.
17
17
 
18
+
19
+
18
20
  == Description
19
21
 
20
22
  Assert is a Test::Unit style testing framework. This means you can write tests in Assert the same way you would with Test::Unit. In addition, Assert adds some helpers and syntax sugar to enhance the way tests are written - most taken from ideas in Shoulda and Leftright. Assert uses class-based contexts so if you want to nest your contexts, use good old inheritance.
21
23
 
22
24
  Assert is tested using itself. The tests are a pretty good place to look for examples and usage patterns. In addition (TODO) check out the wiki and ./examples in the source.
23
25
 
26
+
27
+
24
28
  == Installation
25
29
 
26
30
  gem install assert
27
31
 
32
+
33
+
28
34
  == Usage
29
35
 
30
36
  require 'assert'
@@ -37,11 +43,92 @@ Assert is tested using itself. The tests are a pretty good place to look for ex
37
43
 
38
44
  end
39
45
 
46
+
47
+
48
+ == Models
49
+ Assert models exist to define, collect, structure, and report on Assert test data.
50
+
51
+ === Context
52
+ Context defines the scope that tests are run in. When tests are run, a new instance of the test context is created and the test code is evaluated within scope of this context instance. Context provides methods for defining tests and test callbacks and for generating test results in running tests. Subclass context classes to achieve nested context behavior
53
+
54
+ === Suite
55
+ Suite is reponsible for collecting and structuring tests and defines the set of tests to run be the test runner. Tests are grouped within the suite by their context. Suite provides access to the contexts, test, and test results to both test runners and views. In addition, the Suite model provides some stats readers (ie. run_time, runnner_seed, etc...) for use by the test runner and views.
56
+
57
+ === Test
58
+ Test defines the test code that needs to be run and the results generated by that test code. Tests are aware of their context and are responsible for running their code in context.
59
+
60
+ === Result
61
+ Result defines the data related to a test result. There are a few kinds of test results available:
62
+ * Pass
63
+ * Fail
64
+ * Error
65
+ * Skip
66
+ * Ignore
67
+
68
+ Tests can have many results of varying types.
69
+
70
+ === Macro
71
+ Macros are procs that define sets of test code and make it available for easy reuse. Macros work nicely with the 'should' and 'test' context methods.
72
+
73
+
74
+
75
+ == Running Tests
76
+ Assert uses a Runner object to run tests. Any runner object should take the test suite and view as arguments and should provide a 'run' method that runs the tests and renders the view.
77
+
78
+ === Default Runner
79
+ Assert provides a default Runner object for running test suites (https://github.com/teaminsight/assert/blob/master/lib/assert/runner.rb). The default provides methods for running the tests, randomizing test order, and benchmarking test run time. Feel free to extend this runner as you see fit.
80
+
81
+ === Test Order
82
+ The default Runner object runs tests in random order and the default Terminal view will display the seed value. If you want to run tests in a consistant order, set a 'runner_seed' environment variable. Here's an example running tests with rake:
83
+
84
+ $ rake test # run tests in random order
85
+ $ rake test runner_seed=1234 # run tests seeding with '1234'
86
+
87
+ === Rake Tasks
88
+ Assert provides some rake task helpers that will scan your test folder and recursively generate rake tasks for each one of your test folders or files ending in '_test'. Use this as an alternative to running ruby on each one of your test files individually.
89
+
90
+ As an example, say your test folder has a file structure like so:
91
+
92
+ - test
93
+ | - basic_test.rb
94
+ | - helper.rb
95
+ | - complex
96
+ | | - fast_tests.rb
97
+ | | - slow_tests.rb
98
+
99
+ Add the following to your Rakefile to generate the test tasks:
100
+
101
+ require 'assert/rake_tasks'
102
+ Assert::RakeTasks.for(:test)
103
+
104
+ This would generate following rake tasks:
105
+
106
+ $ rake -T
107
+ rake test # Run all tests
108
+ rake test:basic # Run tests for basic
109
+ rake test:complex # Run all tests for assertions
110
+ rake test:complex:fast # Run tests for assertions:assert_block
111
+ rake test:complex:slow # Run tests for assertions:assert_empty
112
+
113
+ === IRB with your environment loaded
114
+ Assert provides a rake task for running irb with your test environment loaded. Create an irb.rb file in your test file directory and have it require 'assert/setup'. See https://github.com/teaminsight/assert/blob/master/test/irb.rb for an example. Here's how you could use it:
115
+
116
+ $ rake irb
117
+ > Assert
118
+ => Assert
119
+ >
120
+
40
121
  == The Assert family of testing tools
41
122
 
42
123
  These are all tools that use and extend Assert. If you write your own, share it with us and we will post it here.
43
124
 
44
- (TODO)
125
+ === assert-view
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
+
128
+ # default is Assert::View::Terminal.new(Assert.suite, $stdout)
129
+ Assert.options.view Assert::View::DifferentView.new(Assert.suite, $stdout)
130
+
131
+
45
132
 
46
133
  == Contributing
47
134
 
@@ -51,6 +138,8 @@ One note, however: please respect that Assert itself is intended to be the flexi
51
138
 
52
139
  If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in it's own gem (named 'assert-<whatever>') that uses Assert as a dependency. When you do, tell us about it and we'll add to the Family of tools.
53
140
 
141
+
142
+
54
143
  == License
55
144
 
56
145
  Copyright (c) 2011 Kelly Redding, Collin Redding, and Team Insight
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'assert/rake_tasks'
2
- include Assert::RakeTasks
2
+ Assert::RakeTasks.for(:test)
3
3
 
4
4
  require 'bundler'
5
5
  Bundler::GemHelper.install_tasks
data/assert.gemspec CHANGED
@@ -18,5 +18,6 @@ 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")
21
22
  s.add_dependency("ansi", ["~> 1.3"])
22
23
  end
data/lib/assert.rb CHANGED
@@ -1,3 +1,10 @@
1
+ require 'assert/options'
2
+
3
+ module Assert
4
+ include Assert::Options
5
+ options {}
6
+ end
7
+
1
8
  require 'assert/setup'
2
9
  require 'assert/autorun'
3
10
 
@@ -1,5 +1,4 @@
1
1
  require 'assert/setup'
2
- require 'assert/runner'
3
2
 
4
3
  module Assert
5
4
 
@@ -23,7 +22,7 @@ module Assert
23
22
 
24
23
  exit_code = nil
25
24
  at_exit { exit(false) if exit_code && exit_code != 0 }
26
- Runner.new(self.suite, self.view).run
25
+ self.runner.new(self.suite, self.view).run
27
26
  end unless @@at_exit_installed
28
27
  @@at_exit_installed = true
29
28
  end
@@ -84,9 +84,11 @@ module Assert
84
84
  if desc_or_macro.kind_of?(Macro)
85
85
  instance_eval(&desc_or_macro)
86
86
  else
87
- raise ArgumentError, "please provide a test block" unless block_given?
88
87
  method_name = "test: #{desc_or_macro}"
89
88
 
89
+ # if no block given, create a test that just skips
90
+ method_block = block_given? ? block : (Proc.new { skip })
91
+
90
92
  # instead of using the typical 'method_defined?' pattern (which) checks
91
93
  # all parent contexts, we really just need to make sure the method_name
92
94
  # is not part of self's local_pulic_test_methods for this check
@@ -97,10 +99,15 @@ module Assert
97
99
  puts " self: #{self.inspect}"
98
100
  end
99
101
 
100
- define_method(method_name, &block)
102
+ define_method(method_name, &method_block)
101
103
  end
102
104
  end
103
105
 
106
+ def test_eventually(desc, &block)
107
+ test(desc)
108
+ end
109
+ alias_method :test_skip, :test_eventually
110
+
104
111
  def should(desc_or_macro, &block)
105
112
  if !desc_or_macro.kind_of?(Macro)
106
113
  desc_or_macro = "should #{desc_or_macro}"
@@ -108,13 +115,8 @@ module Assert
108
115
  test(desc_or_macro, &block)
109
116
  end
110
117
 
111
- def test_eventually(desc, &block)
112
- test(desc) { skip }
113
- end
114
- alias_method :test_skip, :test_eventually
115
-
116
118
  def should_eventually(desc, &block)
117
- should(desc) { skip }
119
+ should(desc)
118
120
  end
119
121
  alias_method :should_skip, :should_eventually
120
122
 
@@ -3,7 +3,6 @@ require 'rake/tasklib'
3
3
 
4
4
  module Assert; end
5
5
  module Assert::RakeTasks
6
- include Rake::DSL if defined? Rake::DSL
7
6
 
8
7
  FILE_SUFFIX = "_test.rb"
9
8
 
@@ -23,6 +22,7 @@ module Assert::RakeTasks
23
22
 
24
23
 
25
24
  class TestTask < Rake::TaskLib
25
+
26
26
  attr_accessor :name, :description, :test_files
27
27
 
28
28
  # Create a testing task.
@@ -62,6 +62,8 @@ module Assert::RakeTasks
62
62
  end
63
63
 
64
64
  class << self
65
+ include Rake::DSL if defined? Rake::DSL
66
+
65
67
  def irb_task(path)
66
68
  irb_file = File.join(path, "irb.rb")
67
69
  if File.exist?(irb_file)
data/lib/assert/runner.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'assert/view/terminal'
2
-
3
1
  module Assert
4
2
  class Runner
5
3
 
@@ -27,15 +25,10 @@ module Assert
27
25
  protected
28
26
 
29
27
  def tests_to_run
30
- tests = @suite.tests
31
-
32
28
  # order tests randomly
33
- max = tests.size
34
- srand
35
- seed = srand % 0xFFFF
36
- srand seed
37
- tests.sort.sort_by { rand max }
38
- tests
29
+ tests = @suite.tests
30
+ srand @suite.runner_seed
31
+ tests.sort.sort_by { rand tests.size }
39
32
  end
40
33
 
41
34
  private
data/lib/assert/setup.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'assert/setup/suite'
2
2
  require 'assert/setup/view'
3
+ require 'assert/setup/runner'
3
4
  require 'assert/setup/helpers'
4
5
 
5
6
  Assert::Helpers.load(caller)
@@ -0,0 +1,14 @@
1
+ require 'assert/options'
2
+ require 'assert/runner'
3
+
4
+ module Assert
5
+ # Setup the default global runner for running tests
6
+ options do
7
+ default_runner Runner
8
+ end
9
+
10
+ class << self
11
+ def runner; self.options.runner; end
12
+ end
13
+
14
+ end
@@ -2,11 +2,15 @@ require 'assert/context'
2
2
  require 'assert/suite'
3
3
 
4
4
  module Assert
5
-
6
5
  # Setup the default global suite for collecting tests as contexts are defined
7
- @@suite = Suite.new
6
+ options do
7
+ default_suite Suite.new
8
+ end
9
+
8
10
  class << self
9
- def suite; @@suite; end
11
+ def suite
12
+ self.options.suite
13
+ end
10
14
  end
11
15
 
12
16
  end
@@ -1,11 +1,13 @@
1
1
  require 'assert/view/terminal'
2
2
 
3
3
  module Assert
4
-
5
4
  # Setup the default view to render test results (override in user or package helpers)
6
- @@view = View::Terminal.new(self.suite, $stdout)
5
+ options do
6
+ default_view View::Terminal.new($stdout)
7
+ end
8
+
7
9
  class << self
8
- def view; @@view; end
10
+ def view; self.options.view; end
9
11
  end
10
12
 
11
13
  end
data/lib/assert/suite.rb CHANGED
@@ -12,6 +12,13 @@ module Assert
12
12
  (@end_time || 0) - (@start_time || 0)
13
13
  end
14
14
 
15
+ def runner_seed
16
+ @run_seed ||= (ENV["runner_seed"] || begin
17
+ srand
18
+ srand % 0xFFFF
19
+ end).to_i
20
+ end
21
+
15
22
  def <<(context_klass)
16
23
  # gsub off any trailing 'Test'
17
24
  self[context_klass] ||= []
data/lib/assert/test.rb CHANGED
@@ -8,7 +8,7 @@ module Assert
8
8
  class Test
9
9
  include Assert::Options
10
10
  options do
11
- default_capture_out true
11
+ default_capture_output false
12
12
  end
13
13
 
14
14
  # a Test is some code/method to run in the scope of a Context. After a
@@ -28,7 +28,7 @@ module Assert
28
28
  def run(view=nil)
29
29
  @results.view = view
30
30
  run_scope = @context_class.new(self)
31
- capture_out(StringIO.new(@output, "w+")) do
31
+ capture_output(StringIO.new(@output, "w+")) do
32
32
  begin
33
33
  @context_class.setup(run_scope)
34
34
  if @code.kind_of?(::Proc)
@@ -79,8 +79,8 @@ module Assert
79
79
 
80
80
  protected
81
81
 
82
- def capture_out(io, &block)
83
- if self.class.options.capture_out && io
82
+ def capture_output(io, &block)
83
+ if self.class.options.capture_output && io
84
84
  orig_stdout = $stdout.clone
85
85
  $stdout = io
86
86
  block.call
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,30 @@
1
+ require 'assert'
2
+
3
+ require 'assert/options'
4
+ require 'assert/view/terminal'
5
+ require 'assert/runner'
6
+ require 'assert/suite'
7
+
8
+ module Assert
9
+ class AssertOptionsTest < Assert::Context
10
+ desc "options for Assert"
11
+ subject { Assert.options }
12
+
13
+ should "be an Options::Base object" do
14
+ assert_kind_of Assert::Options::Base, subject
15
+ end
16
+
17
+ should "default the view option" do
18
+ assert_kind_of Assert::View::Terminal, subject.default_view
19
+ end
20
+
21
+ should "default the suite option" do
22
+ assert_kind_of Assert::Suite, subject.default_suite
23
+ end
24
+
25
+ should "default the runner option" do
26
+ assert_equal Assert::Runner, subject.default_runner
27
+ end
28
+
29
+ end
30
+ end
@@ -241,12 +241,12 @@ class Assert::Context
241
241
  class TestMethTest < ClassMethodsTest
242
242
  desc "test method"
243
243
  setup do
244
- should_desc = "be true"
245
- should_block = @should_block = ::Proc.new{ assert(true) }
246
- @context_class = Factory.context_class do
247
- test(should_desc, &should_block)
248
- end
249
- @method_name = "test: #{should_desc}"
244
+ @should_desc = "be true"
245
+ @should_block = ::Proc.new{ assert(true) }
246
+ @method_name = "test: #{@should_desc}"
247
+
248
+ d, b = @should_desc, @should_block
249
+ @context_class = Factory.context_class { test(d, &b) }
250
250
  @context = @context_class.new(Factory.test("something", @context_class))
251
251
  end
252
252
  subject{ @context }
@@ -258,15 +258,30 @@ class Assert::Context
258
258
 
259
259
  end
260
260
 
261
- class TestEventuallyTest < ClassMethodsTest
261
+ class NoBlockTestMethTest < TestMethTest
262
+ desc "called with no block"
263
+ setup do
264
+ d = @should_desc
265
+ @context_class = Factory.context_class { test(d) }
266
+ @context = @context_class.new(Factory.test("something", @context_class))
267
+ end
268
+ subject{ @context }
269
+
270
+ should "define a test method named after the should desc that raises a test skipped" do
271
+ assert_raises(Assert::Result::TestSkipped) do
272
+ subject.send(@method_name)
273
+ end
274
+ end
275
+
276
+ end
277
+
278
+ class TestEventuallyTest < TestMethTest
262
279
  desc "test_eventually method"
263
280
  setup do
264
- should_desc = @should_desc = "be true"
265
- should_block = @should_block = ::Proc.new{ assert(true) }
281
+ d, b = @should_desc, @should_block
266
282
  @context_class = Factory.context_class do
267
- test_eventually(should_desc, &should_block)
283
+ test_eventually(d, &b)
268
284
  end
269
- @method_name = "test: #{@should_desc}"
270
285
  @context = @context_class.new(Factory.test("something", @context_class))
271
286
  end
272
287
  subject{ @context }
@@ -283,14 +298,14 @@ class Assert::Context
283
298
 
284
299
 
285
300
  class ShouldTest < ClassMethodsTest
286
- desc "should method"
301
+ desc "'should' method"
287
302
  setup do
288
- should_desc = "be true"
289
- should_block = @should_block = ::Proc.new{ assert(true) }
290
- @context_class = Factory.context_class do
291
- should(should_desc, &should_block)
292
- end
293
- @method_name = "test: should #{should_desc}"
303
+ @should_desc = "be true"
304
+ @should_block = ::Proc.new{ assert(true) }
305
+ @method_name = "test: should #{@should_desc}"
306
+
307
+ d, b = @should_desc, @should_block
308
+ @context_class = Factory.context_class { should(d, &b) }
294
309
  @context = @context_class.new(Factory.test("something", @context_class))
295
310
  end
296
311
  subject{ @context }
@@ -302,17 +317,28 @@ class Assert::Context
302
317
 
303
318
  end
304
319
 
320
+ class NoBlockShouldTest < ShouldTest
321
+ desc "called with no block"
322
+ setup do
323
+ d = @should_desc
324
+ @context_class = Factory.context_class { should(d) }
325
+ @context = @context_class.new(Factory.test("something", @context_class))
326
+ end
327
+ subject{ @context }
328
+
329
+ should "define a test method named after the should desc that raises a test skipped" do
330
+ assert_raises(Assert::Result::TestSkipped) do
331
+ subject.send(@method_name)
332
+ end
333
+ end
305
334
 
335
+ end
306
336
 
307
- class ShouldEventuallyTest < ClassMethodsTest
337
+ class ShouldEventuallyTest < ShouldTest
308
338
  desc "should_eventually method"
309
339
  setup do
310
- should_desc = @should_desc = "be true"
311
- should_block = @should_block = ::Proc.new{ assert(true) }
312
- @context_class = Factory.context_class do
313
- should_eventually(should_desc, &should_block)
314
- end
315
- @method_name = "test: should #{@should_desc}"
340
+ d, b = @should_desc, @should_block
341
+ @context_class = Factory.context_class { should_eventually(d, &b) }
316
342
  @context = @context_class.new(Factory.test("something", @context_class))
317
343
  end
318
344
  subject{ @context }
data/test/options_test.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'assert'
2
-
3
2
  require 'assert/options'
4
3
 
5
4
  module Assert::Options
@@ -43,36 +42,4 @@ module Assert::Options
43
42
 
44
43
  end
45
44
 
46
- class TerminalTest < BaseTest
47
- desc "for the terminal view"
48
- subject do
49
- Assert::View::Terminal.options
50
- end
51
-
52
- should "be an Options::Base object" do
53
- assert_kind_of Assert::Options::Base, Assert::View::Terminal.options
54
- end
55
-
56
- should "default the styled option" do
57
- assert_equal false, subject.default_styled
58
- end
59
-
60
- should "default its result abbreviations" do
61
- assert_equal '.', subject.default_passed_abbrev
62
- assert_equal 'F', subject.default_failed_abbrev
63
- assert_equal 'I', subject.default_ignored_abbrev
64
- assert_equal 'S', subject.default_skipped_abbrev
65
- assert_equal 'E', subject.default_errored_abbrev
66
- end
67
-
68
- should "default its result styles" do
69
- assert_equal :green, subject.default_passed_styles
70
- assert_equal [:red, :bold], subject.default_failed_styles
71
- assert_equal :magenta, subject.default_ignored_styles
72
- assert_equal :cyan, subject.default_skipped_styles
73
- assert_equal [:yellow, :bold], subject.default_errored_styles
74
- end
75
-
76
- end
77
-
78
45
  end
data/test/suite_test.rb CHANGED
@@ -16,11 +16,12 @@ class Assert::Suite
16
16
  end
17
17
  subject { @suite }
18
18
 
19
- should have_accessors :start_time, :end_time
20
19
  should have_instance_method :<<
21
20
  should have_instance_methods :contexts, :tests, :ordered_tests, :ordered_results
22
21
  should have_instance_methods :count, :test_count, :result_count
23
- should have_instance_method :run_time
22
+
23
+ should have_accessors :start_time, :end_time
24
+ should have_instance_method :run_time, :runner_seed
24
25
 
25
26
  should "be a hash" do
26
27
  assert_kind_of ::Hash, subject
data/test/test_test.rb CHANGED
@@ -190,12 +190,12 @@ class Assert::Test
190
190
  puts "std out from the test"
191
191
  assert true
192
192
  }
193
- @orig_capture = @test.class.options.capture_out
194
- @test.class.options.capture_out(true)
193
+ @orig_capture = @test.class.options.capture_output
194
+ @test.class.options.capture_output(true)
195
195
  @test.run
196
196
  }
197
197
  teardown {
198
- @test.class.options.capture_out(@orig_capture)
198
+ @test.class.options.capture_output(@orig_capture)
199
199
  }
200
200
 
201
201
  should "capture any io from the test" do
@@ -220,12 +220,12 @@ class Assert::Test
220
220
  true
221
221
  end
222
222
 
223
- @orig_capture = @test.class.options.capture_out
224
- @test.class.options.capture_out(true)
223
+ @orig_capture = @test.class.options.capture_output
224
+ @test.class.options.capture_output(true)
225
225
  @test.run
226
226
  end
227
227
  teardown {
228
- @test.class.options.capture_out(@orig_capture)
228
+ @test.class.options.capture_output(@orig_capture)
229
229
  }
230
230
 
231
231
  should "collect it on itself in the output accessor" do
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: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,11 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-23 00:00:00 Z
19
+ date: 2011-08-31 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
22
  type: :development
23
+ prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
@@ -31,12 +31,26 @@ dependencies:
31
31
  - 1
32
32
  - 0
33
33
  version: "1.0"
34
- name: bundler
35
34
  version_requirements: *id001
35
+ name: bundler
36
36
  - !ruby/object:Gem::Dependency
37
- prerelease: false
38
37
  type: :runtime
38
+ prerelease: false
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ version_requirements: *id002
49
+ name: assert-view
50
+ - !ruby/object:Gem::Dependency
51
+ type: :runtime
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
40
54
  none: false
41
55
  requirements:
42
56
  - - ~>
@@ -46,8 +60,8 @@ dependencies:
46
60
  - 1
47
61
  - 3
48
62
  version: "1.3"
63
+ version_requirements: *id003
49
64
  name: ansi
50
- version_requirements: *id002
51
65
  description: Test::Unit style testing framework, just better than Test::Unit.
52
66
  email:
53
67
  - kelly@kelredd.com
@@ -77,13 +91,13 @@ files:
77
91
  - lib/assert/runner.rb
78
92
  - lib/assert/setup.rb
79
93
  - lib/assert/setup/helpers.rb
94
+ - lib/assert/setup/runner.rb
80
95
  - lib/assert/setup/suite.rb
81
96
  - lib/assert/setup/view.rb
82
97
  - lib/assert/suite.rb
83
98
  - lib/assert/test.rb
84
99
  - lib/assert/version.rb
85
- - lib/assert/view/base.rb
86
- - lib/assert/view/terminal.rb
100
+ - test/assert_test.rb
87
101
  - test/assertions/assert_block_test.rb
88
102
  - test/assertions/assert_empty_test.rb
89
103
  - test/assertions/assert_equal_test.rb
@@ -121,7 +135,6 @@ files:
121
135
  - test/suite_test.rb
122
136
  - test/test/running_test.rb
123
137
  - test/test_test.rb
124
- - test/view_test.rb
125
138
  homepage: http://github.com/teaminsight/assert
126
139
  licenses: []
127
140
 
@@ -151,11 +164,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
164
  requirements: []
152
165
 
153
166
  rubyforge_project:
154
- rubygems_version: 1.8.8
167
+ rubygems_version: 1.8.10
155
168
  signing_key:
156
169
  specification_version: 3
157
170
  summary: Test::Unit style testing framework, just better than Test::Unit.
158
171
  test_files:
172
+ - test/assert_test.rb
159
173
  - test/assertions/assert_block_test.rb
160
174
  - test/assertions/assert_empty_test.rb
161
175
  - test/assertions/assert_equal_test.rb
@@ -193,4 +207,3 @@ test_files:
193
207
  - test/suite_test.rb
194
208
  - test/test/running_test.rb
195
209
  - test/test_test.rb
196
- - test/view_test.rb
@@ -1,54 +0,0 @@
1
- require 'assert/options'
2
-
3
- module Assert::View
4
-
5
- class Base
6
- include Assert::Options
7
-
8
- attr_reader :suite
9
-
10
- def initialize(suite, output_io)
11
- @suite = suite
12
- @out = output_io
13
- end
14
-
15
- # override this to define how a view calls the runner and renders its results
16
- def render(*args, &runner)
17
- end
18
-
19
- def handle_runtime_result(result)
20
- sym = result.to_sym
21
- if self.respond_to?(:options)
22
- io_print(self.options.send("#{sym}_abbrev"))
23
- end
24
- end
25
-
26
- protected
27
-
28
- def io_puts(msg, opts={})
29
- @out.puts(io_msg(msg, opts={}))
30
- end
31
-
32
- def io_print(msg, opts={})
33
- @out.print(io_msg(msg, opts={}))
34
- end
35
-
36
- def io_msg(msg, opts={})
37
- if msg.kind_of?(::Symbol) && self.respond_to?(msg)
38
- self.send(msg).to_s
39
- else
40
- msg.to_s
41
- end
42
- end
43
-
44
- def run_time(format='%.6f')
45
- format % @suite.run_time
46
- end
47
-
48
- def count(type)
49
- @suite.count(type)
50
- end
51
-
52
- end
53
-
54
- end
@@ -1,131 +0,0 @@
1
- require 'assert/view/base'
2
- require 'assert/result'
3
-
4
- require 'ansi/code'
5
-
6
- module Assert::View
7
-
8
- class Terminal < Base
9
-
10
- options do
11
- default_styled false
12
- default_passed_abbrev '.'
13
- default_failed_abbrev 'F'
14
- default_ignored_abbrev 'I'
15
- default_skipped_abbrev 'S'
16
- default_errored_abbrev 'E'
17
- default_passed_styles :green
18
- default_failed_styles :red, :bold
19
- default_errored_styles :yellow, :bold
20
- default_skipped_styles :cyan
21
- default_ignored_styles :magenta
22
- end
23
-
24
- def render(*args, &block)
25
- self.io_puts(:load_stmt)
26
-
27
- if count(:tests) > 0
28
- block.call if block
29
- self.io_puts(:detailed_results)
30
- end
31
-
32
- self.io_puts(:results_stmt)
33
- end
34
-
35
- def handle_runtime_result(result)
36
- sym = result.to_sym
37
- self.io_print(result_io_msg(self.options.send("#{sym}_abbrev"), sym))
38
- end
39
-
40
- protected
41
-
42
- def load_stmt
43
- tplur = (tcount = count(:tests)) == 1 ? "test": "tests"
44
- "\nLoaded suite (#{tcount} #{tplur})"
45
- end
46
-
47
- def detailed_results
48
- details = self.suite.ordered_tests.reverse.collect do |test|
49
- test.results.collect do |result|
50
- if show_result_details?(result)
51
- [ result_io_msg(result.to_s, result.to_sym),
52
- output_io_msg(test.output.to_s)
53
- ].join("\n")
54
- end
55
- end
56
- end.flatten.compact
57
- "\n\n" + details.join("\n\n") if !details.empty?
58
- end
59
-
60
- def results_stmt
61
- rplur = (rcount = count(:results)) == 1 ? "result" : "results"
62
- [ "\n",
63
- "#{rcount} test #{rplur}: ", results_breakdown, "\n\n",
64
- "(#{run_time} seconds)"
65
- ].join('')
66
- end
67
-
68
- def results_breakdown
69
- if count(:passed) == count(:results)
70
- stmnt = if count(:results) < 1
71
- "uhh..."
72
- elsif count(:results) == 1
73
- "it passed"
74
- else
75
- "all passed"
76
- end
77
- result_io_msg(stmnt, :passed)
78
- else
79
- breakdowns = [:passed, :failed, :ignored, :skipped, :errored]
80
- breakdowns = breakdowns.inject([]) do |results, result_sym|
81
- results << (if count(result_sym) > 0
82
- result_io_msg("#{count(result_sym)} #{result_sym}", result_sym)
83
- end)
84
- end.compact
85
- if breakdowns.size < 2
86
- breakdowns.join('')
87
- elsif breakdowns.size == 2
88
- breakdowns.join(" and ")
89
- else
90
- [breakdowns[0..-2].join(", "), breakdowns.last].join(", and ")
91
- end
92
- end
93
- end
94
-
95
- def result_io_msg(msg, result_sym)
96
- term_styles = if self.options.styled
97
- self.options.send("#{result_sym}_styles")
98
- end
99
- io_msg(msg, :term_styles => term_styles)
100
- end
101
-
102
- def output_io_msg(output)
103
- if output && !output.empty?
104
- [ "--- stdout ---",
105
- io_msg(output),
106
- "--------------"
107
- ].collect{|i| i.strip}.join("\n")
108
- end
109
- end
110
-
111
- def io_msg(msg, opts={})
112
- val = super
113
- if !(style = term_style(*opts[:term_styles])).empty?
114
- val = style + val + ANSI.send(:reset)
115
- else
116
- val
117
- end
118
- end
119
-
120
- def term_style(*ansi_codes)
121
- ansi_codes.collect{|code| ANSI.send(code) rescue nil}.compact.join('')
122
- end
123
-
124
- def show_result_details?(result)
125
- ([:failed, :errored].include?(result.to_sym)) ||
126
- ([:skipped, :ignored].include?(result.to_sym) && result.message)
127
- end
128
-
129
- end
130
-
131
- end
data/test/view_test.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'assert'
2
-
3
- require 'assert/view/base'
4
- require 'assert/suite'
5
-
6
- module Assert::View
7
-
8
- class BaseTest < Assert::Context
9
- desc "the view base"
10
- setup do
11
- @view = Assert::View::Base.new(Assert::Suite.new, StringIO.new("", "w+"))
12
- end
13
- subject{ @view }
14
-
15
- should have_reader :suite
16
- should have_instance_methods :render, :handle_runtime_result, :options
17
- should have_class_method :options
18
-
19
- end
20
-
21
- end