patir 0.5.7 → 0.5.8
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.
- data/History.txt +2 -0
- data/lib/patir/base.rb +1 -1
- data/lib/patir/command.rb +96 -93
- metadata +2 -2
data/History.txt
CHANGED
data/lib/patir/base.rb
CHANGED
data/lib/patir/command.rb
CHANGED
@@ -246,7 +246,7 @@ module Patir
|
|
246
246
|
break
|
247
247
|
end
|
248
248
|
end
|
249
|
-
end
|
249
|
+
end#each step
|
250
250
|
#we finished
|
251
251
|
@state.stop_time=Time.now
|
252
252
|
@state.status=running_status
|
@@ -377,10 +377,12 @@ module Patir
|
|
377
377
|
:output=>step.output,
|
378
378
|
:duration=>step.exec_time,
|
379
379
|
:error=>step.error,
|
380
|
-
:strategy=>step.strategy
|
381
|
-
|
382
|
-
|
383
|
-
|
380
|
+
:strategy=>step.strategy
|
381
|
+
}
|
382
|
+
#this way we don't have to compare all the step states we always get the worst last stable state
|
383
|
+
#:not_executed<:success<:warning<:success
|
384
|
+
unless @status==:running
|
385
|
+
@previous_status=@status
|
384
386
|
case step.status
|
385
387
|
when :running
|
386
388
|
@status=:running
|
@@ -396,97 +398,98 @@ module Patir
|
|
396
398
|
when :not_executed
|
397
399
|
@status=@previous_status
|
398
400
|
end
|
399
|
-
end
|
400
|
-
#produces a brief text summary for this status
|
401
|
-
def summary
|
402
|
-
sum=""
|
403
|
-
sum<<"#{@sequence_id}:" if @sequence_id
|
404
|
-
sum<<"#{@sequence_name}. " unless @sequence_name.empty?
|
405
|
-
sum<<"Status - #{@status}"
|
406
|
-
if !@step_states.empty? && @status!=:not_executed
|
407
|
-
sum<<". States #{@step_states.size}\nStep status summary:"
|
408
|
-
sorter=Hash.new
|
409
|
-
@step_states.each do |number,state|
|
410
|
-
#sort them by number
|
411
|
-
sorter[number]="\n\t#{number}:'#{state[:name]}' - #{state[:status]}"
|
412
|
-
end
|
413
|
-
1.upto(sorter.size) {|i| sum<<sorter[i] if sorter[i]}
|
414
|
-
end
|
415
|
-
return sum
|
416
|
-
end
|
417
|
-
def to_s
|
418
|
-
"'#{sequence_id}':'#{@sequence_name}' on '#{@sequence_runner}' started at #{@start_time}.#{@step_states.size} steps"
|
419
|
-
end
|
420
|
-
def exec_time
|
421
|
-
return @stop_time-@start_time if @stop_time
|
422
|
-
return 0
|
423
|
-
end
|
424
|
-
def name
|
425
|
-
return @sequence_name
|
426
|
-
end
|
427
|
-
def number
|
428
|
-
return @sequence_id
|
429
|
-
end
|
430
|
-
def output
|
431
|
-
return self.summary
|
432
|
-
end
|
433
|
-
def error
|
434
|
-
return ""
|
435
|
-
end
|
436
|
-
def executed?
|
437
|
-
return true unless @status==:not_executed
|
438
|
-
return false
|
439
|
-
end
|
401
|
+
end#unless running
|
440
402
|
end
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
# RubyCommand.new("prompt") do |cmd|
|
454
|
-
# cmd.output=""
|
455
|
-
# cmd.error=""
|
456
|
-
# if HighLine.agree("#{step.text}?")
|
457
|
-
# :success
|
458
|
-
# else
|
459
|
-
# :error
|
460
|
-
# end
|
461
|
-
# end
|
462
|
-
class RubyCommand
|
463
|
-
include Patir::Command
|
464
|
-
attr_reader :cmd,:working_directory
|
465
|
-
def initialize name,working_directory=nil,&block
|
466
|
-
@name=name
|
467
|
-
@working_directory=working_directory||"."
|
468
|
-
if block_given?
|
469
|
-
@cmd=block
|
470
|
-
else
|
471
|
-
raise "You need to provide a block"
|
403
|
+
#produces a brief text summary for this status
|
404
|
+
def summary
|
405
|
+
sum=""
|
406
|
+
sum<<"#{@sequence_id}:" if @sequence_id
|
407
|
+
sum<<"#{@sequence_name}. " unless @sequence_name.empty?
|
408
|
+
sum<<"Status - #{@status}"
|
409
|
+
if !@step_states.empty? && @status!=:not_executed
|
410
|
+
sum<<". States #{@step_states.size}\nStep status summary:"
|
411
|
+
sorter=Hash.new
|
412
|
+
@step_states.each do |number,state|
|
413
|
+
#sort them by number
|
414
|
+
sorter[number]="\n\t#{number}:'#{state[:name]}' - #{state[:status]}"
|
472
415
|
end
|
416
|
+
1.upto(sorter.size) {|i| sum<<sorter[i] if sorter[i]}
|
417
|
+
end
|
418
|
+
return sum
|
419
|
+
end
|
420
|
+
def to_s
|
421
|
+
"'#{sequence_id}':'#{@sequence_name}' on '#{@sequence_runner}' started at #{@start_time}.#{@step_states.size} steps"
|
422
|
+
end
|
423
|
+
def exec_time
|
424
|
+
return @stop_time-@start_time if @stop_time
|
425
|
+
return 0
|
426
|
+
end
|
427
|
+
def name
|
428
|
+
return @sequence_name
|
429
|
+
end
|
430
|
+
def number
|
431
|
+
return @sequence_id
|
432
|
+
end
|
433
|
+
def output
|
434
|
+
return self.summary
|
435
|
+
end
|
436
|
+
def error
|
437
|
+
return ""
|
438
|
+
end
|
439
|
+
def executed?
|
440
|
+
return true unless @status==:not_executed
|
441
|
+
return false
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
#This class allows you to wrap Ruby blocks and handle them like Command
|
446
|
+
#
|
447
|
+
#Provide a block to RubyCommand#new and you can execute the block using
|
448
|
+
#RubyCommand#run
|
449
|
+
#
|
450
|
+
#The block receives the instance of RubyCommand so you can set the output and error output.
|
451
|
+
#
|
452
|
+
#The return value of the block is assigned as the command status.
|
453
|
+
#
|
454
|
+
#== Examples
|
455
|
+
#An example (using the excellent HighLine lib) of a CLI prompt as a RubyCommand
|
456
|
+
# RubyCommand.new("prompt") do |cmd|
|
457
|
+
# cmd.output=""
|
458
|
+
# cmd.error=""
|
459
|
+
# if HighLine.agree("#{step.text}?")
|
460
|
+
# :success
|
461
|
+
# else
|
462
|
+
# :error
|
463
|
+
# end
|
464
|
+
# end
|
465
|
+
class RubyCommand
|
466
|
+
include Patir::Command
|
467
|
+
attr_reader :cmd,:working_directory
|
468
|
+
def initialize name,working_directory=nil,&block
|
469
|
+
@name=name
|
470
|
+
@working_directory=working_directory||"."
|
471
|
+
if block_given?
|
472
|
+
@cmd=block
|
473
|
+
else
|
474
|
+
raise "You need to provide a block"
|
473
475
|
end
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
rescue
|
483
|
-
error<<"RubyCommand failed:"
|
484
|
-
error<<"#{$!}"
|
485
|
-
@status=:error
|
486
|
-
ensure
|
487
|
-
@exec_time=Time.now-t1
|
476
|
+
end
|
477
|
+
#Runs the associated block
|
478
|
+
def run
|
479
|
+
@run=true
|
480
|
+
begin
|
481
|
+
t1=Time.now
|
482
|
+
Dir.chdir(@working_directory) do
|
483
|
+
@status=@cmd.call(self)
|
488
484
|
end
|
489
|
-
|
485
|
+
rescue
|
486
|
+
error<<"RubyCommand failed:"
|
487
|
+
error<<"#{$!}"
|
488
|
+
@status=:error
|
489
|
+
ensure
|
490
|
+
@exec_time=Time.now-t1
|
490
491
|
end
|
492
|
+
return @status
|
491
493
|
end
|
492
|
-
end
|
494
|
+
end
|
495
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vassilis Rizopoulos
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-18 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|