assert 2.18.4 → 2.19.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/assert.gemspec +11 -5
  4. data/bin/assert +1 -0
  5. data/lib/assert.rb +20 -6
  6. data/lib/assert/actual_value.rb +26 -8
  7. data/lib/assert/assert_runner.rb +38 -17
  8. data/lib/assert/assertions.rb +145 -41
  9. data/lib/assert/cli.rb +19 -66
  10. data/lib/assert/clirb.rb +55 -0
  11. data/lib/assert/config.rb +22 -8
  12. data/lib/assert/config_helpers.rb +57 -22
  13. data/lib/assert/context.rb +28 -47
  14. data/lib/assert/context/let_dsl.rb +8 -2
  15. data/lib/assert/context/method_missing.rb +3 -0
  16. data/lib/assert/context/setup_dsl.rb +24 -16
  17. data/lib/assert/context/subject_dsl.rb +9 -7
  18. data/lib/assert/context/suite_dsl.rb +5 -1
  19. data/lib/assert/context/test_dsl.rb +58 -19
  20. data/lib/assert/context_info.rb +2 -0
  21. data/lib/assert/default_runner.rb +2 -0
  22. data/lib/assert/default_suite.rb +27 -15
  23. data/lib/assert/default_view.rb +49 -30
  24. data/lib/assert/factory.rb +2 -0
  25. data/lib/assert/file_line.rb +8 -6
  26. data/lib/assert/macro.rb +3 -1
  27. data/lib/assert/macros/methods.rb +73 -45
  28. data/lib/assert/result.rb +117 -61
  29. data/lib/assert/runner.rb +70 -51
  30. data/lib/assert/stub.rb +44 -3
  31. data/lib/assert/suite.rb +76 -38
  32. data/lib/assert/test.rb +43 -44
  33. data/lib/assert/utils.rb +22 -11
  34. data/lib/assert/version.rb +3 -1
  35. data/lib/assert/view.rb +46 -18
  36. data/lib/assert/view_helpers.rb +102 -92
  37. data/test/helper.rb +8 -4
  38. data/test/support/factory.rb +40 -21
  39. data/test/support/inherited_stuff.rb +2 -0
  40. data/test/system/stub_tests.rb +182 -144
  41. data/test/system/test_tests.rb +88 -60
  42. data/test/unit/actual_value_tests.rb +103 -46
  43. data/test/unit/assert_tests.rb +48 -40
  44. data/test/unit/assertions/assert_block_tests.rb +12 -10
  45. data/test/unit/assertions/assert_changes_tests.rb +103 -0
  46. data/test/unit/assertions/assert_empty_tests.rb +16 -12
  47. data/test/unit/assertions/assert_equal_tests.rb +46 -24
  48. data/test/unit/assertions/assert_file_exists_tests.rb +17 -13
  49. data/test/unit/assertions/assert_includes_tests.rb +12 -10
  50. data/test/unit/assertions/assert_instance_of_tests.rb +16 -14
  51. data/test/unit/assertions/assert_is_a_tests.rb +128 -0
  52. data/test/unit/assertions/assert_match_tests.rb +12 -10
  53. data/test/unit/assertions/assert_nil_tests.rb +18 -12
  54. data/test/unit/assertions/assert_raises_tests.rb +34 -23
  55. data/test/unit/assertions/assert_respond_to_tests.rb +12 -10
  56. data/test/unit/assertions/assert_same_tests.rb +26 -24
  57. data/test/unit/assertions/assert_true_false_tests.rb +34 -24
  58. data/test/unit/assertions_tests.rb +25 -17
  59. data/test/unit/config_helpers_tests.rb +15 -8
  60. data/test/unit/config_tests.rb +36 -9
  61. data/test/unit/context/let_dsl_tests.rb +2 -0
  62. data/test/unit/context/setup_dsl_tests.rb +26 -14
  63. data/test/unit/context/subject_dsl_tests.rb +5 -3
  64. data/test/unit/context/suite_dsl_tests.rb +6 -4
  65. data/test/unit/context/test_dsl_tests.rb +43 -19
  66. data/test/unit/context_info_tests.rb +6 -4
  67. data/test/unit/context_tests.rb +112 -54
  68. data/test/unit/default_runner_tests.rb +2 -0
  69. data/test/unit/default_suite_tests.rb +12 -6
  70. data/test/unit/factory_tests.rb +4 -2
  71. data/test/unit/file_line_tests.rb +9 -7
  72. data/test/unit/macro_tests.rb +13 -11
  73. data/test/unit/result_tests.rb +49 -41
  74. data/test/unit/runner_tests.rb +33 -18
  75. data/test/unit/suite_tests.rb +42 -24
  76. data/test/unit/test_tests.rb +66 -73
  77. data/test/unit/utils_tests.rb +52 -37
  78. data/test/unit/view_helpers_tests.rb +23 -14
  79. data/test/unit/view_tests.rb +7 -5
  80. metadata +40 -9
  81. data/test/unit/assertions/assert_kind_of_tests.rb +0 -66
@@ -1,10 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert; end
2
4
  class Assert::Context; end
5
+
3
6
  module Assert::Context::LetDSL
4
7
  def let(name, &block)
5
- self.send(:define_method, name, &-> {
8
+ send(:define_method, name, &->{
6
9
  unless instance_variable_defined?("@__assert_let_#{name}__")
7
- instance_variable_set("@__assert_let_#{name}__", instance_eval(&block))
10
+ instance_variable_set(
11
+ "@__assert_let_#{name}__",
12
+ instance_eval(&block),
13
+ )
8
14
  end
9
15
 
10
16
  instance_variable_get("@__assert_let_#{name}__")
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/assertions"
2
4
 
3
5
  module Assert; end
4
6
  class Assert::Context; end
7
+
5
8
  module Assert::Context::MethodMissing
6
9
  def method_missing(method, *args, &block)
7
10
  if Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
@@ -1,29 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert; end
4
+
2
5
  class Assert::Context
3
6
  module SetupDSL
4
7
  def setup_once(&block)
5
- self.suite.setup(&block)
8
+ suite.setup(&block)
6
9
  end
7
10
  alias_method :before_once, :setup_once
8
11
  alias_method :startup, :setup_once
9
12
 
10
13
  def teardown_once(&block)
11
- self.suite.teardown(&block)
14
+ suite.teardown(&block)
12
15
  end
13
16
  alias_method :after_once, :teardown_once
14
17
  alias_method :shutdown, :teardown_once
15
18
 
16
19
  def around(&block)
17
- self.arounds << block
20
+ arounds << block
18
21
  end
19
22
 
20
23
  def setup(method_name = nil, &block)
21
- self.setups << (block || method_name)
24
+ setups << (block || method_name)
22
25
  end
23
26
  alias_method :before, :setup
24
27
 
25
28
  def teardown(method_name = nil, &block)
26
- self.teardowns << (block || method_name)
29
+ teardowns << (block || method_name)
27
30
  end
28
31
  alias_method :after, :teardown
29
32
 
@@ -40,12 +43,13 @@ class Assert::Context
40
43
  end
41
44
 
42
45
  def run_arounds(scope, &run_block)
43
- context_block = self.arounds.compact.reverse.inject(run_block) do |run_b, around_b|
44
- Proc.new{ scope.instance_exec(run_b, &around_b) }
45
- end
46
+ context_block =
47
+ arounds.compact.reverse.inject(run_block) do |run_b, around_b|
48
+ Proc.new{ scope.instance_exec(run_b, &around_b) }
49
+ end
46
50
 
47
- if self.superclass.respond_to?(:run_arounds)
48
- self.superclass.run_arounds(scope, &context_block)
51
+ if superclass.respond_to?(:run_arounds)
52
+ superclass.run_arounds(scope, &context_block)
49
53
  else
50
54
  context_block.call
51
55
  end
@@ -53,20 +57,24 @@ class Assert::Context
53
57
 
54
58
  def run_setups(scope)
55
59
  # setup the parent...
56
- self.superclass.run_setups(scope) if self.superclass.respond_to?(:run_setups)
60
+ superclass.run_setups(scope) if superclass.respond_to?(:run_setups)
57
61
  # ... before you setup the child
58
- self.setups.compact.each do |setup|
59
- setup.kind_of?(::Proc) ? scope.instance_eval(&setup) : scope.send(setup)
62
+ setups.compact.each do |setup|
63
+ setup.is_a?(::Proc) ? scope.instance_eval(&setup) : scope.send(setup)
60
64
  end
61
65
  end
62
66
 
63
67
  def run_teardowns(scope)
64
68
  # teardown the child...
65
- self.teardowns.compact.each do |teardown|
66
- teardown.kind_of?(::Proc) ? scope.instance_eval(&teardown) : scope.send(teardown)
69
+ teardowns.compact.each do |teardown|
70
+ if teardown.is_a?(::Proc)
71
+ scope.instance_eval(&teardown)
72
+ else
73
+ scope.send(teardown)
74
+ end
67
75
  end
68
76
  # ... before the parent
69
- self.superclass.run_teardowns(scope) if self.superclass.respond_to?(:run_teardowns)
77
+ superclass.run_teardowns(scope) if superclass.respond_to?(:run_teardowns)
70
78
  end
71
79
  end
72
80
  end
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert; end
2
4
  class Assert::Context; end
5
+
3
6
  module Assert::Context::SubjectDSL
4
- # Add a piece of description text or return the full description for the context
7
+ # Add a piece of description text or return the full description
8
+ # for the context.
5
9
  def description(text = nil)
6
10
  if text
7
- self.descriptions << text.to_s
11
+ descriptions << text.to_s
8
12
  else
9
- parent = self.superclass.desc if self.superclass.respond_to?(:desc)
10
- own = self.descriptions
13
+ parent = superclass.desc if superclass.respond_to?(:desc)
14
+ own = descriptions
11
15
  [parent, *own].compact.reject(&:empty?).join(" ")
12
16
  end
13
17
  end
@@ -18,9 +22,7 @@ module Assert::Context::SubjectDSL
18
22
  if block_given?
19
23
  @subject = block
20
24
  else
21
- @subject || if superclass.respond_to?(:subject)
22
- superclass.subject
23
- end
25
+ @subject || (superclass.subject if superclass.respond_to?(:subject))
24
26
  end
25
27
  end
26
28
 
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert; end
4
+
2
5
  class Assert::Context
3
6
  module SuiteDSL
4
7
  def suite(suite_obj = nil)
5
8
  if suite_obj
6
9
  @suite = suite_obj
7
10
  else
8
- @suite || if superclass.respond_to?(:suite)
11
+ @suite ||
12
+ if superclass.respond_to?(:suite)
9
13
  superclass.suite
10
14
  else
11
15
  Assert.suite
@@ -1,51 +1,90 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/context_info"
2
4
  require "assert/macro"
3
5
  require "assert/suite"
4
6
  require "assert/test"
5
7
 
6
8
  module Assert; end
9
+
7
10
  class Assert::Context
8
11
  module TestDSL
9
12
  def test(desc_or_macro, called_from = nil, first_caller = nil, &block)
10
- if desc_or_macro.kind_of?(Assert::Macro)
13
+ if desc_or_macro.is_a?(Assert::Macro)
11
14
  instance_eval(&desc_or_macro)
12
15
  elsif block_given?
13
16
  # create a test from the given code block
14
- self.suite.on_test(Assert::Test.for_block(
15
- desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
16
- Assert::ContextInfo.new(self, called_from, first_caller || caller_locations.first),
17
- self.suite.config,
18
- &block
19
- ))
17
+ desc =
18
+ if desc_or_macro.is_a?(Assert::Macro)
19
+ desc_or_macro.name
20
+ else
21
+ desc_or_macro
22
+ end
23
+ suite.on_test(
24
+ Assert::Test.for_block(
25
+ desc,
26
+ Assert::ContextInfo.new(
27
+ self,
28
+ called_from,
29
+ first_caller || caller_locations.first,
30
+ ),
31
+ suite.config,
32
+ &block
33
+ ),
34
+ )
20
35
  else
21
- test_eventually(desc_or_macro, called_from, first_caller || caller_locations.first, &block)
36
+ test_eventually(
37
+ desc_or_macro,
38
+ called_from,
39
+ first_caller || caller_locations.first,
40
+ &block
41
+ )
22
42
  end
23
43
  end
24
44
 
25
- def test_eventually(desc_or_macro, called_from = nil, first_caller = nil, &block)
45
+ def test_eventually(desc_or_macro, called_from = nil, first_caller = nil)
26
46
  # create a test from a proc that just skips
27
- ci = Assert::ContextInfo.new(self, called_from, first_caller || caller_locations.first)
28
- self.suite.on_test(Assert::Test.for_block(
29
- desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
47
+ ci =
48
+ Assert::ContextInfo.new(
49
+ self,
50
+ called_from,
51
+ first_caller || caller_locations.first,
52
+ )
53
+ suite.on_test(Assert::Test.for_block(
54
+ desc_or_macro.is_a?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
30
55
  ci,
31
- self.suite.config,
32
- &proc { skip("TODO", [ci.called_from.to_s]) }
56
+ suite.config,
57
+ &proc{ skip("TODO", [ci.called_from.to_s]) }
33
58
  ))
34
59
  end
35
60
  alias_method :test_skip, :test_eventually
36
61
 
37
62
  def should(desc_or_macro, called_from = nil, first_caller = nil, &block)
38
- if !desc_or_macro.kind_of?(Assert::Macro)
63
+ unless desc_or_macro.is_a?(Assert::Macro)
39
64
  desc_or_macro = "should #{desc_or_macro}"
40
65
  end
41
- test(desc_or_macro, called_from, first_caller || caller_locations.first, &block)
66
+ test(
67
+ desc_or_macro,
68
+ called_from,
69
+ first_caller || caller_locations.first,
70
+ &block
71
+ )
42
72
  end
43
73
 
44
- def should_eventually(desc_or_macro, called_from = nil, first_caller = nil, &block)
45
- if !desc_or_macro.kind_of?(Assert::Macro)
74
+ def should_eventually(
75
+ desc_or_macro,
76
+ called_from = nil,
77
+ first_caller = nil,
78
+ &block)
79
+ unless desc_or_macro.is_a?(Assert::Macro)
46
80
  desc_or_macro = "should #{desc_or_macro}"
47
81
  end
48
- test_eventually(desc_or_macro, called_from, first_caller || caller_locations.first, &block)
82
+ test_eventually(
83
+ desc_or_macro,
84
+ called_from,
85
+ first_caller || caller_locations.first,
86
+ &block
87
+ )
49
88
  end
50
89
  alias_method :should_skip, :should_eventually
51
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert
2
4
  class ContextInfo
3
5
  attr_reader :called_from, :klass, :file
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/runner"
2
4
 
3
5
  module Assert
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/suite"
2
4
 
3
5
  module Assert
@@ -5,41 +7,51 @@ module Assert
5
7
  # behavior, it accumulates test/result counts in memory. This data is used
6
8
  # by the runner/view for handling and presentation purposes.
7
9
  class DefaultSuite < Assert::Suite
10
+ attr_reader :test_count, :result_count, :pass_result_count
11
+ attr_reader :fail_result_count, :error_result_count
12
+ attr_reader :skip_result_count, :ignore_result_count
13
+
8
14
  def initialize(config)
9
15
  super
10
16
  reset_run_data
11
17
  end
12
18
 
13
- def test_count; @test_count; end
14
- def result_count; @result_count; end
15
- def pass_result_count; @pass_result_count; end
16
- def fail_result_count; @fail_result_count; end
17
- def error_result_count; @error_result_count; end
18
- def skip_result_count; @skip_result_count; end
19
- def ignore_result_count; @ignore_result_count; end
20
-
21
19
  # Callbacks
22
20
 
23
21
  def on_start
24
22
  reset_run_data
25
23
  end
26
24
 
27
- def before_test(test)
25
+ def before_test(_test)
28
26
  @test_count += 1
29
27
  end
30
28
 
31
29
  def on_result(result)
32
30
  @result_count += 1
33
- self.send("increment_#{result.type}_result_count")
31
+ send("increment_#{result.type}_result_count")
34
32
  end
35
33
 
36
34
  private
37
35
 
38
- def increment_pass_result_count; @pass_result_count += 1; end
39
- def increment_fail_result_count; @fail_result_count += 1; end
40
- def increment_error_result_count; @error_result_count += 1; end
41
- def increment_skip_result_count; @skip_result_count += 1; end
42
- def increment_ignore_result_count; @ignore_result_count += 1; end
36
+ def increment_pass_result_count
37
+ @pass_result_count += 1
38
+ end
39
+
40
+ def increment_fail_result_count
41
+ @fail_result_count += 1
42
+ end
43
+
44
+ def increment_error_result_count
45
+ @error_result_count += 1
46
+ end
47
+
48
+ def increment_skip_result_count
49
+ @skip_result_count += 1
50
+ end
51
+
52
+ def increment_ignore_result_count
53
+ @ignore_result_count += 1
54
+ end
43
55
 
44
56
  def reset_run_data
45
57
  @test_count = 0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/view"
2
4
  require "assert/view_helpers"
3
5
 
@@ -29,26 +31,28 @@ module Assert
29
31
  end
30
32
 
31
33
  def on_finish
32
- if self.test_count > 0
33
- dump_test_results
34
- end
34
+ dump_test_results if test_count > 0
35
35
 
36
36
  # show profile output
37
37
  if show_test_profile_info?
38
38
  # sort the test datas fastest to slowest
39
- @test_datas.values.sort{ |a, b| a.run_time <=> b.run_time }.each do |test_data|
40
- puts "#{formatted_run_time(test_data.run_time)} seconds,"\
41
- " #{test_data.result_count} results,"\
42
- " #{formatted_result_rate(test_data.result_rate)} results/s --"\
43
- " #{test_data.context}: #{test_data.name.inspect}"
44
- end
39
+ @test_datas
40
+ .values
41
+ .sort{ |a, b| a.run_time <=> b.run_time }
42
+ .each do |test_data|
43
+ puts "#{formatted_run_time(test_data.run_time)} seconds,"\
44
+ " #{test_data.result_count} results,"\
45
+ " #{formatted_result_rate(test_data.result_rate)} results/s "\
46
+ "-- #{test_data.context}: #{test_data.name.inspect}"
47
+ end
45
48
  puts
46
49
  end
47
50
 
48
51
  # style the summaries of each result set
49
- styled_results_sentence = results_summary_sentence do |summary, result_type|
50
- ansi_styled_msg(summary, result_type)
51
- end
52
+ styled_results_sentence =
53
+ results_summary_sentence do |summary, result_type|
54
+ ansi_styled_msg(summary, result_type)
55
+ end
52
56
 
53
57
  puts "#{result_count_statement}: #{styled_results_sentence}"
54
58
  puts
@@ -66,7 +70,7 @@ module Assert
66
70
  puts
67
71
  end
68
72
 
69
- def on_interrupt(err)
73
+ def on_interrupt(_err)
70
74
  dump_test_results
71
75
  end
72
76
 
@@ -80,7 +84,7 @@ module Assert
80
84
  def set_callbacks
81
85
  @metaclass = class << self; self; end
82
86
  if accumulate_test_data?
83
- @metaclass.class_eval <<-callbacks
87
+ @metaclass.class_eval <<-RUBY
84
88
  def before_test(test)
85
89
  test_data = get_test_data(test)
86
90
  puts "\#{test_data.name.inspect} (\#{test_data.context})"
@@ -89,32 +93,46 @@ module Assert
89
93
  end
90
94
 
91
95
  def on_result(result)
92
- print ansi_styled_msg(self.send("\#{result.to_sym}_abbrev"), result.type)
93
- @results_to_dump << ResultData.for_result(result) if dumpable_result?(result)
96
+ print(
97
+ ansi_styled_msg(
98
+ self.send("\#{result.to_sym}_abbrev"),
99
+ result.type,
100
+ )
101
+ )
102
+ @results_to_dump <<
103
+ ResultData.for_result(result) if dumpable_result?(result)
94
104
  find_test_data(result.test_file_line).result_count += 1
95
105
  end
96
106
 
97
107
  def after_test(test)
98
108
  test_data = find_test_data(test.file_line)
99
- test_data.run_time = test.run_time
100
- test_data.result_rate = get_rate(test_data.result_count, test_data.run_time)
109
+ test_data.run_time = test.run_time
110
+ test_data.result_rate =
111
+ get_rate(test_data.result_count, test_data.run_time)
101
112
 
102
113
  if show_test_verbose_info?
103
114
  print " \#{formatted_run_time(test_data.run_time)} seconds,"\
104
115
  " \#{test_data.result_count} results,"\
105
- " \#{formatted_result_rate(test_data.result_rate)} results/s\n"
116
+ " \#{formatted_result_rate(test_data.result_rate)} "\
117
+ "results/s\n"
106
118
  else
107
119
  print "\n"
108
120
  end
109
121
  end
110
- callbacks
122
+ RUBY
111
123
  else
112
- @metaclass.class_eval <<-callbacks
124
+ @metaclass.class_eval <<-RUBY
113
125
  def on_result(result)
114
- print ansi_styled_msg(self.send("\#{result.to_sym}_abbrev"), result.type)
115
- @results_to_dump << ResultData.for_result(result) if dumpable_result?(result)
126
+ print(
127
+ ansi_styled_msg(
128
+ self.send("\#{result.to_sym}_abbrev"),
129
+ result.type
130
+ )
131
+ )
132
+ @results_to_dump <<
133
+ ResultData.for_result(result) if dumpable_result?(result)
116
134
  end
117
- callbacks
135
+ RUBY
118
136
  end
119
137
  end
120
138
 
@@ -156,27 +174,28 @@ module Assert
156
174
  end
157
175
  end
158
176
 
159
- attrs = [:name, :context, :file_line, :result_count, :run_time, :result_rate]
177
+ attrs =
178
+ [:name, :context, :file_line, :result_count, :run_time, :result_rate]
160
179
  class TestData < Struct.new(*attrs)
161
180
  def self.for_test(t)
162
- self.new(t.name, t.context_class, t.file_line.to_s, 0, 0.0, 0.0)
181
+ new(t.name, t.context_class, t.file_line.to_s, 0, 0.0, 0.0)
163
182
  end
164
183
  end
165
184
 
166
185
  attrs = [:type, :details, :output, :test_id, :sort_by]
167
186
  class ResultData < Struct.new(*attrs)
168
187
  def self.for_result(r)
169
- self.new(r.type, r.to_s, r.output, r.test_id, self.sort_by(r))
188
+ new(r.type, r.to_s, r.output, r.test_id, sort_by(r))
170
189
  end
171
190
 
172
191
  def self.sort_by(r)
173
192
  [r.test_file_name, r.test_line_num, r.file_name, r.line_num]
174
193
  end
175
194
 
176
- def <=>(other_rd)
195
+ def <=>(other)
177
196
  # show in reverse definition order
178
- if other_rd.kind_of?(ResultData)
179
- other_rd.sort_by <=> self.sort_by
197
+ if other.is_a?(ResultData)
198
+ other.sort_by <=> sort_by
180
199
  else
181
200
  super
182
201
  end