Sha256: 8e48c21914f97ce636e68b310afdf9b01438556c7ce4b3288662785887173ffe
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
require 'cucumber/step_match' require 'cucumber/core_ext/string' require 'cucumber/core_ext/proc' module Cucumber module RbSupport # A Ruby Step Definition holds a Regexp and a Proc, and is created # by calling <tt>Given</tt>, <tt>When</tt> or <tt>Then</tt> # in the <tt>step_definitions</tt> ruby files. See also RbDsl. # # Example: # # Given /I have (\d+) cucumbers in my belly/ do # # some code here # end # class RbStepDefinition include LanguageSupport::StepDefinitionMethods class MissingProc < StandardError def message "Step definitions must always have a proc" end end attr_reader :proc, :regexp def initialize(rb_language, pattern, proc) raise MissingProc if proc.nil? if String === pattern p = pattern.gsub(/\$\w+/, '(.*)') # Replace $var with (.*) pattern = Regexp.new("^#{p}$") end @rb_language, @regexp, @proc = rb_language, pattern, proc end def invoke(args) args = args.map{|arg| Ast::PyString === arg ? arg.to_s : arg} begin args = @rb_language.execute_transforms(args) @rb_language.current_world.cucumber_instance_exec(true, regexp.inspect, *args, &@proc) rescue Cucumber::ArityMismatchError => e e.backtrace.unshift(self.backtrace_line) raise e end end def file_colon_line @proc.file_colon_line end def file @file ||= file_colon_line.split(':')[0] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aslakhellesoy-cucumber-0.3.101.2 | lib/cucumber/rb_support/rb_step_definition.rb |