Class: Cranium::TestFramework::CucumberTable

Inherits:
Object
  • Object
show all
Defined in:
lib/cranium/test_framework/cucumber_table.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array_of_hashes, column_types = {}) ⇒ CucumberTable

Returns a new instance of CucumberTable.



10
11
12
# File 'lib/cranium/test_framework/cucumber_table.rb', line 10

def initialize(array_of_hashes, column_types = {})
  @pattern_replacements, @data, @column_types = {}, array_of_hashes, column_types
end

Class Method Details

.from_ast_table(ast_table) ⇒ Object



3
4
5
6
# File 'lib/cranium/test_framework/cucumber_table.rb', line 3

def self.from_ast_table(ast_table)
  column_types, hashes = process_ast_table ast_table
  new remove_comment_columns(hashes), column_types
end

Instance Method Details

#accept(_) ⇒ Object



28
29
# File 'lib/cranium/test_framework/cucumber_table.rb', line 28

def accept(_)
end

#dataObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cranium/test_framework/cucumber_table.rb', line 39

def data
  column_count = @column_types.count

  evaluate_cells.tap do |array_of_hashes|
    array_of_hashes.define_singleton_method(:columns) do

      result = self.reduce(Hash.new { |hash, key| hash[key] = [] }) do |result, current_hash|
        current_hash.each { |key, value| result[key] << value }
        result
      end.values

      result == [] ? Array.new(column_count) { [] } : result
    end
  end
end

#data_arrayObject



57
58
59
# File 'lib/cranium/test_framework/cucumber_table.rb', line 57

def data_array
  data.map { |hash| hash.values.first }
end

#fieldsObject



33
34
35
# File 'lib/cranium/test_framework/cucumber_table.rb', line 33

def fields
  @data.first.keys
end

#to_step_definition_argObject



22
23
24
# File 'lib/cranium/test_framework/cucumber_table.rb', line 22

def to_step_definition_arg
  dup
end

#with_patterns(pattern_replacements) ⇒ Object



16
17
18
# File 'lib/cranium/test_framework/cucumber_table.rb', line 16

def with_patterns(pattern_replacements)
  self.tap { @pattern_replacements = pattern_replacements }
end