Sha256: 0c06338f5b82ca10edf5adcb635ed0534cc0d79a0770c22fcfca271c0616b6a3

Contents?: true

Size: 1.34 KB

Versions: 168

Compression:

Stored size: 1.34 KB

Contents

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

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

    # We can't use method_missing - therubyracer isn't able to invoke methods like that.
    [:comment, :tag, :feature, :background, :scenario, :scenario_outline, :examples, :step, :doc_string, :row, :eof, :uri, :syntax_error].each do |event|
      define_method(event) do |*args|
        args  = rubify(args)
        args  = sexpify(args)
        @sexps << [event] + args
      end
    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)
      array = (defined?(JRUBY_VERSION) && Java.java.util.Collection === o) || 
              (defined?(V8) && V8::Array === o) ||
              Array === o
      if array
        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

168 entries across 163 versions & 9 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/gherkin-2.12.2/spec/gherkin/sexp_recorder.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/gherkin-2.12.2/spec/gherkin/sexp_recorder.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/gherkin-2.12.2/spec/gherkin/sexp_recorder.rb
gherkin-2.12.2 spec/gherkin/sexp_recorder.rb
gherkin-2.12.2-x86-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.12.2-x86-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.12.2-java spec/gherkin/sexp_recorder.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/gherkin-2.11.1/spec/gherkin/sexp_recorder.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/gherkin-2.11.1/spec/gherkin/sexp_recorder.rb
candlepin-api-0.4.0 bundle/ruby/gems/gherkin-2.11.1/spec/gherkin/sexp_recorder.rb
gherkin-2.12.1 spec/gherkin/sexp_recorder.rb
gherkin-2.12.1-x86-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.12.1-x86-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.12.1-java spec/gherkin/sexp_recorder.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/gherkin-2.11.6/spec/gherkin/sexp_recorder.rb
gherkin-2.12.0 spec/gherkin/sexp_recorder.rb
gherkin-2.12.0-x86-mingw32 spec/gherkin/sexp_recorder.rb
gherkin-2.12.0-x86-mswin32 spec/gherkin/sexp_recorder.rb
gherkin-2.12.0-java spec/gherkin/sexp_recorder.rb
gherkin-2.11.8 spec/gherkin/sexp_recorder.rb