Sha256: 823b0f51b9daa844394ad0828f5b5c765313a1cc7107f9d9fa7f2450c43e65b9

Contents?: true

Size: 1.45 KB

Versions: 45

Compression:

Stored size: 1.45 KB

Contents

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

module PrettyPlease
  def pretty(source)
    io       = StringIO.new
    listener = Gherkin::Formatter::PrettyFormatter.new(io)
    parser   = Gherkin::Parser::Parser.new(listener, true)
    lexer    = Gherkin::I18nLexer.new(parser)
    lexer.scan(source)
    io.rewind
    io.read
  end
end

World(PrettyPlease)

Given /^I have Cucumber's home dir defined in CUCUMBER_HOME$/ do
  @cucumber_home = ENV['CUCUMBER_HOME']
  raise "No CUCUMBER_HOME" if @cucumber_home.nil?
end

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

When /^I parse the prettified representation of each of them$/ do
  @errors = [['Path', 'Error']]
  @features.each do |feature|
    pretty1 = nil
    pretty2 = nil
    begin
      pretty1 = pretty(IO.read(feature))
      pretty2 = pretty(pretty1)
      pretty2.should == pretty1
    rescue Spec::Expectations::ExpectationNotMetError => e
      File.open("p1.feature", "wb") {|io| io.write(pretty1)}
      File.open("p2.feature", "wb") {|io| io.write(pretty2)}
      announce "========== #{feature}:"
      if(e.message =~ /(@@.*)/m)
        announce $1
      else
        announce "??? NO DIFF ???"
      end
      @errors << [feature, "See announced diff"]
    rescue => e
      @errors << [feature, e.message]
    end
  end
end

Then /^the following files should have errors:$/ do |table|
  table.diff!(@errors)
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
gherkin-1.0.30 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.30-i386-mswin32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.30-i386-mingw32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.30-universal-dotnet features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.30-java features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.29 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.29-i386-mswin32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.29-i386-mingw32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.29-java features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.28 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.28-i386-mswin32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.28-i386-mingw32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.28-java features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.27 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.27-i386-mswin32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.27-i386-mingw32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.27-java features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.26 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.26-i386-mswin32 features/step_definitions/pretty_formatter_steps.rb
gherkin-1.0.26-i386-mingw32 features/step_definitions/pretty_formatter_steps.rb