diff --git a/lib/cucumber/step_match.rb b/lib/cucumber/step_match.rb index 40b25b5140..0039dcb3a1 100644 --- a/lib/cucumber/step_match.rb +++ b/lib/cucumber/step_match.rb @@ -12,7 +12,7 @@ def initialize(step_definition, name_to_match, name_to_report, step_arguments) end def args - @step_arguments.map{|g| g.val.freeze } + @step_arguments.map{|g| g.val } end def name @@ -20,7 +20,7 @@ def name end def invoke(multiline_arg) - all_args = args.dup + all_args = deep_clone_args multiline_arg.append_to(all_args) @step_definition.invoke(all_args) end @@ -80,6 +80,11 @@ def replace_arguments(string, step_arguments, format, &proc) def inspect #:nodoc: sprintf("#<%s:0x%x>", self.class, self.object_id) end + + private + def deep_clone_args + Marshal.load( Marshal.dump( args ) ) + end end class NoStepMatch #:nodoc: diff --git a/spec/cucumber/rb_support/rb_step_definition_spec.rb b/spec/cucumber/rb_support/rb_step_definition_spec.rb index 2a7f4e7147..83c084b3ec 100644 --- a/spec/cucumber/rb_support/rb_step_definition_spec.rb +++ b/spec/cucumber/rb_support/rb_step_definition_spec.rb @@ -18,7 +18,11 @@ module RbSupport end def run_step(text) - support_code.step_match(text).invoke(MultilineArgument::None.new) + step_match(text).invoke(MultilineArgument::None.new) + end + + def step_match(text) + support_code.step_match(text) end it "allows calling of other steps" do @@ -111,14 +115,17 @@ def run_step(text) }).to raise_error(Cucumber::ArityMismatchError) end - it "does not allow modification of args since it messes up pretty formatting" do + it "does not modify the step_match arg when arg is modified in a step" do dsl.Given(/My car is (.*)/) do |colour| colour << "xxx" end + step_name = "My car is white" + step_args = step_match(step_name).args + expect(-> { - run_step "My car is white" - }).to raise_error(RuntimeError, /can't modify frozen String/i) + run_step step_name + }).not_to change{ step_args.first } end it "allows puts" do