sinclair bain
2007-Nov-13 17:05 UTC
[rspec-users] Story problem if parenthesis used in Given, When, Then or And
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
David Chelimsky
2007-Nov-13 17:16 UTC
[rspec-users] Story problem if parenthesis used in Given, When, Then or And
On Nov 13, 2007 11:05 AM, sinclair bain <rspec.user at gmail.com> wrote:> 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.Please do not use this list for patches if you expect them to be incorporated. http://rspec.rubyforge.org/community/contribute.html http://rubyforge.org/tracker/?group_id=797 Cheers, David
sinclair bain
2007-Nov-13 17:54 UTC
[rspec-users] Story problem if parenthesis used in Given, When, Then or And
Submitted error #15608. On Nov 13, 2007 12:16 PM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Nov 13, 2007 11:05 AM, sinclair bain <rspec.user at gmail.com> wrote: > > 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. > > Please do not use this list for patches if you expect them to be > incorporated. > > http://rspec.rubyforge.org/community/contribute.html > http://rubyforge.org/tracker/?group_id=797 > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Cheers! sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071113/2f9fb2be/attachment.html