Sha256: 272379c6ec4dbb71152694a0d7508cd9b5fd09e551c4c830014129661588f4a3

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 KB

Contents

require 'gherkin/rubify'
require 'gherkin/parser/row'

module Gherkin
  class SexpRecorder
    include Rubify
    
    def initialize
      @sexps = []
    end

    def method_missing(event, *args)
      event = :scenario_outline if event == :scenarioOutline # Special Java Lexer handling
      event = :py_string if event == :pyString # Special Java Lexer handling
      event = :syntax_error if event == :syntaxError # Special Java Lexer handling
      args  = rubify(args)
      args  = sexpify(args)
      @sexps << [event] + args
    end

    def to_sexp
      @sexps
    end

    # Useful in IRB
    def reset!
      @sexps = []
    end

    def errors
      @sexps.select { |sexp| sexp[0] == :syntax_error }
    end

    def line(number)
      @sexps.find { |sexp| sexp.last == number }
    end

    def sexpify(o)
      if (defined?(JRUBY_VERSION) && Java.java.util.Collection === o) || Array === o
        o.map{|e| sexpify(e)}
      elsif(Parser::Row === o)
        {
          "cells" => rubify(o.cells),
          "comments" => rubify(o.comments),
          "line" => o.line,
        }
      else
        o
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gherkin-2.0.2 spec/gherkin/sexp_recorder.rb
gherkin-2.0.2-i386-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.0.2-i386-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.0.2-universal-dotnet spec/gherkin/sexp_recorder.rb
gherkin-2.0.2-java spec/gherkin/sexp_recorder.rb
gherkin-2.0.1 spec/gherkin/sexp_recorder.rb
gherkin-2.0.1-i386-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.0.1-i386-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.0.1-universal-dotnet spec/gherkin/sexp_recorder.rb
gherkin-2.0.1-java spec/gherkin/sexp_recorder.rb
gherkin-2.0.0 spec/gherkin/sexp_recorder.rb
gherkin-2.0.0-i386-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.0.0-i386-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.0.0-universal-dotnet spec/gherkin/sexp_recorder.rb
gherkin-2.0.0-java spec/gherkin/sexp_recorder.rb