[rspec-devel] [ rspec-Bugs-15608 ] Story problem if parenthesis used in Given, When, Then or And

noreply at rubyforge.org noreply at rubyforge.org
Fri Nov 16 00:39:07 EST 2007


Bugs item #15608, was opened at 2007-11-13 17:50
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=15608&group_id=797

Category: rails plugin
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: sinclair  bain (sinclair)
>Assigned to: David Chelimsky (dchelimsky)
Summary: Story problem if parenthesis used in Given, When, Then or And

Initial Comment:
VERSION: rspec rails plugin current edge version
XP/Cygwin on XP

Hi,
I hit this when trying to use parenthesis in my stories ... (that'll teach me!).

If a scenario looks  like the following:

Story "User has story with parentheses", %{
  As a user
  I want parenthesis
  So that ... well I just do 
}, :type => RailsStory do

  Scenario "the Given has parentheses" do
    Given "parenthesis () in the given " do
    end

    When "anything" do
    end
   
    Then "The error occurred while evaluating nil.perform " do
    end
 
  end
end

This fails with the following:

The error occurred while evaluating nil.perform
  /cygdrive/c/development/sandbox/prototypes/proj/config/../vendor/plugins/rspec/lib/spec/story/world.rb: 60:in `store_and_call'
/cygdrive/c/development/sandbox/prototypes/proj/config/../vendor/plugins/rspec/lib/spec/story/world.rb: 92:in `Given'
stories/parenthesis_error_story.rb:10


Looks like the problem is in the Step#matches? method
since
    "abc (re) def".match /abc (re) def/
returns nil
however
    "abc (re) def".match /abc \(re\) def/
returns the match

The Step#assign_expression method when modifed as follows

        def assign_expression(name)
          expression = name.dup
          if String === expression
            while expression =~ /(\$\w*)/
              expression.gsub!($1, "(.*)")
            end
           
            expression.gsub! '(', '\('     # here
            expression.gsub! ')', '\)'     # here

          end
          @expression = Regexp.new ("^#{expression}$")
        end

Then the specs pass.

----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-11-16 05:39

Message:
Fixed in 2900.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=15608&group_id=797


More information about the rspec-devel mailing list