<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Rick Salsa&#187; Programming</title> <atom:link href="http://www.ricksalsa.com/category/programming/feed/" rel="self" type="application/rss+xml" /><link>http://www.ricksalsa.com</link> <description></description> <lastBuildDate>Thu, 03 Mar 2011 00:54:54 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.5</generator> <item><title>Date selectors for Capybara</title><link>http://www.ricksalsa.com/2010/11/04/date-selectors-for-capybara/</link> <comments>http://www.ricksalsa.com/2010/11/04/date-selectors-for-capybara/#comments</comments> <pubDate>Fri, 05 Nov 2010 06:50:23 +0000</pubDate> <dc:creator>Rick Salsa</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[bdd]]></category> <category><![CDATA[capybara]]></category> <category><![CDATA[cucumber]]></category> <category><![CDATA[rails]]></category><guid
isPermaLink="false">http://www.ricksalsa.com/?p=22</guid> <description><![CDATA[If you&#8217;ve used webrat with cucumber-rails, you&#8217;ll know that you have access to steps like: When I select &#34;[time]&#34; as the date and time When I select &#34;[datetime]&#34; as the &#34;[datetime_label]&#34; date and time When I select &#34;[time]&#34; as the time When I select &#34;[time]&#34; as the &#34;[time_label]&#34; time When I select &#34;[date]&#34; as the [...]]]></description> <content:encoded><![CDATA[<p>If you&#8217;ve used webrat with cucumber-rails, you&#8217;ll know that you have access to steps like:</p><pre class="brush: ruby; gutter: false;">
When I select &quot;[time]&quot; as the date and time
When I select &quot;[datetime]&quot; as the &quot;[datetime_label]&quot; date and time
When I select &quot;[time]&quot; as the time
When I select &quot;[time]&quot; as the &quot;[time_label]&quot; time
When I select &quot;[date]&quot; as the date
When I select &quot;[date]&quot; as the &quot;[date_label]&quot; date
</pre><p>Cucumber doesn&#8217;t have these steps available for Capybara (** as far as I can see) at this point. Some quick googling led me to creating the following step_definitions file:</p><pre class="brush: ruby; gutter: false;">
When /^(?:|I )select &quot;([^\&quot;]*)&quot; as the date$/ do |date|
  date = Chronic.parse(date)
  prefix = &quot;date&quot;

  select date.year.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:year]}&quot;
  select date.strftime('%B'), :from =&gt; &quot;#{prefix}_#{dt_suffix[:month]}&quot;
  select date.day.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:day]}&quot;
end

When /^(?:|I )select &quot;([^\&quot;]*)&quot; as the &quot;([^\&quot;]*)&quot; date$/ do |date, prefix|
  date = Chronic.parse(date)

  select date.year.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:year]}&quot;
  select date.strftime('%B'), :from =&gt; &quot;#{prefix}_#{dt_suffix[:month]}&quot;
  select date.day.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:day]}&quot;
end

When /^(?:|I )select &quot;([^\&quot;]*)&quot; as the date and time$/ do |date|
  date = Chronic.parse(date)
  prefix = &quot;date&quot;

  select date.year.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:year]}&quot;
  select date.strftime('%B'), :from =&gt; &quot;#{prefix}_#{dt_suffix[:month]}&quot;
  select date.day.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:day]}&quot;
  select date.hour.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:hour]}&quot;
  select date.min.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:minute]}&quot;
end

When /^(?:|I )select &quot;([^\&quot;]*)&quot; as the &quot;([^\&quot;]*)&quot; date and time$/ do |date, prefix|
  date = Chronic.parse(date)

  select date.year.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:year]}&quot;
  select date.strftime('%B'), :from =&gt; &quot;#{prefix}_#{dt_suffix[:month]}&quot;
  select date.day.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:day]}&quot;
  select date.hour.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:hour]}&quot;
  select date.min.to_s, :from =&gt; &quot;#{prefix}_#{dt_suffix[:minute]}&quot;
end

def dt_suffix
   {
    :year   =&gt; '1i',
    :month  =&gt; '2i',
    :day    =&gt; '3i',
    :hour   =&gt; '4i',
    :minute =&gt; '5i'
  }
end
</pre><p>So now you can test the rails date-time select helpers with the above. I&#8217;m sure there is probably a better way, but this works and was easy to implement. You&#8217;ll need to add the Chronic gem to your test group in Bundler for it to work.</p><p>It was inspired by jdfren&#8217;s <a
href="https://github.com/jdfrens/calvincs/blob/6c9e9cb9bd80cf001ffe150d1d8bedfc7adeab23/features/step_definitions/date_selection_steps.rb">code</a> on github.</p><div
class="sociable"><div
class="sociable_tagline"> Share:</div><ul><li
class="sociablefirst"><a
rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Date%20selectors%20for%20Capybara%20-%20http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F" title="Twitter"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://twitter.com/home/?status=tip%20@Techmeme%20http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F%20Date%20selectors%20for%20Capybara" title="Suggest to Techmeme via Twitter"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/techmeme.png" title="Suggest to Techmeme via Twitter" alt="Suggest to Techmeme via Twitter" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;t=Date%20selectors%20for%20Capybara" title="Facebook"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://posterous.com/share?linkto=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;title=Date%20selectors%20for%20Capybara&amp;selection=If%20you%27ve%20used%20webrat%20with%20cucumber-rails%2C%20you%27ll%20know%20that%20you%20have%20access%20to%20steps%20like%3A%0D%0A%0D%0A%5Bruby%20gutter%3D%22false%22%5D%0D%0AWhen%20I%20select%20%26quot%3B%5Btime%5D%26quot%3B%20as%20the%20date%20and%20time%0D%0AWhen%20I%20select%20%26quot%3B%5Bdatetime%5D%26quot%3B%20as%20the%20%26quot%3B%5Bdatetime_label%5D%26quot%3B%20date%20" title="Posterous"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/posterous.png" title="Posterous" alt="Posterous" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;title=Date%20selectors%20for%20Capybara&amp;notes=If%20you%27ve%20used%20webrat%20with%20cucumber-rails%2C%20you%27ll%20know%20that%20you%20have%20access%20to%20steps%20like%3A%0D%0A%0D%0A%5Bruby%20gutter%3D%22false%22%5D%0D%0AWhen%20I%20select%20%26quot%3B%5Btime%5D%26quot%3B%20as%20the%20date%20and%20time%0D%0AWhen%20I%20select%20%26quot%3B%5Bdatetime%5D%26quot%3B%20as%20the%20%26quot%3B%5Bdatetime_label%5D%26quot%3B%20date%20" title="del.icio.us"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;title=Date%20selectors%20for%20Capybara&amp;bodytext=If%20you%27ve%20used%20webrat%20with%20cucumber-rails%2C%20you%27ll%20know%20that%20you%20have%20access%20to%20steps%20like%3A%0D%0A%0D%0A%5Bruby%20gutter%3D%22false%22%5D%0D%0AWhen%20I%20select%20%26quot%3B%5Btime%5D%26quot%3B%20as%20the%20date%20and%20time%0D%0AWhen%20I%20select%20%26quot%3B%5Bdatetime%5D%26quot%3B%20as%20the%20%26quot%3B%5Bdatetime_label%5D%26quot%3B%20date%20" title="Digg"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;title=Date%20selectors%20for%20Capybara" title="StumbleUpon"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F" title="Technorati"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;title=Date%20selectors%20for%20Capybara&amp;source=Rick+Salsa+&amp;summary=If%20you%27ve%20used%20webrat%20with%20cucumber-rails%2C%20you%27ll%20know%20that%20you%20have%20access%20to%20steps%20like%3A%0D%0A%0D%0A%5Bruby%20gutter%3D%22false%22%5D%0D%0AWhen%20I%20select%20%26quot%3B%5Btime%5D%26quot%3B%20as%20the%20date%20and%20time%0D%0AWhen%20I%20select%20%26quot%3B%5Bdatetime%5D%26quot%3B%20as%20the%20%26quot%3B%5Bdatetime_label%5D%26quot%3B%20date%20" title="LinkedIn"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F" title="Identi.ca"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/identica.png" title="Identi.ca" alt="Identi.ca" class="sociable-hovers" /></a></li><li><a
rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;title=Date%20selectors%20for%20Capybara&amp;annotation=If%20you%27ve%20used%20webrat%20with%20cucumber-rails%2C%20you%27ll%20know%20that%20you%20have%20access%20to%20steps%20like%3A%0D%0A%0D%0A%5Bruby%20gutter%3D%22false%22%5D%0D%0AWhen%20I%20select%20%26quot%3B%5Btime%5D%26quot%3B%20as%20the%20date%20and%20time%0D%0AWhen%20I%20select%20%26quot%3B%5Bdatetime%5D%26quot%3B%20as%20the%20%26quot%3B%5Bdatetime_label%5D%26quot%3B%20date%20" title="Google Bookmarks"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li><li
class="sociablelast"><a
rel="nofollow"  target="_blank" href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fwww.ricksalsa.com%2F2010%2F11%2F04%2Fdate-selectors-for-capybara%2F&amp;title=Date%20selectors%20for%20Capybara" title="blogmarks"><img
src="http://www.ricksalsa.com/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a></li></ul></div> ]]></content:encoded> <wfw:commentRss>http://www.ricksalsa.com/2010/11/04/date-selectors-for-capybara/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 14/22 queries in 0.009 seconds using disk

Served from: www.ricksalsa.com @ 2012-05-21 08:45:47 -->
