Sha256: d1c45b61f234d863d82cad53be6d6fc7654cfc585a81c0311fe0dcb4454789bb

Contents?: true

Size: 1.5 KB

Versions: 18

Compression:

Stored size: 1.5 KB

Contents

module Cucumber
  module Ast
    # Represents an inline argument in a step. Example:
    #
    #   Given the message
    #     """
    #     I like
    #     Cucumber sandwich
    #     """
    #
    # The text between the pair of <tt>"""</tt> is stored inside a PyString,
    # which is yielded to the StepDefinition block as the last argument.
    #
    # The StepDefinition can then access the String via the #to_s method. In the
    # example above, that would return: <tt>"I like\nCucumber sandwich"</tt>
    #
    # Note how the indentation from the source is stripped away.
    #
    class PyString #:nodoc:
      attr_accessor :file

      def self.default_arg_name
        "string"
      end

      def initialize(start_line, end_line, string, quotes_indent)
        @start_line, @end_line = start_line, end_line
        @string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent
      end

      def to_s
        @string.indent(-@quotes_indent)
      end

      def accept(visitor)
        return if Cucumber.wants_to_quit
        visitor.visit_py_string(to_s)
      end
      
      def arguments_replaced(arguments) #:nodoc:
        string = @string
        arguments.each do |name, value|
          value ||= ''
          string = string.gsub(name, value)
        end
        PyString.new(@start_line, @end_line, string, @quotes_indent)
      end

      def has_text?(text)
        @string.index(text)
      end

      # For testing only
      def to_sexp #:nodoc:
        [:py_string, to_s]
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 5 rubygems

Version Path
cucumber-0.6.3 lib/cucumber/ast/py_string.rb
davidtrogers-cucumber-0.6.2 lib/cucumber/ast/py_string.rb
cucumber-0.6.2 lib/cucumber/ast/py_string.rb
cucumber-0.6.1 lib/cucumber/ast/py_string.rb
cucumber-0.6.0 lib/cucumber/ast/py_string.rb
cucumber-0.5.3 lib/cucumber/ast/py_string.rb
cucumber-0.5.2 lib/cucumber/ast/py_string.rb
cucumber-0.5.1 lib/cucumber/ast/py_string.rb
cucumber-0.5.0 lib/cucumber/ast/py_string.rb
cucumber-0.4.5.rc2 lib/cucumber/ast/py_string.rb
kbaum-cucumber-0.4.5.pre lib/cucumber/ast/py_string.rb
cucumber-0.4.5.rc1 lib/cucumber/ast/py_string.rb
middleman-0.10.17 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/ast/py_string.rb
middleman-0.10.16 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/ast/py_string.rb
middleman-0.10.15 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/ast/py_string.rb
rackjour-0.1.8 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/ast/py_string.rb
middleman-0.10.14 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/ast/py_string.rb
cucumber-0.4.4 lib/cucumber/ast/py_string.rb