Class Uttk::Strategies::Block
In: lib/uttk/strategies/Block.rb
Parent: IOBased

I can evaluate a Ruby block. The test fails if block raise an excption or return a false/nil value.

Methods

assertion   create   prologue   run_impl   test=  

Included Modules

Concrete

Public Class methods

[Source]

# File lib/uttk/strategies/Block.rb, line 17
      def self.create ( *a, &block )
        raise ArgumentError, 'need a block' if block.nil?
        strategy = new(*a)
        strategy.test = block
        strategy
      end

Public Instance methods

[Source]

# File lib/uttk/strategies/Block.rb, line 25
      def test=(block1=nil, &block2)
        if block2
          @test = block2
        elsif not block1.nil?
          @test = block1
        else
          raise ArgumentError, 'no block given'
        end
      end

Protected Instance methods

[Source]

# File lib/uttk/strategies/Block.rb, line 61
      def assertion
        fail @raised_exception if @raised_exception
        pass if @result
        fail @result
      end

[Source]

# File lib/uttk/strategies/Block.rb, line 36
      def prologue
        super

        if @test.is_a?(String)
          str = @test.dup
          @test = lambda { eval str.do_symtbl_gsub(@symtbl) }
        end

        @result, @raised_exception = nil, nil
      end

[Source]

# File lib/uttk/strategies/Block.rb, line 49
      def run_impl
        begin
          @result = @test[*@args]
        rescue Status => ex
          raise ex
        rescue Exception => ex
          @raised_exception = ex
        end
      end

[Validate]