[rspec-users] How to write a step for a feature with a select control

David Chelimsky dchelimsky at gmail.com
Tue Sep 16 11:06:39 EDT 2008

On Tue, Sep 16, 2008 at 9:55 AM, Damian Jones <lists at ruby-forum.com> wrote:
> David Chelimsky wrote:
>> 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
> HI David, I tried the method above but I am getting "You have a nil
> object when you didn't expect it"
> I can see that the following line is creating a new ArticleCategory with
> :name => "My article category" (BTW is it just coincidence that I have
> the field :name in my Article category table or is this a convention I
> should be following anyway?)

It is a convention that I tend to follow, but I wouldn't say that it's
a community wide convention, nor would I necessarily recommend it as
such. I'll just say it works well for me.

What I would recommend is that you use *some* convention when it comes
to things that are going to show up in lists :)

> field_name.gsub(' ','').constantize.find_or_create_by_name(option_value)
> But I don't see where this new ArticleCategory is getting bound to the
> select control.

That should be the responsibility of your application code - something
you would drive out with code examples rather than scenarios.

Make sense?


More information about the rspec-users mailing list