Sha256: 4aac94358bd027d9cd147e833065aa2c7440428084ef5dd06154b91cf37910a4

Contents?: true

Size: 1.4 KB

Versions: 34

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'delegate'
require 'cucumber/multiline_argument/data_table'
require 'cucumber/multiline_argument/doc_string'

module Cucumber
  module MultilineArgument
    class << self
      def from_core(node)
        builder.wrap(node)
      end

      def from(argument, location = nil, content_type = nil)
        location ||= Core::Test::Location.of_caller
        case argument
        when String
          builder.doc_string(Core::Test::DocString.new(argument, content_type))
        when Array
          location = location.on_line(argument.first.line..argument.last.line)
          builder.data_table(argument.map(&:cells), location)
        when DataTable, DocString, None
          argument
        when nil
          None.new
        else
          raise ArgumentError, "Don't know how to convert #{argument.class} #{argument.inspect} into a MultilineArgument"
        end
      end

      private

      def builder
        @builder ||= Builder.new
      end

      class Builder
        def wrap(node)
          @result = None.new
          node.describe_to(self)
          @result
        end

        def doc_string(node, *_args)
          @result = DocString.new(node)
        end

        def data_table(node, *_args)
          @result = DataTable.new(node)
        end
      end
    end

    class None
      def append_to(array); end

      def describe_to(visitor); end
    end
  end
end

Version data entries

34 entries across 34 versions & 4 rubygems

Version Path
cucumber-9.2.1 lib/cucumber/multiline_argument.rb
cucumber-9.2.0 lib/cucumber/multiline_argument.rb
cucumber-9.1.2 lib/cucumber/multiline_argument.rb
cucumber-9.1.1 lib/cucumber/multiline_argument.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.1.0/lib/cucumber/multiline_argument.rb
cucumber-9.1.0 lib/cucumber/multiline_argument.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.0.2/lib/cucumber/multiline_argument.rb
cucumber-9.0.2 lib/cucumber/multiline_argument.rb
cucumber-9.0.1 lib/cucumber/multiline_argument.rb
cucumber-9.0.0 lib/cucumber/multiline_argument.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/multiline_argument.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/multiline_argument.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/multiline_argument.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/multiline_argument.rb
cucumber-8.0.0 lib/cucumber/multiline_argument.rb
cucumber-8.0.0.rc.1 lib/cucumber/multiline_argument.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-7.1.0/lib/cucumber/multiline_argument.rb
cucumber-7.1.0 lib/cucumber/multiline_argument.rb
cucumber-7.0.0 lib/cucumber/multiline_argument.rb
cucumber-6.1.0 lib/cucumber/multiline_argument.rb