spectre-core 1.12.2 → 1.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b85338c15a8c29d520ed02d2e6816a64c579b6edd654f3d047fbeddb4a5c0ea3
4
- data.tar.gz: 7be4646412f7dd3a971b21269215cddff5398cc12a50cd42dcd78a6bb70bf012
3
+ metadata.gz: fd2c5dd03f2ded27246d351696a749bf0f0fbb06ff87ecc27363873202ecb1ac
4
+ data.tar.gz: a17d75c2581c6f64f58664b78c68449936610f8fa9c6c313dc73011da59094c6
5
5
  SHA512:
6
- metadata.gz: 043d7b2bda42acf5687f09ce9468c8b3ce01566c5a61d3d1c753b9d61a126898b883f00b67be67d6d61600a85143475e8b041b31fdf42f02dee5aca48260037c
7
- data.tar.gz: 890154e9fabf2664d50289f5eeb212cd9ea508a967341d9b27a2ad5dd329600542a168352274d4a0ca09dbe9aa91f3bc22e6c855d36a80e1219ccac9132dd047
6
+ metadata.gz: 941692c923f0437410ad99376a1df249c81dd970c527445e9a4e3721554e35e2f6d10cca4f23293894df212f7bd5dc4b36ab1610b3351919a88dc9a6fdd8cd18
7
+ data.tar.gz: 7245b35708dc29ee1c0d2ec60ec10cbd39125f7302aa3e84962037e2e30824793290b59f70c51e8a7892d79780747697f8635c90b48e3ba4d2276015538bb8b3
data/exe/spectre CHANGED
@@ -9,8 +9,14 @@ require 'ectoplasm'
9
9
 
10
10
  require_relative '../lib/spectre'
11
11
 
12
+ def load_yaml file_path
13
+ yaml = File.read(file_path)
14
+ YAML.safe_load(yaml, aliases: true)
15
+ end
16
+
12
17
 
13
18
  DEFAULT_CONFIG = {
19
+ 'project' => nil,
14
20
  'config_file' => './spectre.yml',
15
21
  'environment' => 'default',
16
22
  'specs' => [],
@@ -21,8 +27,8 @@ DEFAULT_CONFIG = {
21
27
  'Spectre::Reporter::Console',
22
28
  ],
23
29
  'loggers' => [
24
- 'Spectre::Logger::Console',
25
- 'Spectre::Logger::File',
30
+ 'Spectre::Logging::Console',
31
+ 'Spectre::Logging::File',
26
32
  ],
27
33
  'log_file' => './logs/spectre_<date>.log',
28
34
  'log_format' => {
@@ -50,6 +56,8 @@ DEFAULT_CONFIG = {
50
56
  'spectre/helpers',
51
57
  'spectre/reporter/console',
52
58
  'spectre/reporter/junit',
59
+ 'spectre/reporter/vstest',
60
+ 'spectre/reporter/html',
53
61
  'spectre/logger/console',
54
62
  'spectre/logger/file',
55
63
  'spectre/assertion',
@@ -61,6 +69,7 @@ DEFAULT_CONFIG = {
61
69
  'spectre/http/basic_auth',
62
70
  'spectre/http/keystone',
63
71
  'spectre/resources',
72
+ 'spectre/async',
64
73
  ],
65
74
  'include' => [
66
75
 
@@ -72,20 +81,24 @@ DEFAULT_CONFIG = {
72
81
 
73
82
 
74
83
  cmd_options = {}
84
+ property_overrides = {}
85
+
86
+ $COMMAND = ['spectre'].concat(ARGV.clone).join(' ')
75
87
 
76
- opt_parser = OptionParser.new do |opts|
88
+ OptionParser.new do |opts|
77
89
  opts.banner = %{Spectre #{Spectre::VERSION}
78
90
 
79
- Usage: spectre [command] [options]
91
+ Usage: spectre [command] [options]
80
92
 
81
- Commands:
82
- list List specs
83
- run Run specs (default)
84
- show Print current environment settings
85
- dump Dumps the given environment in YAML format to console
86
- init Initializes a new spectre project
93
+ Commands:
94
+ list List specs
95
+ run Run specs (default)
96
+ show Print current environment settings
97
+ dump Dumps the given environment in YAML format to console
98
+ cleanup Will remove all generated files (e.g. logs and reports)
99
+ init Initializes a new spectre project
87
100
 
88
- Specific options:}
101
+ Specific options:}
89
102
 
90
103
  opts.on('-s SPEC,SPEC', '--specs SPEC,SPEC', Array, 'The specs to run') do |specs|
91
104
  cmd_options['specs'] = specs
@@ -132,17 +145,24 @@ Specific options:}
132
145
  end
133
146
 
134
147
  opts.on('-p KEY=VAL', '--property KEY=VAL', "Override config option. Use `spectre show` to get list of available options") do |option|
135
- key, val = option.split '='
136
- val = val.split ',' if DEFAULT_CONFIG[key].is_a? Array
137
- val = ['true', '1'].include? val if [true, false].include? DEFAULT_CONFIG[key]
148
+ key, val = option.split('=')
149
+ val = val.split(',') if DEFAULT_CONFIG[key].is_a? Array
150
+ val = ['true', '1'].include? val if [true, false].include?(DEFAULT_CONFIG[key])
138
151
  val = val.to_i if DEFAULT_CONFIG[key].is_a? Integer
139
- cmd_options[key] = val
140
152
 
141
- curr_opt = cmd_options
142
- (key.split '.').each do |k|
143
- curr_opt[k] = {} unless curr_opt.key? k
153
+ opt_path = key.split('.')
154
+
155
+ curr_opt = property_overrides
156
+
157
+ opt_path.each_with_index do |part, i|
158
+ if i == opt_path.count-1
159
+ curr_opt[part] = val
160
+ break
161
+ end
162
+
163
+ curr_opt[part] = {} unless curr_opt.key?(part)
164
+ curr_opt = curr_opt[part]
144
165
  end
145
- curr_opt = val
146
166
  end
147
167
 
148
168
  opts.separator "\nCommon options:"
@@ -173,20 +193,21 @@ cfg.deep_merge! DEFAULT_CONFIG
173
193
  global_config_file = File.join File.expand_path('~'), '.spectre'
174
194
 
175
195
  if File.exists? global_config_file
176
- global_options = YAML.load_file(global_config_file)
196
+ global_options = load_yaml(global_config_file)
177
197
  cfg.deep_merge! global_options if global_options
178
198
  end
179
199
 
180
200
  config_file = cmd_options['config_file'] || cfg['config_file']
181
201
 
182
202
  if File.exists? config_file
183
- file_options = YAML.load_file(config_file)
203
+ file_options = load_yaml(config_file)
184
204
  cfg.deep_merge! file_options
185
205
  Dir.chdir File.dirname(config_file)
186
206
  end
187
207
 
188
- cfg.deep_merge! cmd_options
208
+ cfg['project'] = File.basename(Dir.pwd) unless cfg['project']
189
209
 
210
+ cfg.deep_merge! cmd_options
190
211
 
191
212
  ###########################################
192
213
  # Load Environment
@@ -197,7 +218,7 @@ envs = {}
197
218
  read_env_files = {}
198
219
  cfg['env_patterns'].each do |pattern|
199
220
  Dir.glob(pattern).each do|f|
200
- spec_env = YAML.load_file(f) || {}
221
+ spec_env = load_yaml(f) || {}
201
222
 
202
223
  name = spec_env['name'] || 'default'
203
224
 
@@ -215,7 +236,7 @@ end
215
236
  # Merge partial environment configs with existing environments
216
237
  cfg['env_partial_patterns'].each do |pattern|
217
238
  Dir.glob(pattern).each do|f|
218
- partial_env = YAML.load_file(f)
239
+ partial_env = load_yaml(f)
219
240
  name = partial_env.delete('name') || 'default'
220
241
  next unless envs.key? name
221
242
 
@@ -224,7 +245,10 @@ cfg['env_partial_patterns'].each do |pattern|
224
245
  end
225
246
 
226
247
  env = envs[cfg['environment']]
227
- cfg.merge! env if env
248
+ cfg.deep_merge! env if env
249
+
250
+ # Merge property overrides after environment load to give it higher priority
251
+ cfg.deep_merge! property_overrides
228
252
 
229
253
 
230
254
  String.colored! if cfg['colored']
@@ -284,16 +308,15 @@ if 'run' == action
284
308
  # Initialize logger
285
309
  now = Time.now
286
310
 
287
- cfg['log_file'] = cfg['log_file'].frmt(
288
- {
289
- shortdate: now.strftime('%Y-%m-%d'),
290
- date: now.strftime('%Y-%m-%d_%H%M%S'),
291
- timestamp: now.strftime('%s'),
292
- subject: 'spectre',
293
- })
311
+ cfg['log_file'] = cfg['log_file'].frmt({
312
+ shortdate: now.strftime('%Y-%m-%d'),
313
+ date: now.strftime('%Y-%m-%d_%H%M%S'),
314
+ timestamp: now.strftime('%s'),
315
+ subject: 'spectre',
316
+ })
294
317
 
295
- log_dir = File.dirname cfg['log_file']
296
- FileUtils.makedirs log_dir unless Dir.exists? log_dir
318
+ log_dir = File.dirname(cfg['log_file'])
319
+ FileUtils.makedirs(log_dir)
297
320
 
298
321
  # Load Modules
299
322
 
@@ -330,11 +353,11 @@ if 'run' == action
330
353
 
331
354
  Spectre.configure(cfg)
332
355
 
333
- Spectre::Logger.debug! if cfg['debug']
356
+ Spectre::Logging.debug! if cfg['debug']
334
357
 
335
358
  cfg['loggers'].each do |logger_name|
336
359
  logger = Kernel.const_get(logger_name).new(cfg)
337
- Spectre::Logger.add(logger)
360
+ Spectre::Logging.add(logger)
338
361
  end if cfg['loggers']
339
362
 
340
363
  specs = Spectre.specs(cfg['specs'], cfg['tags'])
@@ -392,6 +415,24 @@ if 'dump' == action
392
415
  end
393
416
 
394
417
 
418
+ ###########################################
419
+ # Cleanup
420
+ ###########################################
421
+
422
+
423
+ if 'cleanup' == action
424
+ log_file_pattern = cfg['log_file'].gsub('<date>', '*')
425
+
426
+ Dir.glob(log_file_pattern).each do |log_file|
427
+ File.delete(log_file)
428
+ end
429
+
430
+ Dir.glob(File.join cfg['out_path'], '/*').each do |out_file|
431
+ File.delete(out_file)
432
+ end
433
+ end
434
+
435
+
395
436
  ###########################################
396
437
  # Init
397
438
  ###########################################
@@ -8,23 +8,23 @@ module Spectre
8
8
  module Assertion
9
9
  class ::Object
10
10
  def should_be(val)
11
- raise AssertionFailure.new("The value '#{self.to_s.trim}' should be '#{val.to_s.trim}'", val, self) unless self.to_s == val.to_s
11
+ raise AssertionFailure.new("'#{self.to_s.trim}' should be '#{val.to_s.trim}'", val, self) unless self.to_s == val.to_s
12
12
  end
13
13
 
14
14
  def should_be_empty
15
- raise AssertionFailure.new("The value '#{self.to_s.trim}' should be empty", nil, self) unless self.nil?
15
+ raise AssertionFailure.new("'#{self.to_s.trim}' should be empty", nil, self) unless self.nil?
16
16
  end
17
17
 
18
18
  def should_not_be(val)
19
- raise AssertionFailure.new("The value '#{self.to_s.trim}' should not be '#{val.to_s.trim}'", val, self) unless self.to_s != val.to_s
19
+ raise AssertionFailure.new("'#{self.to_s.trim}' should not be '#{val.to_s.trim}'", val, self) unless self.to_s != val.to_s
20
20
  end
21
21
 
22
22
  def should_not_exist
23
- raise AssertionFailure.new("The value '#{self.to_s.trim}' should not exist, but it does", val, self) unless self.to_s != nil
23
+ raise AssertionFailure.new("'#{self.to_s.trim}' should not exist, but it does", val, self) unless self.to_s != nil
24
24
  end
25
25
 
26
26
  def should_not_be_empty
27
- raise AssertionFailure.new('The value is empty', 'nothing', self) unless self != nil
27
+ raise AssertionFailure.new('empty value', 'nothing', self) unless self != nil
28
28
  end
29
29
 
30
30
  def or other
@@ -38,7 +38,7 @@ module Spectre
38
38
 
39
39
  class ::NilClass
40
40
  def should_be(val)
41
- raise AssertionFailure.new("There is nothing, but the value should be '#{val.to_s.trim}'", val, nil) unless val == nil
41
+ raise AssertionFailure.new("Value is empty, but it should be '#{val.to_s.trim}'", val, nil) unless val == nil
42
42
  end
43
43
 
44
44
  def should_be_empty
@@ -52,7 +52,7 @@ module Spectre
52
52
  end
53
53
 
54
54
  def should_not_be_empty
55
- raise AssertionFailure.new('The list is empty', 'nil')
55
+ raise AssertionFailure.new('Value is empty', 'nil')
56
56
  end
57
57
  end
58
58
 
@@ -66,21 +66,21 @@ module Spectre
66
66
  end
67
67
 
68
68
  def should_be_empty
69
- raise AssertionFailure.new('The object should be empty', nil, self) unless self.empty?
69
+ raise AssertionFailure.new('Object should be empty', nil, self) unless self.empty?
70
70
  end
71
71
 
72
72
  def should_not_be_empty
73
- raise AssertionFailure.new('The object should not be empty', nil, self) if self.empty?
73
+ raise AssertionFailure.new('Object should not be empty', nil, self) if self.empty?
74
74
  end
75
75
  end
76
76
 
77
77
  class ::OpenStruct
78
78
  def should_be_empty
79
- raise AssertionFailure.new('The object should be empty', nil, self) unless self.to_h.empty?
79
+ raise AssertionFailure.new('Object should be empty', nil, self) unless self.to_h.empty?
80
80
  end
81
81
 
82
82
  def should_not_be_empty
83
- raise AssertionFailure.new('The object should not be empty', nil, self) if self.to_h.empty?
83
+ raise AssertionFailure.new('Object should not be empty', nil, self) if self.to_h.empty?
84
84
  end
85
85
  end
86
86
 
@@ -93,7 +93,7 @@ module Spectre
93
93
  val = OpenStruct.new(val)
94
94
  end
95
95
 
96
- raise AssertionFailure.new("The list [#{list.join(', ').trim}] should contain '#{val.to_s.trim}'", val, list) unless list.include? val
96
+ raise AssertionFailure.new("[#{list.join(', ').trim}] should contain '#{val.to_s.trim}'", val, list) unless list.include? val
97
97
  end
98
98
 
99
99
  def should_not_contain(val)
@@ -104,37 +104,37 @@ module Spectre
104
104
  val = OpenStruct.new(val)
105
105
  end
106
106
 
107
- raise AssertionFailure.new("The list [#{list.join(', ').trim}] should not contain '#{val.to_s.trim}'", val, list) if list.include? val
107
+ raise AssertionFailure.new("[#{list.join(', ').trim}] should not contain '#{val.to_s.trim}'", val, list) if list.include? val
108
108
  end
109
109
 
110
110
  def should_be_empty
111
- raise AssertionFailure.new('The list is not empty', self) unless self.empty?
111
+ raise AssertionFailure.new('List is not empty', self) unless self.empty?
112
112
  end
113
113
 
114
114
  def should_not_be_empty
115
- raise AssertionFailure.new('The list is empty', self) if self.empty?
115
+ raise AssertionFailure.new('List is empty', self) if self.empty?
116
116
  end
117
117
  end
118
118
 
119
119
  class ::String
120
120
  def should_be(val)
121
- raise AssertionFailure.new("The text '#{self.trim}' should be '#{val.to_s.trim}'", val, self) unless self == val
121
+ raise AssertionFailure.new("'#{self.trim}' should be '#{val.to_s.trim}'", val, self) unless self == val
122
122
  end
123
123
 
124
124
  def should_be_empty
125
- raise AssertionFailure.new("The text '#{self.trim}' should be empty", nil, self) unless self.empty?
125
+ raise AssertionFailure.new("'#{self.trim}' should be empty", nil, self) unless self.empty?
126
126
  end
127
127
 
128
128
  def should_not_be(val)
129
- raise AssertionFailure.new("The text '#{self.trim}' should not be '#{val.to_s.trim}'", val, self) unless self != val
129
+ raise AssertionFailure.new("'#{self.trim}' should not be '#{val.to_s.trim}'", val, self) unless self != val
130
130
  end
131
131
 
132
132
  def should_not_be_empty
133
- raise AssertionFailure.new('The text should not be empty', 'nothing', self) unless not self.empty?
133
+ raise AssertionFailure.new('Text should not be empty', 'nothing', self) unless not self.empty?
134
134
  end
135
135
 
136
136
  def should_contain(value)
137
- raise AssertionFailure.new("The value is nil") if value.nil?
137
+ raise AssertionFailure.new("Value is nil") if value.nil?
138
138
 
139
139
  predicate = proc { |x| self.include? x.to_s }
140
140
  evaluation = SingleEvaluation.new(value)
@@ -142,19 +142,19 @@ module Spectre
142
142
 
143
143
  return if success
144
144
 
145
- raise AssertionFailure.new("The text '#{self.to_s.trim}' should contain #{evaluation.to_s}", evaluation, self)
145
+ raise AssertionFailure.new("'#{self.to_s.trim}' should contain #{evaluation.to_s}", evaluation, self)
146
146
  end
147
147
 
148
148
  def should_not_contain(val)
149
- raise AssertionFailure.new("The text '#{self.trim}' should not contain '#{val.trim}'", val, self) if self.include? val
149
+ raise AssertionFailure.new("'#{self.trim}' should not contain '#{val.trim}'", val, self) if self.include? val
150
150
  end
151
151
 
152
152
  def should_match(regex)
153
- raise AssertionFailure.new("The text '#{self.trim}' should match '#{val}'", regex, self) unless self.match(regex)
153
+ raise AssertionFailure.new("'#{self.trim}' should match '#{val}'", regex, self) unless self.match(regex)
154
154
  end
155
155
 
156
156
  def should_not_match(regex)
157
- raise AssertionFailure.new("The text '#{self.trim}' should not match '#{val}'", regex, self) if self.match(regex)
157
+ raise AssertionFailure.new("'#{self.trim}' should not match '#{val}'", regex, self) if self.match(regex)
158
158
  end
159
159
 
160
160
  alias :| :or
@@ -194,10 +194,6 @@ module Spectre
194
194
  end
195
195
 
196
196
  class OrEvaluation < Evaluation
197
- def initialize value, other
198
- super(value, other)
199
- end
200
-
201
197
  def call predicate
202
198
  eval_assertion(predicate, @value) or eval_assertion(predicate, @other)
203
199
  end
@@ -208,10 +204,6 @@ module Spectre
208
204
  end
209
205
 
210
206
  class AndEvaluation < Evaluation
211
- def initialize value, other
212
- super(value, other)
213
- end
214
-
215
207
  def call predicate
216
208
  eval_assertion(predicate, @value) and eval_assertion(predicate, @other)
217
209
  end
@@ -236,18 +228,26 @@ module Spectre
236
228
  @@success = nil
237
229
 
238
230
  def expect desc
231
+ status = 'unknown'
232
+
239
233
  begin
240
- Logger.log_process("expect #{desc}")
234
+ Logging.log_process("expect #{desc}")
241
235
  yield
242
- Logger.log_status(desc, Logger::Status::OK)
236
+ Logging.log_status(desc, Logging::Status::OK)
237
+ status = 'ok'
243
238
  rescue Interrupt => e
239
+ status = 'skipped'
244
240
  raise e
245
241
  rescue AssertionFailure => e
246
- Logger.log_status(desc, Logger::Status::FAILED)
242
+ Logging.log_status(desc, Logging::Status::FAILED)
243
+ status = 'failed'
247
244
  raise AssertionFailure.new(e.message, e.expected, e.actual, desc), cause: nil
248
245
  rescue Exception => e
249
- Logger.log_status(desc, Logger::Status::ERROR)
250
- raise AssertionFailure.new("An unexpected error occured during expectation: #{e.message}", nil, nil, desc), cause: e
246
+ Logging.log_status(desc, Logging::Status::ERROR)
247
+ status = 'error'
248
+ raise AssertionFailure.new("An unexpected error occurred during expectation: #{e.message}", nil, nil, desc), cause: e
249
+ ensure
250
+ Spectre::Runner.current.expectations.append([desc, status])
251
251
  end
252
252
  end
253
253
 
@@ -256,7 +256,7 @@ module Spectre
256
256
  prefix += " '#{desc}'" if desc
257
257
 
258
258
  begin
259
- Logger.log_info(prefix) if desc
259
+ Logging.log_info(prefix) if desc
260
260
  yield
261
261
  @@success = true
262
262
  @@logger.info("#{prefix} finished with success")
@@ -281,7 +281,7 @@ module Spectre
281
281
  end
282
282
 
283
283
  Spectre.register do |config|
284
- @@logger = ::Logger.new(config['log_file'], progname: 'spectre/assertion')
284
+ @@logger = Spectre::Logging::ModuleLogger.new(config, 'spectre/assertion')
285
285
  @@debug = config['debug']
286
286
  end
287
287
 
@@ -0,0 +1,31 @@
1
+ require_relative '../spectre'
2
+
3
+ Thread.abort_on_exception = true
4
+
5
+ module Spectre
6
+ module Async
7
+ class << self
8
+ @@threads = {}
9
+
10
+ def async name='default', &block
11
+ unless @@threads.key? name
12
+ @@threads[name] = []
13
+ end
14
+
15
+ @@threads[name] << Thread.new(&block)
16
+ end
17
+
18
+ def await name='default'
19
+ return unless @@threads.key? name
20
+
21
+ threads = @@threads[name].map { |x| x.join() }
22
+
23
+ @@threads.delete(name)
24
+
25
+ threads.map { |x| x.value }
26
+ end
27
+ end
28
+
29
+ Spectre.delegate :async, :await, to: self
30
+ end
31
+ end
data/lib/spectre/bag.rb CHANGED
@@ -12,7 +12,7 @@ module Spectre
12
12
  end
13
13
  end
14
14
 
15
- Spectre.register do |config|
15
+ Spectre.register do |_config|
16
16
  @@bag = OpenStruct.new
17
17
  end
18
18
 
data/lib/spectre/curl.rb CHANGED
@@ -301,13 +301,16 @@ module Spectre::Curl
301
301
 
302
302
  req_log = "[>] #{req_id} #{req['method']} #{uri}\n"
303
303
  req_log += header_to_s(req['headers'])
304
- req_log += try_format_json(req['body'], pretty: true)
304
+
305
+ if req[:body] != nil and not req[:body].empty?
306
+ req_log += try_format_json(req['body'], pretty: true)
307
+ end
305
308
 
306
309
  @@logger.info(req_log)
307
310
 
308
311
  start_time = Time.now
309
312
 
310
- stdin, stdout, stderr, wait_thr = Open3.popen3(sys_cmd)
313
+ _, stdout, stderr, wait_thr = Open3.popen3(sys_cmd)
311
314
 
312
315
  end_time = Time.now
313
316
 
@@ -329,7 +332,7 @@ module Spectre::Curl
329
332
 
330
333
  exit_code = wait_thr.value.exitstatus
331
334
 
332
- raise Exception.new "An error occured while executing curl:\n#{debug_log.lines.map { |x| not x.empty? }}" unless exit_code == 0
335
+ raise Exception.new "An error occurred while executing curl:\n#{debug_log.lines.map { |x| not x.empty? }}" unless exit_code == 0
333
336
 
334
337
  # Parse protocol, version, status code and status message from response
335
338
  match = /^(?<protocol>[A-Za-z0-9]+)\/(?<version>\d+\.?\d*) (?<code>\d+) (?<message>.*)/.match result
@@ -356,8 +359,8 @@ module Spectre::Curl
356
359
  end
357
360
 
358
361
  res_log = "[<] #{req_id} #{res[:code]} #{res[:message]} (#{end_time - start_time}s)\n"
359
- res_headers.each do |header|
360
- res_log += "#{header[0].to_s.ljust(30, '.')}: #{header[1].to_s}\n"
362
+ res_headers.each do |http_header|
363
+ res_log += "#{http_header[0].to_s.ljust(30, '.')}: #{http_header[1].to_s}\n"
361
364
  end
362
365
 
363
366
  if res[:body] != nil and not res[:body].empty?
@@ -377,11 +380,9 @@ module Spectre::Curl
377
380
  Spectre.register do |config|
378
381
  @@debug = config['debug']
379
382
 
380
- @@logger = ::Logger.new(config['log_file'], progname: 'spectre/curl')
381
- @@logger.level = @@debug ? Logger::DEBUG : Logger::INFO
383
+ @@logger = Spectre::Logging::ModuleLogger.new(config, 'spectre/curl')
382
384
 
383
385
  @@secure_keys = config['secure_keys'] || []
384
-
385
386
  @@curl_path = config['curl_path'] || 'curl'
386
387
 
387
388
  if config.key? 'http'
@@ -119,6 +119,10 @@ class ::Hash
119
119
  end
120
120
 
121
121
  class ::Array
122
+ def first_element
123
+ self[0]
124
+ end
125
+
122
126
  def last_element
123
127
  self[-1]
124
128
  end
@@ -42,8 +42,6 @@ module Spectre::Http
42
42
  net_req['X-Auth-Token'] = token
43
43
  end
44
44
 
45
- private
46
-
47
45
  def self.authenticate keystone_url, username, password, project, domain, cert
48
46
  auth_data = {
49
47
  auth: {
data/lib/spectre/http.rb CHANGED
@@ -27,9 +27,6 @@ module Spectre
27
27
  @@modules = []
28
28
 
29
29
  class HttpError < Exception
30
- def initialize message
31
- super message
32
- end
33
30
  end
34
31
 
35
32
  class SpectreHttpRequest < Spectre::DslClass
@@ -112,6 +109,10 @@ module Spectre
112
109
  @__req['use_ssl'] = true
113
110
  end
114
111
 
112
+ def no_log!
113
+ @__req['no_log'] = true
114
+ end
115
+
115
116
  def to_s
116
117
  @__req.to_s
117
118
  end
@@ -230,6 +231,10 @@ module Spectre
230
231
  # do nothing
231
232
  end
232
233
 
234
+ if str.length > 1000
235
+ str = str[0...1000] + "\n[...]"
236
+ end
237
+
233
238
  str
234
239
  end
235
240
 
@@ -314,7 +319,14 @@ module Spectre
314
319
 
315
320
  req_log = "[>] #{req_id} #{req['method']} #{uri}\n"
316
321
  req_log += header_to_s(net_req)
317
- req_log += try_format_json(req['body'], pretty: true) if req['body'] != nil and not req['body'].empty?
322
+
323
+ unless req['body'].nil? or req['body'].empty?
324
+ unless req['no_log']
325
+ req_log += try_format_json(req['body'], pretty: true)
326
+ else
327
+ req_log += '[...]'
328
+ end
329
+ end
318
330
 
319
331
  @@logger.info(req_log)
320
332
 
@@ -345,7 +357,14 @@ module Spectre
345
357
 
346
358
  res_log = "[<] #{req_id} #{net_res.code} #{net_res.message} (#{end_time - start_time}s)\n"
347
359
  res_log += header_to_s(net_res)
348
- res_log += try_format_json(net_res.body, pretty: true) unless net_res.body.nil? or net_res.body.empty?
360
+
361
+ unless net_res.body.nil? or net_res.body.empty?
362
+ unless req['no_log']
363
+ res_log += try_format_json(net_res.body, pretty: true)
364
+ else
365
+ res_log += '[...]'
366
+ end
367
+ end
349
368
 
350
369
  @@logger.info(res_log)
351
370
 
@@ -361,7 +380,7 @@ module Spectre
361
380
  end
362
381
 
363
382
  Spectre.register do |config|
364
- @@logger = ::Logger.new(config['log_file'], progname: 'spectre/http')
383
+ @@logger = Spectre::Logging::ModuleLogger.new(config, 'spectre/http')
365
384
  @@secure_keys = config['secure_keys'] || []
366
385
  @@debug = config['debug']
367
386
 
@@ -1,7 +1,7 @@
1
1
  require 'ectoplasm'
2
2
 
3
3
  module Spectre
4
- module Logger
4
+ module Logging
5
5
  class Console
6
6
  def initialize config
7
7
  raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'console'
@@ -113,8 +113,14 @@ module Spectre
113
113
  print_line('', txt)
114
114
  end
115
115
 
116
- def log_skipped _spec
117
- print_line('', Status::SKIPPED.grey)
116
+ def log_skipped _spec, message=nil
117
+ txt = Status::SKIPPED
118
+
119
+ unless message.nil?
120
+ txt += ' - ' + message
121
+ end
122
+
123
+ print_line('', txt.grey)
118
124
  end
119
125
 
120
126
  private