assert 2.16.5 → 2.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +3 -1
  3. data/README.md +79 -54
  4. data/assert.gemspec +6 -5
  5. data/bin/assert +4 -4
  6. data/lib/assert.rb +8 -18
  7. data/lib/assert/actual_value.rb +127 -0
  8. data/lib/assert/assert_runner.rb +7 -10
  9. data/lib/assert/assertions.rb +15 -28
  10. data/lib/assert/cli.rb +41 -57
  11. data/lib/assert/config.rb +8 -12
  12. data/lib/assert/config_helpers.rb +6 -10
  13. data/lib/assert/context.rb +30 -24
  14. data/lib/assert/context/let_dsl.rb +13 -0
  15. data/lib/assert/context/method_missing.rb +19 -0
  16. data/lib/assert/context/setup_dsl.rb +0 -4
  17. data/lib/assert/context/subject_dsl.rb +0 -4
  18. data/lib/assert/context/suite_dsl.rb +0 -4
  19. data/lib/assert/context/test_dsl.rb +5 -9
  20. data/lib/assert/context_info.rb +2 -6
  21. data/lib/assert/default_runner.rb +1 -5
  22. data/lib/assert/default_suite.rb +1 -6
  23. data/lib/assert/default_view.rb +8 -12
  24. data/lib/assert/factory.rb +1 -4
  25. data/lib/assert/file_line.rb +0 -4
  26. data/lib/assert/macro.rb +1 -4
  27. data/lib/assert/macros/methods.rb +5 -11
  28. data/lib/assert/result.rb +19 -34
  29. data/lib/assert/runner.rb +12 -11
  30. data/lib/assert/stub.rb +16 -2
  31. data/lib/assert/suite.rb +3 -7
  32. data/lib/assert/test.rb +13 -18
  33. data/lib/assert/utils.rb +8 -12
  34. data/lib/assert/version.rb +1 -1
  35. data/lib/assert/view.rb +18 -21
  36. data/lib/assert/view_helpers.rb +6 -17
  37. data/log/{.gitkeep → .keep} +0 -0
  38. data/test/helper.rb +26 -41
  39. data/test/support/factory.rb +20 -6
  40. data/test/support/inherited_stuff.rb +0 -2
  41. data/test/system/stub_tests.rb +350 -354
  42. data/test/system/test_tests.rb +119 -133
  43. data/test/unit/actual_value_tests.rb +335 -0
  44. data/test/unit/assert_tests.rb +125 -52
  45. data/test/unit/assertions/assert_block_tests.rb +34 -37
  46. data/test/unit/assertions/assert_empty_tests.rb +38 -38
  47. data/test/unit/assertions/assert_equal_tests.rb +84 -86
  48. data/test/unit/assertions/assert_file_exists_tests.rb +37 -39
  49. data/test/unit/assertions/assert_includes_tests.rb +45 -46
  50. data/test/unit/assertions/assert_instance_of_tests.rb +39 -40
  51. data/test/unit/assertions/assert_kind_of_tests.rb +39 -40
  52. data/test/unit/assertions/assert_match_tests.rb +39 -40
  53. data/test/unit/assertions/assert_nil_tests.rb +35 -38
  54. data/test/unit/assertions/assert_raises_tests.rb +58 -62
  55. data/test/unit/assertions/assert_respond_to_tests.rb +41 -42
  56. data/test/unit/assertions/assert_same_tests.rb +94 -90
  57. data/test/unit/assertions/assert_true_false_tests.rb +67 -69
  58. data/test/unit/assertions_tests.rb +17 -19
  59. data/test/unit/config_helpers_tests.rb +41 -43
  60. data/test/unit/config_tests.rb +42 -46
  61. data/test/unit/context/let_dsl_tests.rb +10 -0
  62. data/test/unit/context/setup_dsl_tests.rb +72 -91
  63. data/test/unit/context/subject_dsl_tests.rb +18 -51
  64. data/test/unit/context/suite_dsl_tests.rb +19 -23
  65. data/test/unit/context/test_dsl_tests.rb +52 -59
  66. data/test/unit/context_info_tests.rb +19 -21
  67. data/test/unit/context_tests.rb +175 -178
  68. data/test/unit/default_runner_tests.rb +4 -10
  69. data/test/unit/default_suite_tests.rb +54 -59
  70. data/test/unit/factory_tests.rb +6 -9
  71. data/test/unit/file_line_tests.rb +34 -40
  72. data/test/unit/macro_tests.rb +11 -20
  73. data/test/unit/result_tests.rb +156 -182
  74. data/test/unit/runner_tests.rb +72 -79
  75. data/test/unit/suite_tests.rb +62 -63
  76. data/test/unit/test_tests.rb +143 -147
  77. data/test/unit/utils_tests.rb +49 -62
  78. data/test/unit/view_helpers_tests.rb +67 -70
  79. data/test/unit/view_tests.rb +26 -32
  80. metadata +54 -47
  81. data/.assert.rb +0 -3
  82. data/.gitignore +0 -19
@@ -0,0 +1,13 @@
1
+ module Assert; end
2
+ class Assert::Context; end
3
+ module Assert::Context::LetDSL
4
+ def let(name, &block)
5
+ self.send(:define_method, name, &-> {
6
+ if instance_variable_get("@#{name}").nil?
7
+ instance_variable_set("@#{name}", instance_eval(&block))
8
+ end
9
+
10
+ instance_variable_get("@#{name}")
11
+ })
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require "assert/assertions"
2
+
3
+ module Assert; end
4
+ class Assert::Context; end
5
+ module Assert::Context::MethodMissing
6
+ def method_missing(method, *args, &block)
7
+ if Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
8
+ ignore "The assertion `#{method}` is not supported."\
9
+ " Please use another assertion or the basic `assert`."
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def respond_to_missing?(method, *)
16
+ Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym) ||
17
+ super
18
+ end
19
+ end
@@ -1,8 +1,6 @@
1
1
  module Assert; end
2
2
  class Assert::Context
3
-
4
3
  module SetupDSL
5
-
6
4
  def setup_once(&block)
7
5
  self.suite.setup(&block)
8
6
  end
@@ -70,7 +68,5 @@ class Assert::Context
70
68
  # ... before the parent
71
69
  self.superclass.run_teardowns(scope) if self.superclass.respond_to?(:run_teardowns)
72
70
  end
73
-
74
71
  end
75
-
76
72
  end
@@ -1,8 +1,6 @@
1
1
  module Assert; end
2
2
  class Assert::Context
3
-
4
3
  module SubjectDSL
5
-
6
4
  # Add a piece of description text or return the full description for the context
7
5
  def description(text = nil)
8
6
  if text
@@ -31,7 +29,5 @@ class Assert::Context
31
29
  def descriptions
32
30
  @descriptions ||= []
33
31
  end
34
-
35
32
  end
36
-
37
33
  end
@@ -1,8 +1,6 @@
1
1
  module Assert; end
2
2
  class Assert::Context
3
-
4
3
  module SuiteDSL
5
-
6
4
  def suite(suite_obj = nil)
7
5
  if suite_obj
8
6
  @suite = suite_obj
@@ -14,7 +12,5 @@ class Assert::Context
14
12
  end
15
13
  end
16
14
  end
17
-
18
15
  end
19
-
20
16
  end
@@ -1,13 +1,11 @@
1
- require 'assert/context_info'
2
- require 'assert/macro'
3
- require 'assert/suite'
4
- require 'assert/test'
1
+ require "assert/context_info"
2
+ require "assert/macro"
3
+ require "assert/suite"
4
+ require "assert/test"
5
5
 
6
6
  module Assert; end
7
7
  class Assert::Context
8
-
9
8
  module TestDSL
10
-
11
9
  def test(desc_or_macro, called_from = nil, first_caller = nil, &block)
12
10
  if desc_or_macro.kind_of?(Assert::Macro)
13
11
  instance_eval(&desc_or_macro)
@@ -31,7 +29,7 @@ class Assert::Context
31
29
  desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
32
30
  ci,
33
31
  self.suite.config,
34
- &proc { skip('TODO', [ci.called_from.to_s]) }
32
+ &proc { skip("TODO", [ci.called_from.to_s]) }
35
33
  ))
36
34
  end
37
35
  alias_method :test_skip, :test_eventually
@@ -50,7 +48,5 @@ class Assert::Context
50
48
  test_eventually(desc_or_macro, called_from, first_caller || caller_locations.first, &block)
51
49
  end
52
50
  alias_method :should_skip, :should_eventually
53
-
54
51
  end
55
-
56
52
  end
@@ -1,19 +1,15 @@
1
1
  module Assert
2
-
3
2
  class ContextInfo
4
-
5
3
  attr_reader :called_from, :klass, :file
6
4
 
7
5
  def initialize(klass, called_from = nil, first_caller = nil)
8
6
  @called_from = called_from || first_caller
9
7
  @klass = klass
10
- @file = @called_from.to_s.gsub(/\:[0-9]+.*$/, '') if @called_from
8
+ @file = @called_from.to_s.gsub(/\:[0-9]+.*$/, "") if @called_from
11
9
  end
12
10
 
13
11
  def test_name(name)
14
- [klass.description.to_s, name.to_s].compact.reject(&:empty?).join(' ')
12
+ [klass.description.to_s, name.to_s].compact.reject(&:empty?).join(" ")
15
13
  end
16
-
17
14
  end
18
-
19
15
  end
@@ -1,12 +1,8 @@
1
- require 'assert/runner'
1
+ require "assert/runner"
2
2
 
3
3
  module Assert
4
-
5
4
  # This is the default runner used by assert. It adds no special behavior on
6
5
  # top of the base runner's behavior
7
-
8
6
  class DefaultRunner < Assert::Runner
9
-
10
7
  end
11
-
12
8
  end
@@ -1,13 +1,10 @@
1
- require 'assert/suite'
1
+ require "assert/suite"
2
2
 
3
3
  module Assert
4
-
5
4
  # This is the default suite used by assert. In addition to the base suite
6
5
  # behavior, it accumulates test/result counts in memory. This data is used
7
6
  # by the runner/view for handling and presentation purposes.
8
-
9
7
  class DefaultSuite < Assert::Suite
10
-
11
8
  def initialize(config)
12
9
  super
13
10
  reset_run_data
@@ -53,7 +50,5 @@ module Assert
53
50
  @skip_result_count = 0
54
51
  @ignore_result_count = 0
55
52
  end
56
-
57
53
  end
58
-
59
54
  end
@@ -1,22 +1,20 @@
1
- require 'assert/view'
2
- require 'assert/view_helpers'
1
+ require "assert/view"
2
+ require "assert/view_helpers"
3
3
 
4
4
  module Assert
5
-
6
5
  # This is the default view used by assert. It renders ansi test output
7
6
  # designed for terminal viewing.
8
-
9
7
  class DefaultView < Assert::View
10
8
  include Assert::ViewHelpers::Ansi
11
9
 
12
10
  # setup options and their default values
13
11
 
14
- option 'styled', true
15
- option 'pass_styles', :green
16
- option 'fail_styles', :red, :bold
17
- option 'error_styles', :yellow, :bold
18
- option 'skip_styles', :cyan
19
- option 'ignore_styles', :magenta
12
+ option "styled", true
13
+ option "pass_styles", :green
14
+ option "fail_styles", :red, :bold
15
+ option "error_styles", :yellow, :bold
16
+ option "skip_styles", :cyan
17
+ option "ignore_styles", :magenta
20
18
 
21
19
  def before_load(test_files)
22
20
  end
@@ -184,7 +182,5 @@ module Assert
184
182
  end
185
183
  end
186
184
  end
187
-
188
185
  end
189
-
190
186
  end
@@ -1,11 +1,8 @@
1
- require 'much-factory'
1
+ require "much-factory"
2
2
 
3
3
  module Assert
4
-
5
4
  module Factory
6
5
  extend MuchFactory
7
6
  include MuchFactory
8
-
9
7
  end
10
-
11
8
  end
@@ -1,7 +1,5 @@
1
1
  module Assert
2
-
3
2
  class FileLine
4
-
5
3
  def self.parse(file_line_path)
6
4
  self.new(*(file_line_path.to_s.match(/(^[^\:]*)\:*(\d*).*$/) || [])[1..2])
7
5
  end
@@ -24,7 +22,5 @@ module Assert
24
22
  super
25
23
  end
26
24
  end
27
-
28
25
  end
29
-
30
26
  end
@@ -1,10 +1,8 @@
1
1
  module Assert
2
2
  class Macro < ::Proc
3
-
4
3
  # this class is essentially a way to define a custom set of tests using
5
- # arguments. When passed as an argument to the 'should' method, a macro
4
+ # arguments. When passed as an argument to the "should" method, a macro
6
5
  # will be instance_eval'd in that Assert::Context.
7
-
8
6
  attr_accessor :name
9
7
 
10
8
  def initialize(name = nil, *args, &block)
@@ -12,6 +10,5 @@ module Assert
12
10
  @name = name || "run this macro"
13
11
  super()
14
12
  end
15
-
16
13
  end
17
14
  end
@@ -1,14 +1,12 @@
1
- require 'assert/macro'
1
+ require "assert/macro"
2
2
 
3
3
  module Assert::Macros
4
4
  module Methods
5
-
6
5
  def self.included(receiver)
7
6
  receiver.send(:extend, ClassMethods)
8
7
  end
9
8
 
10
9
  module ClassMethods
11
-
12
10
  def have_instance_method(*methods)
13
11
  called_from = (methods.last.kind_of?(Array) ? methods.pop : caller_locations).first
14
12
  Assert::Macro.new do
@@ -101,35 +99,33 @@ module Assert::Macros
101
99
 
102
100
  def _methods_macro_test(called_from)
103
101
  @_methods_macro_test ||= test "should respond to methods", called_from do
104
-
105
102
  self.class._methods_macro_instance_methods.each do |(method, called_from)|
106
103
  msg = "#{subject.class.name} does not have instance method ##{method}"
107
104
  with_backtrace([called_from]) do
108
- assert_respond_to method, subject, msg
105
+ assert_that(subject).responds_to(method, msg)
109
106
  end
110
107
  end
111
108
 
112
109
  self.class._methods_macro_class_methods.each do |(method, called_from)|
113
110
  msg = "#{subject.class.name} does not have class method ##{method}"
114
111
  with_backtrace([called_from]) do
115
- assert_respond_to method, subject.class, msg
112
+ assert_that(subject.class).responds_to(method, msg)
116
113
  end
117
114
  end
118
115
 
119
116
  self.class._methods_macro_not_instance_methods.each do |(method, called_from)|
120
117
  msg = "#{subject.class.name} has instance method ##{method}"
121
118
  with_backtrace([called_from]) do
122
- assert_not_respond_to method, subject, msg
119
+ assert_that(subject).does_not_respond_to(method, msg)
123
120
  end
124
121
  end
125
122
 
126
123
  self.class._methods_macro_not_class_methods.each do |(method, called_from)|
127
124
  msg = "#{subject.class.name} has class method ##{method}"
128
125
  with_backtrace([called_from]) do
129
- assert_not_respond_to method, subject.class, msg
126
+ assert_that(subject.class).does_not_respond_to(method, msg)
130
127
  end
131
128
  end
132
-
133
129
  end
134
130
  end
135
131
 
@@ -148,8 +144,6 @@ module Assert::Macros
148
144
  def _methods_macro_not_class_methods
149
145
  @_methods_macro_not_class_methods ||= []
150
146
  end
151
-
152
147
  end
153
-
154
148
  end
155
149
  end
@@ -1,8 +1,7 @@
1
- require 'assert/file_line'
1
+ require "assert/file_line"
2
2
 
3
3
  module Assert; end
4
4
  module Assert::Result
5
-
6
5
  class Base ; end
7
6
  class Pass < Base ; end
8
7
  class Ignore < Base ; end
@@ -26,9 +25,8 @@ module Assert::Result
26
25
  end
27
26
 
28
27
  class Base
29
-
30
28
  def self.type; :unknown; end
31
- def self.name; ''; end
29
+ def self.name; ""; end
32
30
 
33
31
  def self.for_test(test, message, bt)
34
32
  self.new({
@@ -54,11 +52,11 @@ module Assert::Result
54
52
  end
55
53
 
56
54
  def test_name
57
- @test_name ||= (@build_data[:test_name] || '')
55
+ @test_name ||= (@build_data[:test_name] || "")
58
56
  end
59
57
 
60
58
  def test_file_line
61
- @test_file_line ||= (@build_data[:test_file_line] || Assert::FileLine.parse(''))
59
+ @test_file_line ||= (@build_data[:test_file_line] || Assert::FileLine.parse(""))
62
60
  end
63
61
 
64
62
  def test_file_name; self.test_file_line.file; end
@@ -69,11 +67,11 @@ module Assert::Result
69
67
  end
70
68
 
71
69
  def message
72
- @message ||= (@build_data[:message] || '')
70
+ @message ||= (@build_data[:message] || "")
73
71
  end
74
72
 
75
73
  def output
76
- @output ||= (@build_data[:output] || '')
74
+ @output ||= (@build_data[:output] || "")
77
75
  end
78
76
 
79
77
  def backtrace
@@ -135,7 +133,7 @@ module Assert::Result
135
133
  end
136
134
 
137
135
  def inspect
138
- "#<#{self.class}:#{'0x0%x' % (object_id << 1)} "\
136
+ "#<#{self.class}:#{"0x0%x" % (object_id << 1)} "\
139
137
  "@message=#{self.message.inspect} "\
140
138
  "@file_line=#{self.file_line.to_s.inspect} "\
141
139
  "@test_file_line=#{self.test_file_line.to_s.inspect}>"
@@ -156,7 +154,7 @@ module Assert::Result
156
154
  end
157
155
 
158
156
  # if the filtered backtrace is empty, just use the backtrace itself (this
159
- # should only occur if the result is an error from a line in assert's
157
+ # should only occur if the result is an error from a line in Assert's
160
158
  # non-test code).
161
159
  def first_filtered_bt_line(backtrace)
162
160
  ((fbt = backtrace.filtered).empty? ? backtrace : fbt).first.to_s
@@ -164,30 +162,25 @@ module Assert::Result
164
162
  end
165
163
 
166
164
  class Pass < Base
167
-
168
165
  def self.type; :pass; end
169
- def self.name; 'Pass'; end
170
-
166
+ def self.name; "Pass"; end
171
167
  end
172
168
 
173
169
  class Ignore < Base
174
-
175
170
  def self.type; :ignore; end
176
- def self.name; 'Ignore'; end
177
-
171
+ def self.name; "Ignore"; end
178
172
  end
179
173
 
180
174
  class HaltingTestResultError < RuntimeError
181
175
  attr_accessor :assert_with_bt
182
176
  end
183
177
 
184
- # raised by the 'fail' context helper to break test execution
178
+ # raised by the "fail" context helper to break test execution
185
179
  TestFailure = Class.new(HaltingTestResultError)
186
180
 
187
181
  class Fail < Base
188
-
189
182
  def self.type; :fail; end
190
- def self.name; 'Fail'; end
183
+ def self.name; "Fail"; end
191
184
 
192
185
  # fail results can be generated manually or by raising Assert::Result::TestFailure
193
186
  def self.for_test(test, msg_or_err, bt = nil)
@@ -201,16 +194,14 @@ module Assert::Result
201
194
  super(test, msg_or_err, bt)
202
195
  end
203
196
  end
204
-
205
197
  end
206
198
 
207
- # raised by the 'skip' context helper to break test execution
199
+ # raised by the "skip" context helper to break test execution
208
200
  TestSkipped = Class.new(HaltingTestResultError)
209
201
 
210
202
  class Skip < Base
211
-
212
203
  def self.type; :skip; end
213
- def self.name; 'Skip'; end
204
+ def self.name; "Skip"; end
214
205
 
215
206
  # skip results are generated by raising Assert::Result::TestSkipped
216
207
  def self.for_test(test, msg_or_err, bt = nil)
@@ -224,13 +215,11 @@ module Assert::Result
224
215
  super(test, msg_or_err, bt)
225
216
  end
226
217
  end
227
-
228
218
  end
229
219
 
230
220
  class Error < Base
231
-
232
221
  def self.type; :error; end
233
- def self.name; 'Error'; end
222
+ def self.name; "Error"; end
234
223
 
235
224
  # error results are generated by raising exceptions in tests
236
225
  def self.for_test(test, err)
@@ -247,11 +236,9 @@ module Assert::Result
247
236
  def build_trace
248
237
  Backtrace.to_s(backtrace)
249
238
  end
250
-
251
239
  end
252
240
 
253
241
  class Backtrace < ::Array
254
-
255
242
  DELIM = "\n".freeze
256
243
 
257
244
  def self.parse(bt)
@@ -272,18 +259,16 @@ module Assert::Result
272
259
 
273
260
  protected
274
261
 
275
- # filter a line out if it's an assert lib/bin line
262
+ # filter a line out if it's an Assert lib/bin line
276
263
  def filter_out?(line)
277
- # './lib' in project dir, or '/usr/local/blahblah' if installed
278
- assert_lib_path = File.expand_path('../..', __FILE__)
279
- assert_macros_path = File.join(assert_lib_path, 'assert/macros')
264
+ # "./lib" in project dir, or "/usr/local/blahblah" if installed
265
+ assert_lib_path = File.expand_path("../..", __FILE__)
266
+ assert_macros_path = File.join(assert_lib_path, "assert/macros")
280
267
  assert_bin_regex = /bin\/assert\:/
281
268
  ( line.rindex(assert_lib_path, 0) &&
282
269
  !line.rindex(assert_macros_path, 0)
283
270
  ) ||
284
271
  line =~ assert_bin_regex
285
272
  end
286
-
287
273
  end
288
-
289
274
  end