Class: IOCheck::Policy

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

Direct Known Subclasses

Block

Defined Under Namespace

Classes: Block, Failure, Success

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePolicy

Returns a new instance of Policy.



4
5
6
# File 'lib/iocheck/policy.rb', line 4

def initialize
  @result = nil
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/iocheck/policy.rb', line 7

def result
  @result
end

Class Method Details

.by_bytesObject



47
48
49
50
51
52
53
54
# File 'lib/iocheck/policy.rb', line 47

def self.by_bytes
  Block.new do |test|
    # TODO: Better to show the diff to the user.
	succeed_if(
	  test.actual.bytes == test.expected.bytes,
      by_bytes_log( test ))
  end
end

.by_bytes_log(test) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/iocheck/policy.rb', line 56

def self.by_bytes_log( test )
  "Bytes not exactly matched.\n" +
  "--------------------------\n" +
  "expected :\n#{test.expected.bytes}\n" +
  "--------------------------\n" +
  "actual   :\n#{test.actual.bytes}" 
end

.succeed_if(pred, log) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/iocheck/policy.rb', line 39

def self.succeed_if( pred, log )
  if pred
    return Success.new
  else
    return Failure.new(log)
  end
end

Instance Method Details

#evaluate(test) ⇒ Object

Expected -> Actual -> Success or Failure

Raises:

  • (NoMethodError)


10
11
12
# File 'lib/iocheck/policy.rb', line 10

def evaluate( test )
  raise NoMethodError, "You must override this method."
end

#run!(test) ⇒ Object



14
15
16
# File 'lib/iocheck/policy.rb', line 14

def run!( test )
  @result = evaluate( test )
end