Class: IOCheck::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/iocheck/test.rb

Defined Under Namespace

Classes: Command, Expected, RakeTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd) ⇒ Test

Returns a new instance of Test.



44
45
46
47
48
49
50
# File 'lib/iocheck/test.rb', line 44

def initialize(cmd)
  @command = Command.new(cmd)
  @policies = []
  @policies << Policy.by_bytes
  @repeat = 1
  @desc = ""
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



137
138
139
# File 'lib/iocheck/test.rb', line 137

def command
  @command
end

Instance Method Details

#actualObject



133
134
135
# File 'lib/iocheck/test.rb', line 133

def actual
  @command.actual
end

#by(policy) ⇒ Object



62
63
64
65
# File 'lib/iocheck/test.rb', line 62

def by(policy)
  @policies << policy
  self
end

#describe(desc) ⇒ Object



57
58
59
60
# File 'lib/iocheck/test.rb', line 57

def describe(desc)
  @desc = desc
  self
end

#do_run!Object



84
85
86
# File 'lib/iocheck/test.rb', line 84

def do_run!
  @command.run!(@repeat)
end

#expectedObject



129
130
131
# File 'lib/iocheck/test.rb', line 129

def expected
  Expected.new(self)
end

#locked?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/iocheck/test.rb', line 71

def locked?
  true if ::IOCheck.include?(name, "#{::IOCheck::Env["dir"]}/lock")
end

#nameObject



67
68
69
# File 'lib/iocheck/test.rb', line 67

def name
  ::IOCheck.name( @command.cmd )
end

#readyObject



95
96
97
# File 'lib/iocheck/test.rb', line 95

def ready
  RakeTask.new(self).create_tasks
end

#repeat(n) ⇒ Object



52
53
54
55
# File 'lib/iocheck/test.rb', line 52

def repeat(n)
  @repeat = n
  self 
end

#run!Object



88
89
90
91
92
93
# File 'lib/iocheck/test.rb', line 88

def run!
  do_run!
  @policies.each do |p|
    p.run!( self )
  end
end

#showObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/iocheck/test.rb', line 107

def show
  n_success = 0
  n_failure = 0
  log = []
  @policies.each do |p|
    if p.result.class == ::IOCheck::Policy::Success
	  n_success += 1
	elsif p.result.class == ::IOCheck::Policy::Failure
	  n_failure += 1
	  log << p.result.log
    else
	  raise Error
    end
  end
  puts "Command       : #{@command.cmd}"
  puts "Description   : #{@desc}"
  puts "Minor Success : #{n_success}"
  puts "Minor Failure : #{n_failure}"
  puts "# Log --------:"
  puts log.join("\n")
end

#succeeded?Boolean

Regard as success iff all the minor tests were end in success.

Returns:

  • (Boolean)


100
101
102
103
104
105
# File 'lib/iocheck/test.rb', line 100

def succeeded?
  @policies.each do |p|
    return false if p.result.class == ::IOCheck::Policy::Failure
  end
  return true
end

#update!Object



75
76
77
78
79
80
81
82
# File 'lib/iocheck/test.rb', line 75

def update!
  return if locked?

  do_run!
  f = File.open( ::IOCheck.writefile(name), "w")
  f.write( @command.actual.bytes )
  f.close
end