Sha256: 32fc2e352ca84ee909088423215a6acea52dd6d3a542c6cc62cff0413ac58592

Contents?: true

Size: 1.01 KB

Versions: 43

Compression:

Stored size: 1.01 KB

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 ? arg.match(@regexp) : nil
      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

43 entries across 43 versions & 5 rubygems

Version Path
cucumber-0.8.7 lib/cucumber/rb_support/rb_transform.rb
stefl-cucumber-0.10.1 lib/cucumber/rb_support/rb_transform.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/rb_support/rb_transform.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/rb_support/rb_transform.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/rb_support/rb_transform.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/rb_support/rb_transform.rb
cucumber-0.10.0 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.9.4 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.9.3 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.9.2 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.9.1 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.9.0 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.8.5 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.8.4 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.8.3 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.8.2 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.8.1 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.8.0 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.7.3 lib/cucumber/rb_support/rb_transform.rb
cucumber-0.7.2 lib/cucumber/rb_support/rb_transform.rb