Class: GherkinFormat
- Inherits:
-
Object
- Object
- GherkinFormat
- Defined in:
- lib/gherkin_format.rb
Overview
format gherkin files
Defined Under Namespace
Classes: Features
Instance Method Summary collapse
- #format(file, options = {}) ⇒ Object
- #format_string(input, file = 'generated.feature') ⇒ Object
- #render(template, files) ⇒ Object
- #to_json(input, file = 'generated.feature') ⇒ Object
Instance Method Details
#format(file, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gherkin_format.rb', line 20 def format(file, = {}) input = File.read file output = format_string input, file return if input == output File.write(file, output) if .key? :replace puts "File #{file} is not formatted well." raise "File #{file} is not formatted well." end |
#format_string(input, file = 'generated.feature') ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/gherkin_format.rb', line 12 def format_string(input, file = 'generated.feature') io = StringIO.new formatter = Gherkin::Formatter::PrettyFormatter.new(io, true, false) parser = Gherkin::Parser::Parser.new(formatter, true) parser.parse(input, file, 0) io.string.split("\n").map(&:rstrip).join("\n") + "\n" end |
#render(template, files) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gherkin_format.rb', line 31 def render(template, files) features = [] files.each do |file| content = File.read file features.push to_json(content, file) end renderer = ERB.new File.read template features = Features.new features.flatten puts renderer.result features.binding_reference end |
#to_json(input, file = 'generated.feature') ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/gherkin_format.rb', line 42 def to_json(input, file = 'generated.feature') io = StringIO.new formatter = Gherkin::Formatter::JSONFormatter.new(io) parser = Gherkin::Parser::Parser.new(formatter, true) parser.parse(input, file, 0) formatter.done MultiJson.load io.string end |