Class: Assay::AE::Check::Proc

Inherits:
Object
  • Object
show all
Defined in:
lib/assay/ae/check.rb

Overview

The Check::Proc class encapsulates a labeled procedure for making assertions using the ok/no methods.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &check) ⇒ Proc

Setup new check procedure.



16
17
18
19
20
# File 'lib/assay/ae/check.rb', line 16

def initialize(options={}, &check)
  @name    = options[:name]
  @message = options[:message] || @name
  @check   = check
end

Instance Method Details

#call(*args) ⇒ Object

Call check procedure.



36
37
38
# File 'lib/assay/ae/check.rb', line 36

def call(*args)
  @check.call(*args)
end

#check!(args, negated, backtrace) ⇒ Object

Assert the check for the given arguments, negated or not. The backtrace says where the failure is reported.



65
66
67
# File 'lib/assay/ae/check.rb', line 65

def check!(args, negated, backtrace)
  Assertor.assert(call(*args), ::Kernel.proc { to_s(*args) }, negated, backtrace)
end

#message(&block) ⇒ Object



23
24
25
26
27
28
# File 'lib/assay/ae/check.rb', line 23

def message(&block)
  if block
    @message = block
  end
  @message
end

#message=(msg) ⇒ Object



31
32
33
# File 'lib/assay/ae/check.rb', line 31

def message=(msg)
  @message = msg
end

#no!(*args) ⇒ Object



59
60
61
# File 'lib/assay/ae/check.rb', line 59

def no!(*args)
  check!(args, true, caller)
end

#ok!(*args) ⇒ Object



54
55
56
# File 'lib/assay/ae/check.rb', line 54

def ok!(*args)
  check!(args, false, caller)
end

#to_s(*args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/assay/ae/check.rb', line 41

def to_s(*args)
  case @message
  when nil
    @name.to_s
  when ::Proc
    @message.call(*args)
  else
    # TODO: count %\S and apply `% args.map{|a|a.inspect}[0,count]`
    @message.to_s
  end
end