assert 2.19.1 → 2.19.6

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