[rspec-users] Selecting a date with Webrat

Ben Mabey ben at benmabey.com
Thu Nov 13 23:48:11 EST 2008


aslak hellesoy wrote:
> On Thu, Nov 13, 2008 at 8:20 PM, David Chelimsky <dchelimsky at gmail.com> wrote:
>   
>> On Thu, Nov 13, 2008 at 1:14 PM, Ben Mabey <ben at benmabey.com> wrote:
>>     
>>> Mike Sassak wrote:
>>>       
>>>> Hi,
>>>>
>>>> I'm writing a scenario that needs to select date values from a form
>>>> created with Rails' form_for() method, and I'm looking for a clean way
>>>> to do that by specifying only the label (in this case "Date"), rather
>>>> than by selecting from each select list one by one.
>>>>
>>>> What I'd like to be able to write is:
>>>>
>>>> When I select "2008-November-13" from "Date"
>>>>
>>>> (or something similar), but this fails because the Date label doesn't
>>>> really apply to the individual select_lists. If I write instead
>>>>
>>>> When I select "2008" from "id_from_year_select_1i"
>>>>
>>>> it works, but then I not only need to do that once for each select,
>>>> but I need to specify the id, which could change if my model changes.
>>>> The first problem could be gotten around by writing a new webrat step
>>>> (corresponding to, say, "When I select the date "2008-November-13"
>>>> from "Date") but I would still need to specify the ids from each
>>>> select. Is there is a better way to do this?
>>>>
>>>> Thanks,
>>>> Mike
>>>> _______________________________________________
>>>> rspec-users mailing list
>>>> rspec-users at rubyforge.org
>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>>
>>>>         
>>> Hey Mike,
>>> What I have done in the past is used the following helper in my stories:
>>>
>>> def selects_time(id_prefix, time)
>>>  selects time.year, :from => "#{id_prefix}_1i"
>>>  selects time.strftime('%B'), :from => "#{id_prefix}_2i" # month name,
>>>  selects time.day, :from => "#{id_prefix}_3i"
>>>  selects time.hour.to_s.rjust(2,'0'), :from => "#{id_prefix}_4i"
>>>  selects time.min.to_s.rjust(2,'0'), :from => "#{id_prefix}_5i"
>>> end
>>>       
>> Somebody should wrap that up in a plugin! I've done that before too. I
>> can do it in March sometime, so if any of you can do it sooner, that'd
>> rock :)
>>
>>     
>
> Or better yet - add it to webrat proper and ask Bryan to pull it.
> (It's rails specific, so it should only be in the rails part of
> webrat).
>
> Aslak
>
>   

Good idea, guys!  And yes, I can take a hint. :)  Here is what I was 
able to get done tonight:

http://github.com/bmabey/webrat/commit/80d3eba59e386790ca67175e412317648c92191a

There are still some things I need to address and test more but the 
functionality is mostly there.

I'll report back if/when Bryan merges it into webrat and I'll create a 
step for it in cucumber's webrat_steps.rb.  You can also follow the 
progress on webrat's lighthouse:
http://webrat.lighthouseapp.com/projects/10503-webrat/tickets/36-add-selects_time-helper

-Ben

>>> I would use Time.parse to convert the string from the scenario to feed it
>>> into the helper.  In my particular case the id prefix could be inferred
>>> easily from th  the step, but your case might be different.  That should
>>> hopefully get you started though.
>>>
>>> -Ben
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>
>>>       
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>>     
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>   



More information about the rspec-users mailing list