Sha256: 74e53fe53d9771e12e2077ccc1ff0c75c998e9d2e92445aebce0c01b42e6596e

Contents?: true

Size: 1.25 KB

Versions: 86

Compression:

Stored size: 1.25 KB

Contents

require 'gherkin/rubify'
require 'gherkin/formatter/model'

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(Formatter::Model::Row === o)
        {
          "cells" => sexpify(o.cells),
          "comments" => sexpify(o.comments),
          "line" => o.line,
        }
      elsif(Formatter::Model::Comment === o)
        o.value
      elsif(Formatter::Model::Tag === o)
        o.name
      else
        o
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 4 rubygems

Version Path
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/gherkin-2.3.3/spec/gherkin/sexp_recorder.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/gherkin-2.3.3/spec/gherkin/sexp_recorder.rb
benhamill-gherkin-2.3.5 spec/gherkin/sexp_recorder.rb
gherkin-2.3.5 spec/gherkin/sexp_recorder.rb
gherkin-2.3.5-x86-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.3.5-x86-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.3.5-universal-dotnet spec/gherkin/sexp_recorder.rb
gherkin-2.3.5-java spec/gherkin/sexp_recorder.rb
gherkin-2.3.4 spec/gherkin/sexp_recorder.rb
gherkin-2.3.4-x86-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.3.4-x86-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.3.4-universal-dotnet spec/gherkin/sexp_recorder.rb
gherkin-2.3.4-java spec/gherkin/sexp_recorder.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/gherkin-2.2.9/spec/gherkin/sexp_recorder.rb
gherkin-2.3.3 spec/gherkin/sexp_recorder.rb
gherkin-2.3.3-x86-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.3.3-x86-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.3.3-universal-dotnet spec/gherkin/sexp_recorder.rb
gherkin-2.3.3-java spec/gherkin/sexp_recorder.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/gherkin-2.2.9/spec/gherkin/sexp_recorder.rb