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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
 
3
5
  module Assert
@@ -10,18 +12,21 @@ module Assert
10
12
  out
11
13
  end
12
14
 
13
- # show objects in a human-readable manner and make the output diff-able. This
14
- # expands on the basic `show` util by escaping newlines and making object id
15
- # hex-values generic.
15
+ # show objects in a human-readable manner and make the output diff-able.
16
+ # This expands on the basic `show` util by escaping newlines and making
17
+ # object id hex-values generic.
16
18
  def self.show_for_diff(obj, config)
17
- show(obj, config).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
19
+ show(obj, config)
20
+ .gsub(/\\n/, "\n")
21
+ .gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
18
22
  end
19
23
 
20
24
  # open a tempfile and yield it
21
25
  def self.tempfile(name, content)
22
26
  require "tempfile"
23
27
  Tempfile.open(name) do |tmpfile|
24
- tmpfile.puts(content); tmpfile.flush
28
+ tmpfile.puts(content)
29
+ tmpfile.flush
25
30
  yield tmpfile if block_given?
26
31
  end
27
32
  end
@@ -29,10 +34,11 @@ module Assert
29
34
  # Get a proc that uses stdlib `PP.pp` to pretty print objects
30
35
  def self.stdlib_pp_proc(width = nil)
31
36
  require "pp"
32
- Proc.new{ |obj| PP.pp(obj, "", width || 79).strip }
37
+ Proc.new{ |obj| PP.pp(obj, +"", width || 79).strip }
33
38
  end
34
39
 
35
- # Return true if if either show output has newlines or is bigger than 29 chars
40
+ # Return true if if either show output has newlines or is bigger than 29
41
+ # chars.
36
42
  def self.default_use_diff_proc
37
43
  Proc.new do |exp_show_output, act_show_output|
38
44
  exp_show_output.include?("\n") || exp_show_output.size > 29 ||
@@ -60,10 +66,15 @@ module Assert
60
66
  def self.git_changed_proc
61
67
  Proc.new do |config, test_paths|
62
68
  files = []
63
- cmd = [
64
- "git diff --no-ext-diff --name-only #{config.changed_ref}", # changed files
65
- "git ls-files --others --exclude-standard" # added files
66
- ].map{ |c| "#{c} -- #{test_paths.join(" ")}" }.join(" && ")
69
+ cmd =
70
+ [
71
+ # changed files
72
+ "git diff --no-ext-diff --name-only #{config.changed_ref}",
73
+ # added files
74
+ "git ls-files --others --exclude-standard",
75
+ ]
76
+ .map{ |c| "#{c} -- #{test_paths.join(" ")}" }
77
+ .join(" && ")
67
78
  Assert::CLI.bench("Load only changed files") do
68
79
  files = `#{cmd}`.split("\n")
69
80
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Assert
2
- VERSION = "2.18.4"
4
+ VERSION = "2.19.4"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/config"
2
4
  require "assert/config_helpers"
3
5
  require "assert/suite"
@@ -14,16 +16,18 @@ module Assert
14
16
 
15
17
  def self.require_user_view(view_name)
16
18
  views_file = File.expand_path(
17
- File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name)
19
+ File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name),
18
20
  )
19
21
 
20
- if File.exists?(view_name) || File.exists?(view_name + ".rb")
22
+ if File.exist?(view_name) || File.exist?(view_name + ".rb")
21
23
  require view_name
22
- elsif File.exists?(views_file + ".rb")
24
+ elsif File.exist?(views_file + ".rb")
23
25
  require views_file
24
26
  else
25
- msg = "[WARN] Can't find or require #{view_name.inspect} view."
26
- msg << " Did you install it in `~/.assert/views`?" if !view_name.match(/\A\//)
27
+ msg = +"[WARN] Can't find or require #{view_name.inspect} view."
28
+ unless view_name.match(%r{\A/})
29
+ msg << " Did you install it in `~/.assert/views`?"
30
+ end
27
31
  warn msg
28
32
  end
29
33
  end
@@ -46,11 +50,13 @@ module Assert
46
50
  attr_reader :config
47
51
 
48
52
  def initialize(config, output_io)
49
- @config , @output_io, = config, output_io
53
+ @config, @output_io, = config, output_io
50
54
  @output_io.sync = true if @output_io.respond_to?(:sync=)
51
55
  end
52
56
 
53
- def view; self; end
57
+ def view
58
+ self
59
+ end
54
60
 
55
61
  def is_tty?
56
62
  !!@output_io.isatty
@@ -77,19 +83,41 @@ module Assert
77
83
  # the test suite
78
84
  # * `on_interrupt`: called when the test suite is interrupted while running
79
85
  # the interrupt exception is passed as an arg
80
- def before_load(test_files); end
81
- def after_load; end
82
- def on_start; end
83
- def before_test(test); end
84
- def on_result(result); end
85
- def after_test(test); end
86
- def on_finish; end
87
- def on_info(test); end
88
- def on_interrupt(err); end
86
+ def before_load(test_files)
87
+ end
88
+
89
+ def after_load
90
+ end
91
+
92
+ def on_start
93
+ end
94
+
95
+ def before_test(test)
96
+ end
97
+
98
+ def on_result(result)
99
+ end
100
+
101
+ def after_test(test)
102
+ end
103
+
104
+ def on_finish
105
+ end
106
+
107
+ def on_info(test)
108
+ end
109
+
110
+ def on_interrupt(err)
111
+ end
89
112
 
90
113
  # IO capture
91
114
 
92
- def puts(*args); @output_io.puts(*args); end
93
- def print(*args); @output_io.print(*args); end
115
+ def puts(*args)
116
+ @output_io.puts(*args)
117
+ end
118
+
119
+ def print(*args)
120
+ @output_io.print(*args)
121
+ end
94
122
  end
95
123
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/config_helpers"
2
4
 
3
5
  module Assert
@@ -14,7 +16,7 @@ module Assert
14
16
  def option(name, *default_vals)
15
17
  default = default_vals.size > 1 ? default_vals : default_vals.first
16
18
  define_method(name) do |*args|
17
- if !(value = args.size > 1 ? args : args.first).nil?
19
+ unless (value = args.size > 1 ? args : args.first).nil?
18
20
  instance_variable_set("@#{name}", value)
19
21
  end
20
22
  (val = instance_variable_get("@#{name}")).nil? ? default : val
@@ -36,11 +38,11 @@ module Assert
36
38
  end
37
39
 
38
40
  def tests_to_run_count_statement
39
- "#{self.tests_to_run_count} test#{"s" if self.tests_to_run_count != 1}"
41
+ "#{tests_to_run_count} test#{"s" if tests_to_run_count != 1}"
40
42
  end
41
43
 
42
44
  def result_count_statement
43
- "#{self.result_count} result#{"s" if self.result_count != 1}"
45
+ "#{result_count} result#{"s" if result_count != 1}"
44
46
  end
45
47
 
46
48
  # generate a comma-seperated sentence fragment given a list of items
@@ -54,9 +56,9 @@ module Assert
54
56
 
55
57
  # generate an appropriate result summary msg for all tests passing
56
58
  def all_pass_result_summary_msg
57
- if self.result_count < 1
59
+ if result_count < 1
58
60
  "uhh..."
59
- elsif self.result_count == 1
61
+ elsif result_count == 1
60
62
  "pass"
61
63
  else
62
64
  "all pass"
@@ -65,112 +67,120 @@ module Assert
65
67
 
66
68
  # print a result summary message for a given result type
67
69
  def result_summary_msg(result_type)
68
- if result_type == :pass && self.all_pass?
69
- self.all_pass_result_summary_msg
70
+ if result_type == :pass && all_pass?
71
+ all_pass_result_summary_msg
70
72
  else
71
- "#{self.send("#{result_type}_result_count")} #{result_type}"
73
+ "#{send("#{result_type}_result_count")} #{result_type}"
72
74
  end
73
75
  end
74
76
 
75
77
  # generate a sentence fragment describing the breakdown of test results
76
- # if a block is given, yield each msg in the breakdown for custom formatting
78
+ # if a block is given, yield each msg in the breakdown for custom
79
+ # formatting.
77
80
  def results_summary_sentence
78
- summaries = self.ocurring_result_types.map do |result_type|
79
- summary_msg = self.result_summary_msg(result_type)
81
+ summaries = ocurring_result_types.map do |result_type|
82
+ summary_msg = result_summary_msg(result_type)
80
83
  block_given? ? yield(summary_msg, result_type) : summary_msg
81
84
  end
82
- self.to_sentence(summaries)
85
+ to_sentence(summaries)
83
86
  end
84
87
  end
85
88
 
86
89
  module Ansi
87
- # Table of supported styles/codes (http://en.wikipedia.org/wiki/ANSI_escape_code)
90
+ # Table of supported styles/codes
91
+ # (http://en.wikipedia.org/wiki/ANSI_escape_code).
88
92
  CODES = {
89
- :clear => 0,
90
- :reset => 0,
91
- :bright => 1,
92
- :bold => 1,
93
- :faint => 2,
94
- :dark => 2,
95
- :italic => 3,
96
- :underline => 4,
97
- :underscore => 4,
98
- :blink => 5,
99
- :slow_blink => 5,
100
- :rapid => 6,
101
- :rapid_blink => 6,
102
- :invert => 7,
103
- :inverse => 7,
104
- :reverse => 7,
105
- :negative => 7,
106
- :swap => 7,
107
- :conceal => 8,
108
- :concealed => 8,
109
- :hide => 9,
110
- :strike => 9,
111
-
112
- :default_font => 10,
113
- :font_default => 10,
114
- :font0 => 10,
115
- :font1 => 11,
116
- :font2 => 12,
117
- :font3 => 13,
118
- :font4 => 14,
119
- :font5 => 15,
120
- :font6 => 16,
121
- :font7 => 17,
122
- :font8 => 18,
123
- :font9 => 19,
124
- :fraktur => 20,
125
- :bright_off => 21,
126
- :bold_off => 21,
127
- :double_underline => 21,
128
- :clean => 22,
129
- :italic_off => 23,
130
- :fraktur_off => 23,
131
- :underline_off => 24,
132
- :blink_off => 25,
133
- :inverse_off => 26,
134
- :positive => 26,
135
- :conceal_off => 27,
136
- :show => 27,
137
- :reveal => 27,
138
- :crossed_off => 29,
139
- :crossed_out_off => 29,
140
-
141
- :black => 30,
142
- :red => 31,
143
- :green => 32,
144
- :yellow => 33,
145
- :blue => 34,
146
- :magenta => 35,
147
- :cyan => 36,
148
- :white => 37,
149
-
150
- :on_black => 40,
151
- :on_red => 41,
152
- :on_green => 42,
153
- :on_yellow => 43,
154
- :on_blue => 44,
155
- :on_magenta => 45,
156
- :on_cyan => 46,
157
- :on_white => 47,
158
-
159
- :frame => 51,
160
- :encircle => 52,
161
- :overline => 53,
162
- :frame_off => 54,
163
- :encircle_off => 54,
164
- :overline_off => 55,
93
+ clear: 0,
94
+ reset: 0,
95
+ bright: 1,
96
+ bold: 1,
97
+ faint: 2,
98
+ dark: 2,
99
+ italic: 3,
100
+ underline: 4,
101
+ underscore: 4,
102
+ blink: 5,
103
+ slow_blink: 5,
104
+ rapid: 6,
105
+ rapid_blink: 6,
106
+ invert: 7,
107
+ inverse: 7,
108
+ reverse: 7,
109
+ negative: 7,
110
+ swap: 7,
111
+ conceal: 8,
112
+ concealed: 8,
113
+ hide: 9,
114
+ strike: 9,
115
+
116
+ default_font: 10,
117
+ font_default: 10,
118
+ font0: 10,
119
+ font1: 11,
120
+ font2: 12,
121
+ font3: 13,
122
+ font4: 14,
123
+ font5: 15,
124
+ font6: 16,
125
+ font7: 17,
126
+ font8: 18,
127
+ font9: 19,
128
+ fraktur: 20,
129
+ bright_off: 21,
130
+ bold_off: 21,
131
+ double_underline: 21,
132
+ clean: 22,
133
+ italic_off: 23,
134
+ fraktur_off: 23,
135
+ underline_off: 24,
136
+ blink_off: 25,
137
+ inverse_off: 26,
138
+ positive: 26,
139
+ conceal_off: 27,
140
+ show: 27,
141
+ reveal: 27,
142
+ crossed_off: 29,
143
+ crossed_out_off: 29,
144
+
145
+ black: 30,
146
+ red: 31,
147
+ green: 32,
148
+ yellow: 33,
149
+ blue: 34,
150
+ magenta: 35,
151
+ cyan: 36,
152
+ white: 37,
153
+
154
+ on_black: 40,
155
+ on_red: 41,
156
+ on_green: 42,
157
+ on_yellow: 43,
158
+ on_blue: 44,
159
+ on_magenta: 45,
160
+ on_cyan: 46,
161
+ on_white: 47,
162
+
163
+ frame: 51,
164
+ encircle: 52,
165
+ overline: 53,
166
+ frame_off: 54,
167
+ encircle_off: 54,
168
+ overline_off: 55,
165
169
  }
166
170
 
167
171
  def self.code_for(*style_names)
168
- style_names.map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }.compact.join("")
172
+ style_names
173
+ .map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }
174
+ .compact
175
+ .join("")
169
176
  end
170
177
 
171
178
  def ansi_styled_msg(msg, result_type)
172
- return msg if !self.is_tty? || !self.styled
173
- code = Assert::ViewHelpers::Ansi.code_for(*self.send("#{result_type}_styles"))
179
+ return msg if !is_tty? || !styled
180
+ code =
181
+ Assert::ViewHelpers::Ansi.code_for(
182
+ *send("#{result_type}_styles"),
183
+ )
174
184
  return msg if code.empty?
175
185
  code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
176
186
  end
@@ -1,7 +1,9 @@
1
- # this file is automatically required when you run `assert`
2
- # put any test helpers here
1
+ # frozen_string_literal: true
3
2
 
4
- # add the root dir to the load path
3
+ # This file is automatically required when you run `assert`; put any test
4
+ # helpers here.
5
+
6
+ # Add the root dir to the load path.
5
7
  ROOT_PATH = File.expand_path("../..", __FILE__)
6
8
  $LOAD_PATH.unshift(ROOT_PATH)
7
9
 
@@ -14,12 +16,13 @@ module Assert::Test::TestHelpers
14
16
  receiver.class_eval do
15
17
  setup do
16
18
  @test_run_results = []
17
- @run_callback = proc { |result| @test_run_results << result }
19
+ @run_callback = proc{ |result| @test_run_results << result }
18
20
  end
19
21
  end
20
22
 
21
23
  private
22
24
 
25
+ # rubocop:disable Lint/NestedMethodDefinition
23
26
  def test_run_callback
24
27
  @run_callback
25
28
  end
@@ -40,5 +43,6 @@ module Assert::Test::TestHelpers
40
43
  def last_test_run_result
41
44
  @test_run_results.last
42
45
  end
46
+ # rubocop:enable Lint/NestedMethodDefinition
43
47
  end
44
48
  end