On Tue, Sep 16, 2008 at 2:00 PM, Damian Jones <[EMAIL PROTECTED]> wrote: > OK, > > I managed to get it to work using David's option 1. > >> 1. add the data in a previous step >> >> Given /an? (.*) named "(.*)"$/ do |class_name, object_name| >> class_name.gsub(' >> ','').constantize.find_or_create_by_name(object_name) >> end > > > My Scenario now goes: > > Given an Article Category named "My Article Category" > And I am on the new article page > When I fill in "Title" with "My article title" > And I fill in "Summary" with "My article summary" > And I fill in "Body" with "My article body" > And I check "Is Live" > And I pick "My Article Category" from Article Category > And I press "Create" > Then I should see "My article title" > And I should see "My article summary" > And I should see "My article body" > And I should see "Article is live" > And I should see "My Article Category" > > And that works. I could not get it to work using David's option 2
That's a matter of order of events. The html is loaded when you say "And I am on the new article page" so it's too late to add new data for display on that page. Make sense? >> 2. add the data in the current step >> >> When(/^I pick "(.*)" from (.*)$/) do |option_value, field_name| >> field_name.gsub(' >> ','').constantize.find_or_create_by_name(option_value) >> selects option_value, :from => field_name >> end > > Have I broken any rules, or is that OK? This is OK, but falls under what some call an imperative style (as opposed to declarative). While it can be useful to have a scenario or two for any given feature that goes field by field, the declarative style helps you keep things a bit more expressive, more high level, less verbose, and less brittle. Check out these resources: http://blog.davidchelimsky.net/assets/2008/7/14/IntegrationTestingWithRSpec.pdf.zip http://www.brynary.com/uploads/Story_Driven_Development.pdf Cheers, David > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users