assert 2.14.0 → 2.15.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 (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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa3c97970bacaed419dd9a2986302c8f7381ef8c
4
- data.tar.gz: 0bf830c19a718be854960e6ddbb6b6bdf30f78fa
3
+ metadata.gz: 977f66c154b34e18051876043c6ef149048f3c24
4
+ data.tar.gz: 4ad230cae2d6fbe5895456d04f421843bbdb43e6
5
5
  SHA512:
6
- metadata.gz: e7dffb68840de736888b0f7aa2c4159677eb820d75a83be49c2568b1ab796ad28135cae9e397eb341b857fb2aa6bbc577d890720094d626c6b4bb3ba3042779c
7
- data.tar.gz: 772c42c5f472a9973d9d59bbc0d3e61a44886e58a7ed25d9f3cd0d6a1d15bc651da563a06ae1a455b6afd8d232cd64e3222014aaeb8e92e2cf7620b49128d909
6
+ metadata.gz: 9ea117fae5c227ae573763287d76156b11b923afa80b50c63223deb6f001605eac1eb55302f08f85ecc134eedf49efb90973cec640b6e1a11c75509100a8ccad
7
+ data.tar.gz: cf13653df60d7b5c295d2a43523923423998ae9c7b40f60bc95d95044af0577a96107d5d04a553d9de8c799bde111599d6656e2d678adcdee0ecb33750aa61e9
data/README.md CHANGED
@@ -428,7 +428,7 @@ Use this if you prefer a 3rd-party tool (like awesome_print or something) over t
428
428
 
429
429
  ## Viewing Test Results
430
430
 
431
- `Assert::View::DefaultView` is the default handler for viewing test results. Its output goes something like this:
431
+ `Assert::DefaultView` is the default view for test results. Its output goes something like this:
432
432
 
433
433
  * before the run starts, output some info about the test suite that is about to run
434
434
  * print out result abbreviations as the test results are generated
@@ -438,7 +438,7 @@ Use this if you prefer a 3rd-party tool (like awesome_print or something) over t
438
438
 
439
439
  You can run a test suite and get a feel for what this default outputs. The view has a few options you can tweak:
440
440
 
441
- * `styled`: whether to apply ANSI styles to the output, default `true`
441
+ * `styled`: whether to apply ansi styles to the output, default `true`
442
442
  * `pass_styles`: how to style pass result output, default `:green`
443
443
  * `fail_styles`: default `:red, :bold`
444
444
  * `error_styles`: default `:yellow, :bold`
@@ -534,7 +534,7 @@ Tests produce results as they are executed. Every `assert` statement produces a
534
534
 
535
535
  ### View
536
536
 
537
- A `View` object is responsible for rendering test result output. Assert provides a `Assert::View::Base` object to provide common helpers and default runner callback handlers for building views. Assert also provides a `Assert::View::DefaultView` that it renders its output with. See the "Viewing Test Results" section below for more details.
537
+ A `View` object is responsible for rendering test result output. Assert provides a `Assert::View::Base` object to provide common helpers and default runner callback handlers for building views. Assert also provides an `Assert::DefaultView` that it renders its output with. See the "Viewing Test Results" section below for more details.
538
538
 
539
539
  ### Macro
540
540
 
@@ -18,6 +18,4 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency("ansi", ["~> 1.3"])
22
-
23
21
  end
@@ -45,7 +45,7 @@ module Assert
45
45
  end
46
46
 
47
47
  def run
48
- self.config.runner.run(self.config.suite, self.config.view)
48
+ self.config.runner.run
49
49
  end
50
50
 
51
51
  private
@@ -294,7 +294,7 @@ module Assert
294
294
  end
295
295
  end
296
296
 
297
- def exception_details(raised_msg=nil, no_raised_msg=nil)
297
+ def exception_details(raised_msg = nil, no_raised_msg = nil)
298
298
  if @exception
299
299
  backtrace = Assert::Result::Backtrace.new(@exception.backtrace)
300
300
  [ raised_msg,
@@ -1,3 +1,8 @@
1
+ require 'assert/default_view'
2
+ require 'assert/runner'
3
+ require 'assert/suite'
4
+ require 'assert/utils'
5
+
1
6
  module Assert
2
7
 
3
8
  class Config
@@ -21,7 +26,7 @@ module Assert
21
26
 
22
27
  def initialize(settings = nil)
23
28
  @suite = Assert::Suite.new(self)
24
- @view = Assert::View::DefaultView.new($stdout, self, @suite)
29
+ @view = Assert::DefaultView.new(self, $stdout)
25
30
  @runner = Assert::Runner.new(self)
26
31
 
27
32
  @test_dir = "test"
@@ -0,0 +1,75 @@
1
+ module Assert
2
+
3
+ module ConfigHelpers
4
+
5
+ def runner_seed
6
+ self.config.runner_seed
7
+ end
8
+
9
+ def count(type)
10
+ self.config.suite.count(type)
11
+ end
12
+
13
+ def tests?
14
+ self.count(:tests) > 0
15
+ end
16
+
17
+ def all_pass?
18
+ self.count(:pass) == self.count(:results)
19
+ end
20
+
21
+ # get the formatted suite run time
22
+ def run_time(format = '%.6f')
23
+ format % self.config.suite.run_time
24
+ end
25
+
26
+ # get the formatted suite test rate
27
+ def test_rate(format = '%.6f')
28
+ format % self.config.suite.test_rate
29
+ end
30
+
31
+ # get the formatted suite result rate
32
+ def result_rate(format = '%.6f')
33
+ format % self.config.suite.result_rate
34
+ end
35
+
36
+ # get a uniq list of contexts for the test suite
37
+ def suite_contexts
38
+ @suite_contexts ||= self.config.suite.tests.inject([]) do |contexts, test|
39
+ contexts << test.context_info.klass
40
+ end.uniq
41
+ end
42
+
43
+ def ordered_suite_contexts
44
+ self.suite_contexts.sort{ |a,b| a.to_s <=> b.to_s }
45
+ end
46
+
47
+ # get a uniq list of files containing contexts for the test suite
48
+ def suite_files
49
+ @suite_files ||= self.config.suite.tests.inject([]) do |files, test|
50
+ files << test.context_info.file
51
+ end.uniq
52
+ end
53
+
54
+ def ordered_suite_files
55
+ self.suite_files.sort{ |a,b| a.to_s <=> b.to_s }
56
+ end
57
+
58
+ def show_test_profile_info?
59
+ !!self.config.profile
60
+ end
61
+
62
+ def show_test_verbose_info?
63
+ !!self.config.verbose
64
+ end
65
+
66
+ # return a list of result symbols that have actually occurred
67
+ def ocurring_result_types
68
+ @result_types ||= [:pass, :fail, :ignore, :skip, :error].select do |sym|
69
+ self.count(sym) > 0
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -33,19 +33,23 @@ module Assert
33
33
 
34
34
  if self.suite.test_methods.include?(klass_method_name)
35
35
  puts "WARNING: redefining '#{klass_method_name}'"
36
- puts " from: #{called_from}"
36
+ puts " from: #{caller.first}"
37
37
  else
38
38
  self.suite.test_methods << klass_method_name
39
39
  end
40
40
 
41
- ci = Suite::ContextInfo.new(self, nil, caller.first)
42
- test = Test.new(method_name.to_s, ci, self.suite.config, :code => method_name)
43
- self.suite.tests << test
41
+ self.suite.tests << Test.for_method(
42
+ method_name.to_s,
43
+ Suite::ContextInfo.new(self, nil, caller.first),
44
+ self.suite.config
45
+ )
44
46
  end
45
47
  end
46
48
 
47
- def initialize(running_test, config)
48
- @__running_test__, @__assert_config__ = running_test, config
49
+ def initialize(running_test, config, result_callback)
50
+ @__running_test__ = running_test
51
+ @__assert_config__ = config
52
+ @__result_callback__ = result_callback
49
53
  end
50
54
 
51
55
  # check if the assertion is a truthy value, if so create a new pass result, otherwise
@@ -75,17 +79,17 @@ module Assert
75
79
 
76
80
  # adds a Pass result to the end of the test's results
77
81
  # does not break test execution
78
- def pass(pass_msg=nil)
82
+ def pass(pass_msg = nil)
79
83
  capture_result do |test, backtrace|
80
- Assert::Result::Pass.new(test, pass_msg, backtrace)
84
+ Assert::Result::Pass.for_test(test, pass_msg, backtrace)
81
85
  end
82
86
  end
83
87
 
84
88
  # adds an Ignore result to the end of the test's results
85
89
  # does not break test execution
86
- def ignore(ignore_msg=nil)
90
+ def ignore(ignore_msg = nil)
87
91
  capture_result do |test, backtrace|
88
- Assert::Result::Ignore.new(test, ignore_msg, backtrace)
92
+ Assert::Result::Ignore.for_test(test, ignore_msg, backtrace)
89
93
  end
90
94
  end
91
95
 
@@ -96,15 +100,17 @@ module Assert
96
100
  raise Result::TestFailure, message || ''
97
101
  else
98
102
  capture_result do |test, backtrace|
99
- Assert::Result::Fail.new(test, message || '', backtrace)
103
+ Assert::Result::Fail.for_test(test, message || '', backtrace)
100
104
  end
101
105
  end
102
106
  end
103
107
  alias_method :flunk, :fail
104
108
 
105
109
  # adds a Skip result to the end of the test's results and breaks test execution
106
- def skip(skip_msg=nil)
107
- raise(Result::TestSkipped, skip_msg || '')
110
+ def skip(skip_msg = nil, called_from = nil)
111
+ err = Result::TestSkipped.new(skip_msg || '')
112
+ err.set_backtrace([called_from]) if called_from
113
+ raise(err)
108
114
  end
109
115
 
110
116
  # alter the backtraces of fail results generated in the given block
@@ -147,7 +153,7 @@ module Assert
147
153
  def capture_result
148
154
  if block_given?
149
155
  result = yield __running_test__, caller
150
- __running_test__.results << result
156
+ __running_test__.capture_result(result, @__result_callback__)
151
157
  result
152
158
  end
153
159
  end
@@ -7,38 +7,42 @@ class Assert::Context
7
7
 
8
8
  module TestDSL
9
9
 
10
- def test(desc_or_macro, called_from=nil, first_caller=nil, &block)
10
+ def test(desc_or_macro, called_from = nil, first_caller = nil, &block)
11
11
  if desc_or_macro.kind_of?(Assert::Macro)
12
12
  instance_eval(&desc_or_macro)
13
13
  elsif block_given?
14
- ci = Assert::Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
15
- test_name = desc_or_macro
16
-
17
14
  # create a test from the given code block
18
- self.suite.tests << Assert::Test.new(test_name, ci, self.suite.config, &block)
15
+ self.suite.tests << Assert::Test.for_block(
16
+ desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
17
+ Assert::Suite::ContextInfo.new(self, called_from, first_caller || caller.first),
18
+ self.suite.config,
19
+ &block
20
+ )
19
21
  else
20
22
  test_eventually(desc_or_macro, called_from, first_caller || caller.first, &block)
21
23
  end
22
24
  end
23
25
 
24
- def test_eventually(desc_or_macro, called_from=nil, first_caller=nil, &block)
25
- ci = Assert::Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
26
- test_name = desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro
27
- skip_block = block.nil? ? Proc.new { skip 'TODO' } : Proc.new { skip }
28
-
26
+ def test_eventually(desc_or_macro, called_from = nil, first_caller = nil, &block)
29
27
  # create a test from a proc that just skips
30
- self.suite.tests << Assert::Test.new(test_name, ci, self.suite.config, &skip_block)
28
+ ci = Assert::Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
29
+ self.suite.tests << Assert::Test.for_block(
30
+ desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
31
+ ci,
32
+ self.suite.config,
33
+ &proc { skip('TODO', ci.called_from) }
34
+ )
31
35
  end
32
36
  alias_method :test_skip, :test_eventually
33
37
 
34
- def should(desc_or_macro, called_from=nil, first_caller=nil, &block)
38
+ def should(desc_or_macro, called_from = nil, first_caller = nil, &block)
35
39
  if !desc_or_macro.kind_of?(Assert::Macro)
36
40
  desc_or_macro = "should #{desc_or_macro}"
37
41
  end
38
42
  test(desc_or_macro, called_from, first_caller || caller.first, &block)
39
43
  end
40
44
 
41
- def should_eventually(desc_or_macro, called_from=nil, first_caller=nil, &block)
45
+ def should_eventually(desc_or_macro, called_from = nil, first_caller = nil, &block)
42
46
  if !desc_or_macro.kind_of?(Assert::Macro)
43
47
  desc_or_macro = "should #{desc_or_macro}"
44
48
  end
@@ -1,13 +1,11 @@
1
- require 'assert/view/base'
1
+ require 'assert/view'
2
2
 
3
- module Assert::View
3
+ module Assert
4
4
 
5
5
  # This is the default view used by assert. It renders ansi test output
6
6
  # designed for terminal viewing.
7
7
 
8
- class DefaultView < Base
9
- require 'assert/view/helpers/ansi_styles'
10
- include Helpers::AnsiStyles
8
+ class DefaultView < Assert::View::Base
11
9
 
12
10
  # setup options and their default values
13
11
 
@@ -26,9 +24,6 @@ module Assert::View
26
24
  end
27
25
 
28
26
  def on_start
29
- if tests?
30
- puts "Running tests in random order, seeded with \"#{runner_seed}\""
31
- end
32
27
  end
33
28
 
34
29
  def before_test(test)
@@ -40,10 +35,7 @@ module Assert::View
40
35
  end
41
36
 
42
37
  def on_result(result)
43
- result_abbrev = self.send("#{result.to_sym}_abbrev")
44
- styled_abbrev = ansi_styled_msg(result_abbrev, result_ansi_styles(result))
45
-
46
- print styled_abbrev
38
+ print ansi_styled_msg(self.send("#{result.to_sym}_abbrev"), result)
47
39
  end
48
40
 
49
41
  def after_test(test)
@@ -61,7 +53,7 @@ module Assert::View
61
53
 
62
54
  # show profile output
63
55
  if show_test_profile_info?
64
- ordered_profile_tests.each do |test|
56
+ config.suite.ordered_tests_by_run_time.each do |test|
65
57
  puts "#{test_run_time(test)} seconds,"\
66
58
  " #{test.result_count} results,"\
67
59
  " #{test_result_rate(test)} results/s --"\
@@ -71,8 +63,8 @@ module Assert::View
71
63
  end
72
64
 
73
65
  # style the summaries of each result set
74
- styled_results_sentence = results_summary_sentence do |summary, sym|
75
- ansi_styled_msg(summary, result_ansi_styles(sym))
66
+ styled_results_sentence = results_summary_sentence do |summary, result_sym|
67
+ ansi_styled_msg(summary, result_sym)
76
68
  end
77
69
 
78
70
  puts "#{result_count_statement}: #{styled_results_sentence}"
@@ -91,12 +83,12 @@ module Assert::View
91
83
  puts
92
84
 
93
85
  # output detailed results for the tests in reverse test/result order
94
- tests = suite.ordered_tests.reverse
86
+ tests = config.suite.ordered_tests.reverse
95
87
  result_details_for(tests, :reversed).each do |details|
96
88
  if show_result_details?(details.result)
97
89
  # output the styled result details
98
90
  result = details.result
99
- puts ansi_styled_msg(result.to_s, result_ansi_styles(result))
91
+ puts ansi_styled_msg(result.to_s, result)
100
92
 
101
93
  # output any captured stdout
102
94
  output = details.output
@@ -33,7 +33,7 @@ module Assert
33
33
  end
34
34
 
35
35
  def string(length = nil)
36
- self.type_cast(Random.string(length), :string)
36
+ self.type_cast(Random.string(length || 10), :string)
37
37
  end
38
38
 
39
39
  def text(length = nil)
@@ -41,7 +41,7 @@ module Assert
41
41
  end
42
42
 
43
43
  def slug(length = nil)
44
- self.type_cast(Random.slug_string(length), :string)
44
+ self.type_cast(Random.string(length || 5), :string)
45
45
  end
46
46
 
47
47
  def hex(length = nil)
@@ -122,11 +122,6 @@ module Assert
122
122
  [*0..((length || 10) - 1)].map{ |n| DICTIONARY[rand(DICTIONARY.size)] }.join
123
123
  end
124
124
 
125
- def self.slug_string(length = nil)
126
- length ||= 8
127
- self.string(length).scan(/.{1,4}/).join('-')
128
- end
129
-
130
125
  def self.hex_string(length = nil)
131
126
  length ||= 10
132
127
  self.integer(("f" * length).hex - 1).to_s(16).rjust(length, '0')
@@ -3,12 +3,12 @@ module Assert
3
3
  class FileLine
4
4
 
5
5
  def self.parse(file_line_path)
6
- self.new(*file_line_path.match(/(.+)\:(.+)/)[1..2])
6
+ self.new(*(file_line_path.to_s.match(/(.+)\:(.+)/) || [])[1..2])
7
7
  end
8
8
 
9
9
  attr_reader :file, :line
10
10
 
11
- def initialize(file, line)
11
+ def initialize(file = nil, line = nil)
12
12
  @file, @line = file.to_s, line.to_s
13
13
  end
14
14
 
@@ -17,7 +17,11 @@ module Assert
17
17
  end
18
18
 
19
19
  def ==(other_file_line)
20
- self.file == other_file_line.file && self.line == other_file_line.line
20
+ if other_file_line.kind_of?(FileLine)
21
+ self.file == other_file_line.file && self.line == other_file_line.line
22
+ else
23
+ super
24
+ end
21
25
  end
22
26
 
23
27
  end
@@ -7,7 +7,7 @@ module Assert
7
7
 
8
8
  attr_accessor :name
9
9
 
10
- def initialize(name=nil, *args, &block)
10
+ def initialize(name = nil, *args, &block)
11
11
  raise ArgumentError unless block_given?
12
12
  @name = name || "run this macro"
13
13
  super()
@@ -100,7 +100,7 @@ module Assert::Macros
100
100
  # private
101
101
 
102
102
  def _methods_macro_test(called_from)
103
- @_methods_macro_test ||= should "respond to methods", called_from do
103
+ @_methods_macro_test ||= test "should respond to methods", called_from do
104
104
 
105
105
  self.class._methods_macro_instance_methods.each do |(method, called_from)|
106
106
  msg = "#{subject.class.name} does not have instance method ##{method}"