Sha256: 448cae058e2de6519c8bc194d87939846fc81767c2b1a1630145a05ccbe69529

Contents?: true

Size: 1.68 KB

Versions: 10

Compression:

Stored size: 1.68 KB

Contents

require 'stringio'
require 'gherkin'
require 'gherkin/formatter/pretty_formatter'

module PrettyPlease
  def pretty(source)
    io        = StringIO.new
    formatter = Gherkin::Formatter::PrettyFormatter.new(io, false)
    listener  = Gherkin::Parser::FormatterListener.new(formatter)
    parser    = Gherkin::Parser::Parser.new(listener, true)
    lexer     = Gherkin::I18nLexer.new(parser)
    lexer.scan(source, "test.feature", 0)
    io.string
  end
end

World(PrettyPlease)

Given /^I have Cucumber's source code next to Gherkin's$/ do
  @cucumber_home = File.dirname(__FILE__) + '/../../../cucumber'
  raise "No Cucumber source in #{@cucumber_home}" unless File.file?(@cucumber_home + '/bin/cucumber')
end

When /^I find all of the \.feature files$/ do
  @feature_paths = Dir["#{@cucumber_home}/**/*.feature"].sort
end

When /^I parse the prettified representation of each of them$/ do
  @error = false
  @feature_paths.each do |feature_path|
    pretty1 = nil
    pretty2 = nil
    begin
      pretty1 = pretty(IO.read(feature_path))
      pretty2 = pretty(pretty1)
      pretty2.should == pretty1
    rescue RSpec::Expectations::ExpectationNotMetError => e
      announce "=========="
      announce feature_path
      if(e.message =~ /(@@.*)/m)
        announce $1
        @error = true
        File.open("p1.feature", "wb") {|io| io.write(pretty1)}
        File.open("p2.feature", "wb") {|io| io.write(pretty2)}
      else
        announce "Identical, except for newlines"
      end
    rescue => e
      e.message << "\nFatal error happened when parsing #{feature_path}"
    end
  end
end

Then /^they should all be identical to the pretty output$/ do
  raise "Some features didn't do pretty well" if @error
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gherkin-2.0.1 features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.1-i386-mswin32 features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.1-i386-mingw32 features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.1-universal-dotnet features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.1-java features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.0 features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.0-i386-mswin32 features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.0-i386-mingw32 features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.0-universal-dotnet features/step_definitions/pretty_formatter_steps.rb
gherkin-2.0.0-java features/step_definitions/pretty_formatter_steps.rb