attestify 0.1.0.pre.2 → 0.1.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 876c694bdaec5a2ae1048fc2a54b2d38b4251969
4
- data.tar.gz: efc2a21cff2441ba14938aeac038f0d8912efbf5
3
+ metadata.gz: 7277786172463a5c2d2b1e37dcb5d9336e69465f
4
+ data.tar.gz: 3b2bdd5dbcf9cc1cad6d36f23fc2e13bce86e84d
5
5
  SHA512:
6
- metadata.gz: 5db0a47826a1872993a5be2780251302d3ec3fb2cf0cae3b9d861cd8c87f9c608f5b93da28bbdfe9b2c9984e413b6d92780dc081dfdb20ae9eefa49cf61b6451
7
- data.tar.gz: 50427b717de140bca88a281a4cbdfa894c7de4ce9ab562c2008686e10cc52f5ff2a4de5235022cd03c4fd295f09770a5d8904933ef103565379f19e4913c4e10
6
+ metadata.gz: 1da0ce79a1f218b79f81f1d299957657f6a8b7308896ecdc59dfc1e4450e55e50a03ed3d3882e2f8fc3a0664ffb0e7af7cad70fbeb75567936a9190dee559213
7
+ data.tar.gz: eba4dafcd0f9bc8cafde2366fdf478af5a72e0490f136389083c2bbd16474b3418e7aaed97835920cb7447193f5e15d8ca2c7b6be743b5e371be9b4938b76879
@@ -20,7 +20,12 @@ module Attestify
20
20
  @root ||= File.realpath(File.expand_path("../..", __FILE__)).freeze
21
21
  end
22
22
 
23
+ def self.disable_autorun
24
+ @autorun_disabled = true
25
+ @autorun.disable if @autorun
26
+ end
27
+
23
28
  def self.autorun
24
- @autorun ||= Attestify::Autorun.new.tap(&:enable)
29
+ @autorun ||= Attestify::Autorun.new.tap { |a| a.enable unless @autorun_disabled }
25
30
  end
26
31
  end
@@ -9,100 +9,97 @@ module Attestify
9
9
  autoload :OutputAssertion, "attestify/assertions/output_assertion"
10
10
 
11
11
  def assert(value, message = nil)
12
- record_assert(value) { message || "Failed assertion." }
12
+ record_assert(value, message) { "Failed assertion." }
13
13
  end
14
14
 
15
15
  def assert_empty(object, message = nil)
16
16
  if object.respond_to?(:empty?)
17
- record_assert(object.empty?) { message || "Expected #{object.inspect} to be empty" }
17
+ record_assert(object.empty?, message) { "Expected #{object.inspect} to be empty" }
18
18
  else
19
- record_assert(false) { message || "Expected #{object.inspect} to be empty, but it didn't respond_to(:empty?)" }
19
+ record_assert(false, message) { "Expected #{object.inspect} to be empty, but it didn't respond_to(:empty?)" }
20
20
  end
21
21
  end
22
22
 
23
23
  def assert_equal(expected, actual, message = nil)
24
- record_assert(expected == actual) { message || "Expected #{expected.inspect} == #{actual.inspect}" }
24
+ record_assert(expected == actual, message) { "Expected #{expected.inspect} == #{actual.inspect}" }
25
25
  end
26
26
 
27
27
  def assert_in_delta(expected, actual, delta = 0.001, message = nil)
28
- record_assert((expected - actual).abs < delta) do
29
- message || "Expected #{expected.inspect} == #{actual.inspect} within #{delta.inspect}"
28
+ record_assert((expected - actual).abs < delta, message) do
29
+ "Expected #{expected.inspect} == #{actual.inspect} within #{delta.inspect}"
30
30
  end
31
31
  end
32
32
 
33
33
  def assert_includes(collection, object, message = nil)
34
34
  if collection.respond_to?(:include?)
35
- record_assert(collection.include?(object)) do
36
- message || "Expected #{collection.inspect} to include?(#{object.inspect})"
35
+ record_assert(collection.include?(object), message) do
36
+ "Expected #{collection.inspect} to include?(#{object.inspect})"
37
37
  end
38
38
  else
39
- record_assert(false) do
40
- message || "Expected #{collection.inspect} to include?(#{object.inspect}), " \
41
- "but it didn't respond_to(:include?)"
39
+ record_assert(false, message) do
40
+ "Expected #{collection.inspect} to include?(#{object.inspect}), but it didn't respond_to(:include?)"
42
41
  end
43
42
  end
44
43
  end
45
44
 
46
45
  def assert_instance_of(clazz, object, message = nil)
47
46
  if clazz.is_a?(Module)
48
- record_assert(object.instance_of?(clazz)) do
49
- message || "Expected #{object.inspect} to be an instance_of?(#{clazz.inspect})"
47
+ record_assert(object.instance_of?(clazz), message) do
48
+ "Expected #{object.inspect} to be an instance_of?(#{clazz.inspect})"
50
49
  end
51
50
  else
52
- record_assert(false) do
53
- message || "Expected #{object.inspect} to be an instance_of?(#{clazz.inspect}), " \
54
- "but #{clazz.inspect} is not a Class or Module"
51
+ record_assert(false, message) do
52
+ "Expected #{object.inspect} to be an instance_of?(#{clazz.inspect}), " \
53
+ "but #{clazz.inspect} is not a Class or Module"
55
54
  end
56
55
  end
57
56
  end
58
57
 
59
58
  def assert_kind_of(clazz, object, message = nil)
60
59
  if clazz.is_a?(Module)
61
- record_assert(object.is_a?(clazz)) do
62
- message || "Expected #{object.inspect} to be a kind_of?(#{clazz.inspect})"
60
+ record_assert(object.is_a?(clazz), message) do
61
+ "Expected #{object.inspect} to be a kind_of?(#{clazz.inspect})"
63
62
  end
64
63
  else
65
- record_assert(false) do
66
- message || "Expected #{object.inspect} to be a kind_of?(#{clazz.inspect}), " \
67
- "but #{clazz.inspect} is not a Class or Module"
64
+ record_assert(false, message) do
65
+ "Expected #{object.inspect} to be a kind_of?(#{clazz.inspect}), but #{clazz.inspect} is not a Class or Module"
68
66
  end
69
67
  end
70
68
  end
71
69
 
72
70
  def assert_match(matcher, object, message = nil)
73
- record_assert(matcher =~ object) { message || "Expected #{matcher.inspect} =~ #{object.inspect}" }
71
+ record_assert(matcher =~ object, message) { "Expected #{matcher.inspect} =~ #{object.inspect}" }
74
72
  end
75
73
 
76
74
  def assert_nil(object, message = nil)
77
- record_assert(object.nil?) { message || "Expected #{object.inspect} to be nil" }
75
+ record_assert(object.nil?, message) { "Expected #{object.inspect} to be nil" }
78
76
  end
79
77
 
80
78
  def assert_operator(left_operand, operator, right_operand, message = nil)
81
79
  if left_operand.respond_to?(operator)
82
- record_assert(left_operand.send(operator, right_operand)) do
83
- message || "Expected #{left_operand.inspect} #{operator} #{right_operand.inspect}"
80
+ record_assert(left_operand.send(operator, right_operand), message) do
81
+ "Expected #{left_operand.inspect} #{operator} #{right_operand.inspect}"
84
82
  end
85
83
  else
86
- record_assert(false) do
87
- message || "Expected #{left_operand.inspect} #{operator} #{right_operand.inspect}, " \
88
- "but #{left_operand.inspect} didn't respond_to?(#{operator})"
84
+ record_assert(false, message) do
85
+ "Expected #{left_operand.inspect} #{operator} #{right_operand.inspect}, " \
86
+ "but #{left_operand.inspect} didn't respond_to?(#{operator})"
89
87
  end
90
88
  end
91
89
  end
92
90
 
93
91
  def assert_output(expected_stdout = nil, expected_stderr = nil, message = nil)
94
92
  stdout, stderr = capture_io { yield }
95
- assertion = Attestify::Assertions::OutputAssertion.new(expected_stdout, expected_stderr, stdout, stderr, message)
96
- record_assert(assertion.assert) { assertion.message }
93
+ assertion = Attestify::Assertions::OutputAssertion.new(expected_stdout, expected_stderr, stdout, stderr)
94
+ record_assert(assertion.assert, message) { assertion.message }
97
95
  end
98
96
 
99
97
  def assert_predicate(object, predicate, message = nil)
100
98
  if object.respond_to?(predicate)
101
- record_assert(object.send(predicate)) { message || "Expected #{object.inspect} to be #{predicate}" }
99
+ record_assert(object.send(predicate), message) { "Expected #{object.inspect} to be #{predicate}" }
102
100
  else
103
- record_assert(false) do
104
- message || "Expected #{object.inspect} to be #{predicate}, " \
105
- "but #{object.inspect} didn't respond_to?(#{predicate})"
101
+ record_assert(false, message) do
102
+ "Expected #{object.inspect} to be #{predicate}, but #{object.inspect} didn't respond_to?(#{predicate})"
106
103
  end
107
104
  end
108
105
  end
@@ -111,11 +108,11 @@ module Attestify
111
108
  message = exceptions.pop if exceptions.last.is_a?(String)
112
109
  exceptions = [StandardError] if exceptions.empty?
113
110
  yield
114
- record_assert(false) { message || "Expected one of: #{exceptions.inspect} to be raised, but nothing was raised" }
111
+ record_assert(false, message) { "Expected one of: #{exceptions.inspect} to be raised, but nothing was raised" }
115
112
  return nil
116
113
  rescue => e
117
- record_assert(exceptions.any? { |x| e.is_a?(x) }) do
118
- message || "Expected one of: #{exceptions.inspect} to be raised, but instead got: #{e.class.name}"
114
+ record_assert(exceptions.any? { |x| e.is_a?(x) }, message) do
115
+ "Expected one of: #{exceptions.inspect} to be raised, but instead got: #{e.class.name}"
119
116
  end
120
117
 
121
118
  return e
@@ -123,31 +120,31 @@ module Attestify
123
120
 
124
121
  def assert_respond_to(object, method, message = nil)
125
122
  if method.is_a?(String) || method.is_a?(Symbol)
126
- record_assert(object.respond_to?(method)) do
127
- message || "Expected #{object.inspect} to respond_to?(#{method.inspect})"
123
+ record_assert(object.respond_to?(method), message) do
124
+ "Expected #{object.inspect} to respond_to?(#{method.inspect})"
128
125
  end
129
126
  else
130
- record_assert(false) do
131
- message || "Expected #{object.inspect} to respond_to?(#{method.inspect}), " \
132
- "but #{method.inspect} is not a String or Symbol"
127
+ record_assert(false, message) do
128
+ "Expected #{object.inspect} to respond_to?(#{method.inspect}), " \
129
+ "but #{method.inspect} is not a String or Symbol"
133
130
  end
134
131
  end
135
132
  end
136
133
 
137
134
  def assert_same(expected, actual, message = nil)
138
- record_assert(expected.equal?(actual)) { message || "Expected #{expected.inspect} is equal?(#{actual.inspect})" }
135
+ record_assert(expected.equal?(actual), message) { "Expected #{expected.inspect} is equal?(#{actual.inspect})" }
139
136
  end
140
137
 
141
138
  def assert_silent(message = nil)
142
139
  stdout, stderr = capture_io { yield }
143
- assertion = Attestify::Assertions::OutputAssertion.new("", "", stdout, stderr, message)
140
+ assertion = Attestify::Assertions::OutputAssertion.new("", "", stdout, stderr)
144
141
 
145
- record_assert(assertion.assert) do
146
- message || "Expected silence, but instead got: $stdout: #{stdout.inspect}, and $stderr: #{stderr.inspect}"
142
+ record_assert(assertion.assert, message) do
143
+ "Expected silence, but instead got: $stdout: #{stdout.inspect}, and $stderr: #{stderr.inspect}"
147
144
  end
148
145
  end
149
146
 
150
- def assert_42(expected, message = nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/LineLength, Metrics/MethodLength, Metrics/PerceivedComplexity
147
+ def assert_42(expected, message = nil) # rubocop:disable Metrics/MethodLength
151
148
  record_assert(
152
149
  if expected.is_a?(Numeric)
153
150
  expected == 42
@@ -157,9 +154,9 @@ module Attestify
157
154
  expected.send("42?")
158
155
  elsif expected.respond_to?(:forty_two?)
159
156
  expected.forty_two?
160
- end
157
+ end, message
161
158
  ) do
162
- message || "Answer to the Ultimate Question of Life, The Universe, and Everything is Incorrect"
159
+ "Answer to the Ultimate Question of Life, The Universe, and Everything is Incorrect"
163
160
  end
164
161
  end
165
162
 
@@ -206,7 +203,7 @@ module Attestify
206
203
  end
207
204
 
208
205
  def flunk(message = nil)
209
- record_assert(false) { message || "Flunked assertion." }
206
+ record_assert(false, message) { "Flunked assertion." }
210
207
  end
211
208
 
212
209
  def pass(_message = nil)
@@ -214,31 +211,31 @@ module Attestify
214
211
  end
215
212
 
216
213
  def refute(value, message = nil)
217
- record_assert(!value) { message || "Failed refutation." }
214
+ record_assert(!value, message) { "Failed refutation." }
218
215
  end
219
216
 
220
217
  def refute_empty(object, message = nil)
221
218
  if object.respond_to?(:empty?)
222
- record_assert(!object.empty?) { message || "Expected #{object.inspect} to not be empty" }
219
+ record_assert(!object.empty?, message) { "Expected #{object.inspect} to not be empty" }
223
220
  else
224
221
  pass
225
222
  end
226
223
  end
227
224
 
228
225
  def refute_equal(expected, actual, message = nil)
229
- record_assert(expected != actual) { message || "Expected #{expected.inspect} != #{actual.inspect}" }
226
+ record_assert(expected != actual, message) { "Expected #{expected.inspect} != #{actual.inspect}" }
230
227
  end
231
228
 
232
229
  def refute_in_delta(expected, actual, delta = 0.001, message = nil)
233
- record_assert((expected - actual).abs >= delta) do
234
- message || "Expected #{expected.inspect} != #{actual.inspect} within #{delta.inspect}"
230
+ record_assert((expected - actual).abs >= delta, message) do
231
+ "Expected #{expected.inspect} != #{actual.inspect} within #{delta.inspect}"
235
232
  end
236
233
  end
237
234
 
238
235
  def refute_includes(collection, object, message = nil)
239
236
  if collection.respond_to?(:include?)
240
- record_assert(!collection.include?(object)) do
241
- message || "Expected #{collection.inspect} to not include?(#{object.inspect})"
237
+ record_assert(!collection.include?(object), message) do
238
+ "Expected #{collection.inspect} to not include?(#{object.inspect})"
242
239
  end
243
240
  else
244
241
  pass
@@ -247,8 +244,8 @@ module Attestify
247
244
 
248
245
  def refute_instance_of(clazz, object, message = nil)
249
246
  if clazz.is_a?(Module)
250
- record_assert(!object.instance_of?(clazz)) do
251
- message || "Expected #{object.inspect} to not be an instance_of?(#{clazz.inspect})"
247
+ record_assert(!object.instance_of?(clazz), message) do
248
+ "Expected #{object.inspect} to not be an instance_of?(#{clazz.inspect})"
252
249
  end
253
250
  else
254
251
  pass
@@ -257,8 +254,8 @@ module Attestify
257
254
 
258
255
  def refute_kind_of(clazz, object, message = nil)
259
256
  if clazz.is_a?(Module)
260
- record_assert(!object.is_a?(clazz)) do
261
- message || "Expected #{object.inspect} to not be a kind_of?(#{clazz.inspect})"
257
+ record_assert(!object.is_a?(clazz), message) do
258
+ "Expected #{object.inspect} to not be a kind_of?(#{clazz.inspect})"
262
259
  end
263
260
  else
264
261
  pass
@@ -266,17 +263,17 @@ module Attestify
266
263
  end
267
264
 
268
265
  def refute_match(matcher, object, message = nil)
269
- record_assert(!(matcher =~ object)) { message || "Expected not #{matcher.inspect} =~ #{object.inspect}" }
266
+ record_assert(!(matcher =~ object), message) { "Expected not #{matcher.inspect} =~ #{object.inspect}" }
270
267
  end
271
268
 
272
269
  def refute_nil(object, message = nil)
273
- record_assert(!object.nil?) { message || "Expected #{object.inspect} to not be nil" }
270
+ record_assert(!object.nil?, message) { "Expected #{object.inspect} to not be nil" }
274
271
  end
275
272
 
276
273
  def refute_operator(left_operand, operator, right_operand, message = nil)
277
274
  if left_operand.respond_to?(operator)
278
- record_assert(!left_operand.send(operator, right_operand)) do
279
- message || "Expected not #{left_operand.inspect} #{operator} #{right_operand.inspect}"
275
+ record_assert(!left_operand.send(operator, right_operand), message) do
276
+ "Expected not #{left_operand.inspect} #{operator} #{right_operand.inspect}"
280
277
  end
281
278
  else
282
279
  pass
@@ -285,7 +282,7 @@ module Attestify
285
282
 
286
283
  def refute_predicate(object, predicate, message = nil)
287
284
  if object.respond_to?(predicate)
288
- record_assert(!object.send(predicate)) { message || "Expected not #{object.inspect} #{predicate}" }
285
+ record_assert(!object.send(predicate), message) { "Expected not #{object.inspect} #{predicate}" }
289
286
  else
290
287
  pass
291
288
  end
@@ -293,8 +290,8 @@ module Attestify
293
290
 
294
291
  def refute_respond_to(object, method, message = nil)
295
292
  if method.is_a?(String) || method.is_a?(Symbol)
296
- record_assert(!object.respond_to?(method)) do
297
- message || "Expected #{object.inspect} to not respond_to?(#{method.inspect})"
293
+ record_assert(!object.respond_to?(method), message) do
294
+ "Expected #{object.inspect} to not respond_to?(#{method.inspect})"
298
295
  end
299
296
  else
300
297
  pass
@@ -302,8 +299,8 @@ module Attestify
302
299
  end
303
300
 
304
301
  def refute_same(expected, actual, message = nil)
305
- record_assert(!expected.equal?(actual)) do
306
- message || "Expected #{expected.inspect} is not equal?(#{actual.inspect})"
302
+ record_assert(!expected.equal?(actual), message) do
303
+ "Expected #{expected.inspect} is not equal?(#{actual.inspect})"
307
304
  end
308
305
  end
309
306
 
@@ -323,11 +320,19 @@ module Attestify
323
320
 
324
321
  private
325
322
 
326
- def record_assert(passed)
323
+ def record_assert(passed, message = nil)
327
324
  if passed
328
325
  assertions.record(passed)
329
326
  else
330
- assertions.record(passed, yield, caller_locations(2))
327
+ assertions.record(passed, combine_message(message, yield), caller_locations(2))
328
+ end
329
+ end
330
+
331
+ def combine_message(message, default_message)
332
+ if message && !message.empty?
333
+ "#{message}\n#{default_message}"
334
+ else
335
+ default_message
331
336
  end
332
337
  end
333
338
  end
@@ -2,12 +2,11 @@ module Attestify
2
2
  module Assertions
3
3
  # A helper class for Attestify::Assertions#assert_output.
4
4
  class OutputAssertion
5
- def initialize(expected_stdout, expected_stderr, stdout, stderr, message)
5
+ def initialize(expected_stdout, expected_stderr, stdout, stderr)
6
6
  @expected_stdout = expected_stdout
7
7
  @expected_stderr = expected_stderr
8
8
  @stdout = stdout
9
9
  @stderr = stderr
10
- @message = message
11
10
  end
12
11
 
13
12
  def assert
@@ -15,7 +14,6 @@ module Attestify
15
14
  end
16
15
 
17
16
  def message
18
- return @message if @message
19
17
  messages = [stdout_message, stderr_message]
20
18
  "Expected #{messages.compact.join(", and ")}"
21
19
  end
@@ -23,14 +23,22 @@ module Attestify
23
23
  end
24
24
  end
25
25
 
26
+ def disable
27
+ @disabled = true
28
+ end
29
+
26
30
  def enable
27
31
  parse_options
28
32
  require_helper
29
- at_exit { start }
33
+ at_exit { at_exit_hook }
30
34
  end
31
35
 
32
36
  private
33
37
 
38
+ def at_exit_hook
39
+ start unless @disabled
40
+ end
41
+
34
42
  def parse_options
35
43
  option_parser.parse!(@args)
36
44
  end
@@ -11,6 +11,7 @@ module Attestify
11
11
  end
12
12
 
13
13
  def self.start
14
+ Attestify.disable_autorun
14
15
  new.start
15
16
  end
16
17
 
@@ -1,3 +1,3 @@
1
1
  module Attestify
2
- VERSION = "0.1.0.pre.2".freeze
2
+ VERSION = "0.1.0.pre.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attestify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.2
4
+ version: 0.1.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Virata-Stone
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler