spectre-core 1.11.0 → 1.12.0
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.
- checksums.yaml +4 -4
- data/exe/spectre +516 -524
- data/lib/spectre/assertion.rb +33 -14
- data/lib/spectre/bag.rb +21 -19
- data/lib/spectre/curl.rb +397 -391
- data/lib/spectre/diagnostic.rb +39 -29
- data/lib/spectre/environment.rb +30 -26
- data/lib/spectre/helpers.rb +133 -134
- data/lib/spectre/http/basic_auth.rb +5 -2
- data/lib/spectre/http/keystone.rb +76 -73
- data/lib/spectre/http.rb +82 -76
- data/lib/spectre/logger/console.rb +143 -142
- data/lib/spectre/logger/file.rb +1 -1
- data/lib/spectre/logger.rb +3 -1
- data/lib/spectre/mixin.rb +58 -34
- data/lib/spectre/reporter/console.rb +102 -104
- data/lib/spectre/reporter/junit.rb +100 -100
- data/lib/spectre/resources.rb +49 -46
- data/lib/spectre.rb +440 -438
- metadata +3 -3
data/lib/spectre/assertion.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative '../spectre'
|
2
|
+
|
1
3
|
require 'ostruct'
|
2
4
|
require_relative 'logger'
|
3
5
|
|
@@ -34,7 +36,6 @@ module Spectre
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
|
38
39
|
class ::NilClass
|
39
40
|
def should_be(val)
|
40
41
|
raise AssertionFailure.new("There is nothing, but the value should be '#{val.to_s.trim}'", val, nil) unless val == nil
|
@@ -55,7 +56,6 @@ module Spectre
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
|
59
59
|
class ::Hash
|
60
60
|
def should_contain(other)
|
61
61
|
raise AssertionFailure.new(other, self) unless self.merge(other) == self
|
@@ -64,8 +64,25 @@ module Spectre
|
|
64
64
|
def should_not_contain(other)
|
65
65
|
raise AssertionFailure.new(other, self) unless self.merge(other) != self
|
66
66
|
end
|
67
|
+
|
68
|
+
def should_be_empty
|
69
|
+
raise AssertionFailure.new("The object should be empty", nil, self) unless self.empty?
|
70
|
+
end
|
71
|
+
|
72
|
+
def should_not_be_empty
|
73
|
+
raise AssertionFailure.new("The object should not be empty", nil, self) if self.empty?
|
74
|
+
end
|
67
75
|
end
|
68
76
|
|
77
|
+
class ::OpenStruct
|
78
|
+
def should_be_empty
|
79
|
+
raise AssertionFailure.new("The object should be empty", nil, self) unless self.to_h.empty?
|
80
|
+
end
|
81
|
+
|
82
|
+
def should_not_be_empty
|
83
|
+
raise AssertionFailure.new("The object should not be empty", nil, self) if self.to_h.empty?
|
84
|
+
end
|
85
|
+
end
|
69
86
|
|
70
87
|
class ::Array
|
71
88
|
def should_contain(val)
|
@@ -99,7 +116,6 @@ module Spectre
|
|
99
116
|
end
|
100
117
|
end
|
101
118
|
|
102
|
-
|
103
119
|
class ::String
|
104
120
|
def should_be(val)
|
105
121
|
raise AssertionFailure.new("The text '#{self.trim}' should be '#{val.to_s.trim}'", val, self) unless self == val
|
@@ -145,7 +161,6 @@ module Spectre
|
|
145
161
|
alias :& :and
|
146
162
|
end
|
147
163
|
|
148
|
-
|
149
164
|
class Evaluation
|
150
165
|
def initialize value, other
|
151
166
|
@value = value
|
@@ -164,7 +179,6 @@ module Spectre
|
|
164
179
|
alias :& :and
|
165
180
|
end
|
166
181
|
|
167
|
-
|
168
182
|
class SingleEvaluation < Evaluation
|
169
183
|
def initialize value
|
170
184
|
super(value, nil)
|
@@ -179,7 +193,6 @@ module Spectre
|
|
179
193
|
end
|
180
194
|
end
|
181
195
|
|
182
|
-
|
183
196
|
class OrEvaluation < Evaluation
|
184
197
|
def initialize value, other
|
185
198
|
super(value, other)
|
@@ -194,7 +207,6 @@ module Spectre
|
|
194
207
|
end
|
195
208
|
end
|
196
209
|
|
197
|
-
|
198
210
|
class AndEvaluation < Evaluation
|
199
211
|
def initialize value, other
|
200
212
|
super(value, other)
|
@@ -209,7 +221,6 @@ module Spectre
|
|
209
221
|
end
|
210
222
|
end
|
211
223
|
|
212
|
-
|
213
224
|
class AssertionFailure < ExpectationFailure
|
214
225
|
attr_reader :expected, :actual
|
215
226
|
|
@@ -229,14 +240,11 @@ module Spectre
|
|
229
240
|
Logger.log_process("expect #{desc}")
|
230
241
|
yield
|
231
242
|
Logger.log_status(desc, Logger::Status::OK)
|
232
|
-
|
233
243
|
rescue Interrupt => e
|
234
244
|
raise e
|
235
|
-
|
236
245
|
rescue AssertionFailure => e
|
237
246
|
Logger.log_status(desc, Logger::Status::FAILED)
|
238
247
|
raise AssertionFailure.new(e.message, e.expected, e.actual, desc), cause: nil
|
239
|
-
|
240
248
|
rescue Exception => e
|
241
249
|
Logger.log_status(desc, Logger::Status::ERROR)
|
242
250
|
raise AssertionFailure.new("An unexpected error occured during expectation: #{e.message}", nil, nil, desc), cause: e
|
@@ -244,15 +252,21 @@ module Spectre
|
|
244
252
|
end
|
245
253
|
|
246
254
|
def observe desc = nil
|
255
|
+
prefix = "observing"
|
256
|
+
prefix += " '#{desc}'" if desc
|
257
|
+
|
247
258
|
begin
|
248
|
-
Logger.log_info(
|
259
|
+
Logger.log_info(prefix) if desc
|
249
260
|
yield
|
250
261
|
@@success = true
|
251
|
-
|
262
|
+
@@logger.info("#{prefix} finished with success")
|
252
263
|
rescue Interrupt => e
|
253
264
|
raise e
|
254
|
-
|
255
265
|
rescue Exception => e
|
266
|
+
error_message = "#{prefix} finished with failure: #{e.message}"
|
267
|
+
error_message += "\n" + e.backtrace.join("\n") if @@debug
|
268
|
+
|
269
|
+
@@logger.info(error_message)
|
256
270
|
@@success = false
|
257
271
|
end
|
258
272
|
end
|
@@ -266,6 +280,11 @@ module Spectre
|
|
266
280
|
end
|
267
281
|
end
|
268
282
|
|
283
|
+
Spectre.register do |config|
|
284
|
+
@@logger = ::Logger.new(config['log_file'], progname: 'spectre/assertion')
|
285
|
+
@@debug = config['debug']
|
286
|
+
end
|
287
|
+
|
269
288
|
Spectre.delegate :expect, :observe, :success?, :fail_with, to: self
|
270
289
|
end
|
271
290
|
end
|
data/lib/spectre/bag.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
require_relative '../spectre'
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Spectre
|
6
|
+
module Bag
|
7
|
+
class << self
|
8
|
+
@@bag
|
9
|
+
|
10
|
+
def bag
|
11
|
+
@@bag
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Spectre.register do |config|
|
16
|
+
@@bag = OpenStruct.new
|
17
|
+
end
|
18
|
+
|
19
|
+
Spectre.delegate :bag, to: self
|
20
|
+
end
|
21
|
+
end
|