[rspec-users] How to write a step for a feature with a select control
dchelimsky at gmail.com
Tue Sep 16 15:09:37 EDT 2008
On Tue, Sep 16, 2008 at 2:00 PM, Damian Jones <lists at ruby-forum.com> wrote:
> 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|
> 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|
>> selects option_value, :from => field_name
> 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:
> Posted via http://www.ruby-forum.com/.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users