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

sinclair bain rspec.user at gmail.com
Tue Nov 13 12:05:53 EST 2007


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.

This has been here for a couple of weeks just got round to debugging.

HTH
heers!
sinclair
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071113/772bad2b/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parenthesis_error_story.rb
Type: application/octet-stream
Size: 893 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071113/772bad2b/attachment.obj 


More information about the rspec-users mailing list