assert 2.19.1 → 2.19.6

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 (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
data/lib/assert/utils.rb CHANGED
@@ -12,18 +12,21 @@ module Assert
12
12
  out
13
13
  end
14
14
 
15
- # show objects in a human-readable manner and make the output diff-able. This
16
- # expands on the basic `show` util by escaping newlines and making object id
17
- # 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.
18
18
  def self.show_for_diff(obj, config)
19
- 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")
20
22
  end
21
23
 
22
24
  # open a tempfile and yield it
23
25
  def self.tempfile(name, content)
24
26
  require "tempfile"
25
27
  Tempfile.open(name) do |tmpfile|
26
- tmpfile.puts(content); tmpfile.flush
28
+ tmpfile.puts(content)
29
+ tmpfile.flush
27
30
  yield tmpfile if block_given?
28
31
  end
29
32
  end
@@ -34,7 +37,8 @@ module Assert
34
37
  Proc.new{ |obj| PP.pp(obj, +"", width || 79).strip }
35
38
  end
36
39
 
37
- # 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.
38
42
  def self.default_use_diff_proc
39
43
  Proc.new do |exp_show_output, act_show_output|
40
44
  exp_show_output.include?("\n") || exp_show_output.size > 29 ||
@@ -62,10 +66,15 @@ module Assert
62
66
  def self.git_changed_proc
63
67
  Proc.new do |config, test_paths|
64
68
  files = []
65
- cmd = [
66
- "git diff --no-ext-diff --name-only #{config.changed_ref}", # changed files
67
- "git ls-files --others --exclude-standard" # added files
68
- ].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(" && ")
69
78
  Assert::CLI.bench("Load only changed files") do
70
79
  files = `#{cmd}`.split("\n")
71
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Assert
4
- VERSION = "2.19.1"
4
+ VERSION = "2.19.6"
5
5
  end
data/lib/assert/view.rb CHANGED
@@ -16,16 +16,18 @@ module Assert
16
16
 
17
17
  def self.require_user_view(view_name)
18
18
  views_file = File.expand_path(
19
- File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name)
19
+ File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name),
20
20
  )
21
21
 
22
- if File.exists?(view_name) || File.exists?(view_name + ".rb")
22
+ if File.exist?(view_name) || File.exist?(view_name + ".rb")
23
23
  require view_name
24
- elsif File.exists?(views_file + ".rb")
24
+ elsif File.exist?(views_file + ".rb")
25
25
  require views_file
26
26
  else
27
- msg = "[WARN] Can't find or require #{view_name.inspect} view."
28
- 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
29
31
  warn msg
30
32
  end
31
33
  end
@@ -48,11 +50,13 @@ module Assert
48
50
  attr_reader :config
49
51
 
50
52
  def initialize(config, output_io)
51
- @config , @output_io, = config, output_io
53
+ @config, @output_io, = config, output_io
52
54
  @output_io.sync = true if @output_io.respond_to?(:sync=)
53
55
  end
54
56
 
55
- def view; self; end
57
+ def view
58
+ self
59
+ end
56
60
 
57
61
  def is_tty?
58
62
  !!@output_io.isatty
@@ -79,19 +83,41 @@ module Assert
79
83
  # the test suite
80
84
  # * `on_interrupt`: called when the test suite is interrupted while running
81
85
  # the interrupt exception is passed as an arg
82
- def before_load(test_files); end
83
- def after_load; end
84
- def on_start; end
85
- def before_test(test); end
86
- def on_result(result); end
87
- def after_test(test); end
88
- def on_finish; end
89
- def on_info(test); end
90
- 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
91
112
 
92
113
  # IO capture
93
114
 
94
- def puts(*args); @output_io.puts(*args); end
95
- 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
96
122
  end
97
123
  end
@@ -16,7 +16,7 @@ module Assert
16
16
  def option(name, *default_vals)
17
17
  default = default_vals.size > 1 ? default_vals : default_vals.first
18
18
  define_method(name) do |*args|
19
- if !(value = args.size > 1 ? args : args.first).nil?
19
+ unless (value = args.size > 1 ? args : args.first).nil?
20
20
  instance_variable_set("@#{name}", value)
21
21
  end
22
22
  (val = instance_variable_get("@#{name}")).nil? ? default : val
@@ -38,11 +38,11 @@ module Assert
38
38
  end
39
39
 
40
40
  def tests_to_run_count_statement
41
- "#{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}"
42
42
  end
43
43
 
44
44
  def result_count_statement
45
- "#{self.result_count} result#{"s" if self.result_count != 1}"
45
+ "#{result_count} result#{"s" if result_count != 1}"
46
46
  end
47
47
 
48
48
  # generate a comma-seperated sentence fragment given a list of items
@@ -56,9 +56,9 @@ module Assert
56
56
 
57
57
  # generate an appropriate result summary msg for all tests passing
58
58
  def all_pass_result_summary_msg
59
- if self.result_count < 1
59
+ if result_count < 1
60
60
  "uhh..."
61
- elsif self.result_count == 1
61
+ elsif result_count == 1
62
62
  "pass"
63
63
  else
64
64
  "all pass"
@@ -67,112 +67,120 @@ module Assert
67
67
 
68
68
  # print a result summary message for a given result type
69
69
  def result_summary_msg(result_type)
70
- if result_type == :pass && self.all_pass?
71
- self.all_pass_result_summary_msg
70
+ if result_type == :pass && all_pass?
71
+ all_pass_result_summary_msg
72
72
  else
73
- "#{self.send("#{result_type}_result_count")} #{result_type}"
73
+ "#{send("#{result_type}_result_count")} #{result_type}"
74
74
  end
75
75
  end
76
76
 
77
77
  # generate a sentence fragment describing the breakdown of test results
78
- # 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.
79
80
  def results_summary_sentence
80
- summaries = self.ocurring_result_types.map do |result_type|
81
- 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)
82
83
  block_given? ? yield(summary_msg, result_type) : summary_msg
83
84
  end
84
- self.to_sentence(summaries)
85
+ to_sentence(summaries)
85
86
  end
86
87
  end
87
88
 
88
89
  module Ansi
89
- # 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).
90
92
  CODES = {
91
- :clear => 0,
92
- :reset => 0,
93
- :bright => 1,
94
- :bold => 1,
95
- :faint => 2,
96
- :dark => 2,
97
- :italic => 3,
98
- :underline => 4,
99
- :underscore => 4,
100
- :blink => 5,
101
- :slow_blink => 5,
102
- :rapid => 6,
103
- :rapid_blink => 6,
104
- :invert => 7,
105
- :inverse => 7,
106
- :reverse => 7,
107
- :negative => 7,
108
- :swap => 7,
109
- :conceal => 8,
110
- :concealed => 8,
111
- :hide => 9,
112
- :strike => 9,
113
-
114
- :default_font => 10,
115
- :font_default => 10,
116
- :font0 => 10,
117
- :font1 => 11,
118
- :font2 => 12,
119
- :font3 => 13,
120
- :font4 => 14,
121
- :font5 => 15,
122
- :font6 => 16,
123
- :font7 => 17,
124
- :font8 => 18,
125
- :font9 => 19,
126
- :fraktur => 20,
127
- :bright_off => 21,
128
- :bold_off => 21,
129
- :double_underline => 21,
130
- :clean => 22,
131
- :italic_off => 23,
132
- :fraktur_off => 23,
133
- :underline_off => 24,
134
- :blink_off => 25,
135
- :inverse_off => 26,
136
- :positive => 26,
137
- :conceal_off => 27,
138
- :show => 27,
139
- :reveal => 27,
140
- :crossed_off => 29,
141
- :crossed_out_off => 29,
142
-
143
- :black => 30,
144
- :red => 31,
145
- :green => 32,
146
- :yellow => 33,
147
- :blue => 34,
148
- :magenta => 35,
149
- :cyan => 36,
150
- :white => 37,
151
-
152
- :on_black => 40,
153
- :on_red => 41,
154
- :on_green => 42,
155
- :on_yellow => 43,
156
- :on_blue => 44,
157
- :on_magenta => 45,
158
- :on_cyan => 46,
159
- :on_white => 47,
160
-
161
- :frame => 51,
162
- :encircle => 52,
163
- :overline => 53,
164
- :frame_off => 54,
165
- :encircle_off => 54,
166
- :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,
167
169
  }
168
170
 
169
171
  def self.code_for(*style_names)
170
- 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("")
171
176
  end
172
177
 
173
178
  def ansi_styled_msg(msg, result_type)
174
- return msg if !self.is_tty? || !self.styled
175
- 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
+ )
176
184
  return msg if code.empty?
177
185
  code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
178
186
  end
data/test/helper.rb CHANGED
@@ -16,12 +16,13 @@ module Assert::Test::TestHelpers
16
16
  receiver.class_eval do
17
17
  setup do
18
18
  @test_run_results = []
19
- @run_callback = proc { |result| @test_run_results << result }
19
+ @run_callback = proc{ |result| @test_run_results << result }
20
20
  end
21
21
  end
22
22
 
23
23
  private
24
24
 
25
+ # rubocop:disable Lint/NestedMethodDefinition
25
26
  def test_run_callback
26
27
  @run_callback
27
28
  end
@@ -42,5 +43,6 @@ module Assert::Test::TestHelpers
42
43
  def last_test_run_result
43
44
  @test_run_results.last
44
45
  end
46
+ # rubocop:enable Lint/NestedMethodDefinition
45
47
  end
46
48
  end
@@ -10,11 +10,17 @@ module Factory
10
10
  extend Assert::Factory
11
11
 
12
12
  def self.context_info_called_from
13
- File.expand_path("#{Factory.path}_tests.rb:#{Factory.integer}", Dir.pwd)
13
+ File.expand_path(
14
+ "#{Factory.path}_tests.rb:#{Factory.integer}",
15
+ Dir.pwd,
16
+ )
14
17
  end
15
18
 
16
19
  def self.context_info(context_klass = nil)
17
- Assert::ContextInfo.new(context_klass || self.context_class, context_info_called_from)
20
+ Assert::ContextInfo.new(
21
+ context_klass || context_class,
22
+ context_info_called_from,
23
+ )
18
24
  end
19
25
 
20
26
  # Generate an anonymous `Context` inherited from `Assert::Context` by default.
@@ -24,9 +30,8 @@ module Factory
24
30
  klass = Class.new(inherit_from || Assert::Context, &block)
25
31
  default = const_name = "FactoryAssertContext"
26
32
 
27
- while(Object.const_defined?(const_name)) do
28
- const_name = "#{default}#{rand(Time.now.to_i)}"
29
- end
33
+ const_name =
34
+ "#{default}#{rand(Time.now.to_i)}" while Object.const_defined?(const_name)
30
35
  Object.const_set(const_name, klass)
31
36
  klass
32
37
  end
@@ -35,9 +40,9 @@ module Factory
35
40
 
36
41
  def self.test(*args, &block)
37
42
  config, context_info, name = [
38
- args.last.kind_of?(Assert::Config) ? args.pop : self.modes_off_config,
39
- args.last.kind_of?(Assert::ContextInfo) ? args.pop : self.context_info,
40
- args.last.kind_of?(::String) ? args.pop : "a test"
43
+ args.last.is_a?(Assert::Config) ? args.pop : modes_off_config,
44
+ args.last.is_a?(Assert::ContextInfo) ? args.pop : self.context_info,
45
+ args.last.is_a?(::String) ? args.pop : "a test",
41
46
  ]
42
47
  Assert::Test.for_block(name, context_info, config, &block)
43
48
  end
@@ -45,15 +50,27 @@ module Factory
45
50
  # Generate results for use in testing.
46
51
 
47
52
  def self.pass_result(msg = nil)
48
- Assert::Result::Pass.for_test(Factory.test(Factory.string), msg || Factory.string, [])
53
+ Assert::Result::Pass.for_test(
54
+ Factory.test(Factory.string),
55
+ msg || Factory.string,
56
+ [],
57
+ )
49
58
  end
50
59
 
51
60
  def self.ignore_result(msg = nil)
52
- Assert::Result::Ignore.for_test(Factory.test(Factory.string), msg || Factory.string, [])
61
+ Assert::Result::Ignore.for_test(
62
+ Factory.test(Factory.string),
63
+ msg || Factory.string,
64
+ [],
65
+ )
53
66
  end
54
67
 
55
68
  def self.fail_result(msg = nil)
56
- Assert::Result::Fail.for_test(Factory.test(Factory.string), msg || Factory.string, [])
69
+ Assert::Result::Fail.for_test(
70
+ Factory.test(Factory.string),
71
+ msg || Factory.string,
72
+ [],
73
+ )
57
74
  end
58
75
 
59
76
  def self.skip_result(exception = nil)
@@ -68,23 +85,23 @@ module Factory
68
85
 
69
86
  def self.modes_off_config
70
87
  Assert::Config.new({
71
- :capture_output => false,
72
- :halt_on_fail => false,
73
- :changed_only => false,
74
- :pp_objects => false,
75
- :debug => false
88
+ capture_output: false,
89
+ halt_on_fail: false,
90
+ changed_only: false,
91
+ pp_objects: false,
92
+ debug: false,
76
93
  })
77
94
  end
78
95
 
79
96
  def self.modes_off_suite
80
- Assert::DefaultSuite.new(self.modes_off_config)
97
+ Assert::DefaultSuite.new(modes_off_config)
81
98
  end
82
99
 
83
100
  def self.modes_off_context_class(*args, &block)
84
- suite_obj = self.modes_off_suite
85
- self.context_class(*args) do
101
+ suite_obj = modes_off_suite
102
+ context_class(*args) do
86
103
  suite(suite_obj)
87
- instance_eval(&block) if !block.nil?
104
+ instance_eval(&block) unless block.nil?
88
105
  end
89
106
  end
90
107
 
@@ -93,7 +110,7 @@ module Factory
93
110
  Factory.modes_off_context_class.new(
94
111
  test,
95
112
  test.config,
96
- result_block || proc { |r| }
113
+ result_block || proc{ |r| },
97
114
  )
98
115
  end
99
116