Class Uttk::Strategies::Iterate
In: lib/uttk/strategies/Iterate.rb
Parent: Collection

Iterate is a generic iteration strategy which bring the full power of Ruby to your test description.

The common use case is somthing like that:

my test:

  strategy: Iterate
  over:     aStructureWichSupportTheMethodMyEach
  with:     TheMethodMyEach # `uttk_each' by default
  iter:     MyIterator
  test:
     my sub test <<MyIterator:i>>:
         strategy: AnotherStrategy
         argument: <<MyIterator>>

In the real life you can use it like that:

my test suite:

   strategy: Iterator
   over: !filelist **/(*).yml
   iter: [path, basename]
   test:
      my sub test <<basename>>:
         strategy: Import
         input:    <<path>>

Methods

iter=   prologue  

Included Modules

Concrete Composite::Ordered

External Aliases

new_symtbl -> make_new_symtbl

Attributes

iterators  [R] 
new_symtbl  [R] 

Public Instance methods

[Source]

# File lib/uttk/strategies/Iterate.rb, line 91
      def iter= ( iter )
        @iter = iter
        iter = iter.to_s if iter.is_a? Symbol
        @iterators = case iter
          when Array      then iter.flatten
          when /^\[.*\]$/ then eval iter
          when /,/        then iter.split(/\s*,\s*/)
          else [iter]
        end
        unless iterators.all? { |it| it.is_a? String }
          raise ArgumentError, 'The iterator name or list of names ' +
                               "must be strings not (#{iterators.inspect})"
        end
      end

Protected Instance methods

Methods

[Source]

# File lib/uttk/strategies/Iterate.rb, line 50
      def prologue
        super

        if @test.is_a? Hash and @test.size == 1
          name, @attributes = @test.to_a.first
          @attributes[:name] = name
          @test = {}
        else
          name = @test.name
        end

        iter1 = iterators.first
        iteri = "#{iter1}:i"
        iterstar = "*#{iter1}"
        unless name.to_s =~ /<<.*>>/
          raise ArgumentError,
            "You cannot provide a static name like (#{name}) because when " +
            'iterating with this name all your tests will have the same ' +
            "name, to avoid this you can add <<#{iteri}>> to your name"
        end


        # Iterate over the object `@over' with the method `@with'.
        turn = 0
        @over.send(@with) do |*args|
          symtbl = make_new_symtbl
          symtbl[iteri] = turn
          symtbl[iterstar] = args
          args.each_with_index do |arg, i|
            symtbl["#{iter1}:#{i}"] = arg
            symtbl["#{iterators[i]}"] = arg if i < iterators.size
          end
          @new_symtbl = symtbl
          create @test
          turn += 1
        end

      end

[Validate]