Sha256: c8332de3daf1b8dfaaa092ec85db67b35c629ece74cd842c70e913260bb63a73

Contents?: true

Size: 1019 Bytes

Versions: 11

Compression:

Stored size: 1019 Bytes

Contents

module Cucumber
  module RbSupport
    # A Ruby Transform holds a Regexp and a Proc, and is created
    # by calling <tt>Transform in the <tt>support</tt> ruby files.
    # See also RbDsl.
    #
    # Example:
    #
    #   Transform /^(\d+) cucumbers$/ do |cucumbers_string|
    #     cucumbers_string.to_i
    #   end
    #
    class RbTransform
      class MissingProc < StandardError
        def message
          "Transforms must always have a proc with at least one argument"
        end
      end

      def initialize(rb_language, pattern, proc)
        raise MissingProc if proc.nil? || proc.arity < 1
        @rb_language, @regexp, @proc = rb_language, Regexp.new(pattern), proc
      end

      def match(arg)
        arg.match(@regexp)
      end

      def invoke(arg)
        if matched = match(arg)
          args = matched.captures.empty? ? [arg] : matched.captures
          @rb_language.current_world.cucumber_instance_exec(true, @regexp.inspect, *args, &@proc)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
middleman-0.10.17 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/rb_support/rb_transform.rb
middleman-0.10.16 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/rb_support/rb_transform.rb
middleman-0.10.15 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/rb_support/rb_transform.rb
rackjour-0.1.8 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/rb_support/rb_transform.rb
middleman-0.10.14 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/rb_support/rb_transform.rb
cucumber-0.4.4 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.4.3 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.4.2 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.4.1 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.4.0 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.4.0.rc1 lib/cucumber/rb_support/rb_transform.rb