Class: GreenPepper::CollectionSetExample

Inherits:
CollectionExample show all
Defined in:
lib/greenpepper/example/collectionexample.rb

Direct Known Subclasses

SetOfExample, SubsetOfExample, SupersetOfExample

Constant Summary

Constants inherited from CollectionExample

GreenPepper::CollectionExample::FIRST_DATA_ROW

Constants inherited from ExampleWithFixture

ExampleWithFixture::EXAMPLE_NAME_COLUMN, ExampleWithFixture::EXAMPLE_NAME_ROW, ExampleWithFixture::FIRST_DATA_ROW, ExampleWithFixture::FIXTURE_NAME_COLUMN, ExampleWithFixture::FIXTURE_NAME_ROW, ExampleWithFixture::HEADER_ROW

Instance Attribute Summary

Attributes inherited from CollectionExample

#data, #headers_array

Attributes inherited from ExampleWithFixture

#fixture_arguments, #fixture_name, #headers

Instance Method Summary collapse

Methods inherited from CollectionExample

#add_header, #add_headers, #add_row, #do_execute

Methods inherited from ExampleWithFixture

#add_fixture_argument, #execute

Constructor Details

#initialize(fixture_name, found_handler, not_found_handler, remain_handler, error_handler = CollectionHandler::ERROR_HANDLER) ⇒ CollectionSetExample

Returns a new instance of CollectionSetExample.



176
177
178
179
180
181
182
183
184
# File 'lib/greenpepper/example/collectionexample.rb', line 176

def initialize (fixture_name, found_handler,
        not_found_handler, remain_handler,
        error_handler = CollectionHandler::ERROR_HANDLER)
  super fixture_name
  @found_handler = found_handler
  @not_found_handler = not_found_handler
  @remain_handler = remain_handler
  @error_handler = error_handler
end

Instance Method Details

#do_execute_collection(results, example_data, collection_data) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/greenpepper/example/collectionexample.rb', line 186

def do_execute_collection(results, example_data, collection_data)
  collection = collection_data.dup
  last_row_idx = example_data.size

  example_data.each_with_index do |example_row, row_index|
    index = collection.index(example_row)
    if index 
      @found_handler.call results, example_row, row_index
      collection.delete_at index 
    else
      @not_found_handler.call results, example_row, row_index
    end
  end

  collection.each do |remaining_row|
    if remaining_row.find { |value| value.is_a? Exception}
      @error_handler.call results, remaining_row, last_row_idx
    else
      @remain_handler.call results, remaining_row, last_row_idx
    end
    last_row_idx += 1
  end
end