diff --git a/lib/cucumber/rb_support/rb_transform.rb b/lib/cucumber/rb_support/rb_transform.rb index a8e961cb10..d6d4fc26ff 100644 --- a/lib/cucumber/rb_support/rb_transform.rb +++ b/lib/cucumber/rb_support/rb_transform.rb @@ -34,11 +34,14 @@ def invoke(arg) end def to_s - strip_captures(strip_anchors(@regexp.source)) + convert_captures(strip_anchors(@regexp.source)) end private - + def convert_captures(regexp_source) + regexp_source.gsub(/(\()(?!\?:)/,'(?:') + end + def strip_captures(regexp_source) regexp_source. gsub(/(\()/, ''). diff --git a/spec/cucumber/rb_support/rb_transform_spec.rb b/spec/cucumber/rb_support/rb_transform_spec.rb index b0888ce9b7..fa3077bfbc 100644 --- a/spec/cucumber/rb_support/rb_transform_spec.rb +++ b/spec/cucumber/rb_support/rb_transform_spec.rb @@ -8,8 +8,12 @@ def transform(regexp) RbTransform.new(nil, regexp, lambda { |a| }) end describe "#to_s" do - it "removes the capture group parentheses" do - transform(/(a)bc/).to_s.should == "abc" + it "converts captures groups to non-capture groups" do + transform(/(a|b)bc/).to_s.should == "(?:a|b)bc" + end + + it "leaves non capture groups alone" do + transform(/(?:a|b)bc/).to_s.should == "(?:a|b)bc" end it "strips away anchors" do