You just have to love this “syntax” ![]()
Story
#features/discussion.feature
Scenario: I add to an discussion
Given I am logged in
And a "Discussion" exists for "Festival" "1"
And I am on "Festival" "1"
When I fill in "Text" with "Halloo"
And I press "Send"
Then I should be on "Festival" "1"
And I should see "Halloo"
Steps
#features/step_definitions/common_steps.rb # On page/record Given /^I am on "([^"]*)"$/ do |path| visit path end Then /^I should be on "([^"]*)"$/ do |path| current_path.should == path end Given /^I am on "([^"]*)" "([^"]*)"$/ do |model,number| visit polymorphic_path(record_from_strings(model,number)) end Then /^I should be on "([^"]*)" "([^"]*)"$/ do |model,number| current_path.should == polymorphic_path(record_from_strings(model,number)) end # Existing Given /^a "([^"]*)" exists for "([^"]*)" "([^"]*)"$/ do |associated,model,number| record = record_from_strings(model,number) record.send(associated.underscore+'=',valid(associated)) record.save! end # Login Then /^I should be logged in$/ do should be_logged_in end Given /^I am logged in$/ do visit 'login' fill_in 'email', :with=>'quentin@example.com' fill_in 'password', :with=>'test' click_button 'Login' end # Support def current_path response.request.request_uri end def record_from_strings(model,number) model.constantize.find(:first,:offset=>number.to_i-1) end
env.rb
#features/support/env.rb #load all fixtures include AuthenticatedTestHelper #restful_authentification include ValidAttributes #http://github.com/grosser/valid_attributes

7 comments
Comments feed for this article
2008-12-31 at 21:45:35
Mark Wilden
Instead of doing “([^"]*)”, you can just do “(.*)”.
2008-12-31 at 23:47:36
pragmatig
yes, for simple cases i could,
but if want to have an additional
/^I am on “([^"]*)” “([^"]*)”$/ then “(.*)” would match –”a”– and –”a” “1″–
Since the (.*) is greedy and grabs –a” “1–
2009-01-01 at 21:09:56
Mark Wilden
/I am on “(.*)” “(.*)”/ does match ‘I am on “a” “1″‘. The first match is “a” and the second match is “1″. The greediness doesn’t matter since the regexp has to match all four quotes.
2009-01-01 at 21:17:02
pragmatig
yes thats true but the problem i am trying to solve is that then simple form also matches the Then I should be on “Festival” “1″
and when 2 ‘Then’s match –> exception
so we are both right
(.*) can be used for the complex form (Then I should be on “Festival” “1″) but ([^"]*) has to be used for the simple form
2009-01-02 at 18:47:39
Mark Wilden
Ah, I think I understand. Just to be sure, you’re saying that the problem is if you have
/I am on “(*.)”/
and
/I am on “(*.)” “(*.)”/
then they’ll both match
‘I am on “Festival” “1″‘
and having two possible matches will produce a Cucumber error. Thanks!
2009-01-02 at 19:08:21
pragmatig
yep you put it clearer then i could
2009-01-02 at 23:57:06
weemymn
просто респект.