public
Created

  • Download Gist
csv-to-gherkin.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/env ruby
 
require 'csv'
 
class Converter
def initialize(feature)
@feature = feature
end
def to_gherkin
@feature.gsub!(/\|<<([\w\.]+)>>\|/) do |match|
rows = CSV.read($1).to_a
rows.inject('') do |output, row|
output << "| " << row.join(" |") << " |\n"
end
end
@feature
end
end
 
puts Converter.new(File.read(ARGV[0])).to_gherkin
my_data.csv
1 2 3
foo, bar, baz
apple, banana, strawberry
dog, cat, monkey
test.feature
Cucumber
1 2 3 4 5 6 7 8 9 10 11 12 13
Feature: My Feature
Scenario Outline: My scenario outline
Given <foo>
When <bar>
Then <baz>
 
Examples: Right here
| foo | bar | baz |
| aaa | bbb | ccc |
| 111 | 222 | 333 |
 
Examples: From elsewhere
|<<my_data.csv>>|

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.