#186
Nov 02, 2009

Pickle with Cucumber

Pickle adds many convenient Cucumber steps for generating models. Also learn about table diffs in this episode.
Download (32.5 MB, 16:43)
alternative download for iPod & Apple TV (21.7 MB, 16:43)

Resources

rails store
sudo rake gems:install RAILS_ENV=test
script/generate cucumber
script/generate pickle
script/generate rspec_model product name:string price:decimal
rake db:migrate
rake db:test:clone
script/generate rspec_controller products show
cucumber features -q
# config/environments/test.rb
config.gem "rspec", :lib => false, :version => ">=1.2.9"
config.gem "rspec-rails", :lib => false, :version => ">=1.2.9"
config.gem "webrat", :lib => false, :version => ">=0.5.3"
config.gem "cucumber", :lib => false, :version => ">=0.4.3"
config.gem "pickle", :lib => false, :version => ">=0.1.21"

# product_steps.rb
Then(/^I should see products table$/) do |expected_table|
  html_table = table_at("#products").to_a
  html_table.map! { |r| r.map! { |c| c.gsub(/<.+?>/, '') } }
  expected_table.diff!(html_table)
end
# display_products.feature
Feature: Display Products
  In order to purchase the right product
  As a customer
  I want to browse products and see detailed information
  
  Scenario: Show product
    Given a product exists with name: "Milk", price: "2.99"
    When I go to the show page for that product
    Then I should see "Milk" within "h1"
    And I should see "$2.99"
  
  Scenario: List products
    Given the following products exist
      | name   | price |
      | Milk   | 2.99  |
      | Puzzle | 8.99  |
    When I go to path "/products"
    Then I should see products table
      | Milk   | $2.99 |
      | Puzzle | $8.99 |
    Then show me the page

RSS Feed for Episode Comments 56 comments

1. Tick Nov 02, 2009 at 00:34

incredible how you manage to always present stuff that I need at that very moment.


2. Igor Nov 02, 2009 at 00:40

Exactly what we need, thanks!


3. QuBiT Nov 02, 2009 at 00:46

Really useful and helpful tips about pickle, table-diffs and debugging cucumber.

Each one was just what I need to improve ^^.

So thanks Ryan and keep going ^^

HINT:
WHEN you get
Word verification response is incorrect, please try again.
THEN enable scripts for recaptcha.net to submit your comment
AS it did not show up otherwise.


4. Steve Nov 02, 2009 at 00:54

I think show me the page will come in very handy... Thanks for the tip! =)


5. Thibaud Guillaume-Gentil Nov 02, 2009 at 01:03

thanks for this great screencast (again!).

I'm also borred with the paths.rb file, so I have added this:

http://gist.github.com/224038

So you can write: "When I go to the products page" and it'll automagically be converted to products_page method. Great right?


6. Pieter Nov 02, 2009 at 01:58

Great screencast Ryan! Thanks.

How did you reformat that table in textmate?


7. Benjamin Lewis Nov 02, 2009 at 02:05

I haven't watched it yet, but SWEET!

Good choice!

Thanks Ryan.


8. Dom Nov 02, 2009 at 02:10

Yeah ditto what @Tick said. Your psychic powers are uncanny. Thanks for this and all the other extremely useful episodes.


9. David Nov 02, 2009 at 03:59

Thanks for the great tips in this episode - really timely (ok, stop reading our minds!).

The table reformat comes from Cucumber textmate bundle Command/Option '\'
(probably)


10. Rafael Nov 02, 2009 at 08:35

Hi Ryan,
thnx for another great episode...
....please give us more on BDD!

greez


11. Ian White Nov 02, 2009 at 09:47

@thibaud - did you try script/generate pickle paths ?

This adds mapping of expressions like 'the product's edit page' and even nested ones like 'the category's product's page'.

Cheers,
ian


12. Kurt Werle Nov 02, 2009 at 11:11

Then show me the page

Didn't know about that - thanks! Sure woulda saved me a lot of debugging time.


13. Tick Nov 02, 2009 at 14:01

I had to do this to get it working

config.gem 'ianwhite-pickle', :lib => 'pickle'


14. Henning Koch Nov 02, 2009 at 15:14

Pickle looks awesome.

I recently posted a similiar Gem called "Cucumber Factory" which shares a lot of ideas with Pickle but focuses on very natural syntax.

Check it out on GitHub:

http://github.com/makandra/cucumber_factory


15. dani Nov 02, 2009 at 15:43

Yes, its advanced, but you teach us during 186 episodes and that's a lot! Thanks for your work! Always a good motivation to continue studying...


16. Tick Nov 02, 2009 at 16:16

Nevermind my last comment. I seem to have missed the migration to gemcutter.


17. Michael MacDonald Nov 02, 2009 at 16:44

I love using Pickle. It really speeds up writing Cucumber features and lets me focus on the real issue and not waste time on setup. Check out the Pickle readme for more detail on what this gem can do. I've also written a post that provides some more detail too: http://rubyflare.com/2009/10/28/pickle-my-cucumber/


18. Boris Nov 02, 2009 at 18:41

I wonder if Rails-based website can be protected more or less automatically from all this alive "Capture breakers" who get live links from Railcasts to UGG boots, Blackberry cases, Weight loss and all other crap? Soon we can expect arrival of "Free Viagra / Cialis, ...", "Cheap pharmacy", ...

What makes me mad is that all these people care is to get real <a href>search term</a> which is just a basic SEO.


19. Stu Nov 02, 2009 at 23:01

Does pickle have a way to delete all records?

eg

Givin I have no xx records?


20. abhishek shukla Nov 03, 2009 at 01:59

Thanks really great stuff.


21. Michael MacDonald Nov 03, 2009 at 02:53

@stu Pickle doesn't have anything built to handle the deletion of records but it isn't hard to create your own step definition using Pickle to achieve this: http://gist.github.com/224945


22. Millisami Nov 03, 2009 at 09:41

As usual, Great cast!!
I tried to convert the table into lists as follows in the view:

<ul id="products">
<% @products.each do |product| -%>
  <li><%= h(product.name) %></li>
  <li><%= number_to_currency product.price %></li>
<% end -%>
</ul>

with step definition:

Then(/^I should see products table$/) do |expected_table|
  html_table = element_at("#products").to_table
  #html_table.map! { |r| r.map! { |c| c.gsub(/<.+?>/, '') } }
  expected_table.diff!(html_table)
end

But I could not figure out the error. Whats wrong with my setp def?? plz.


23. Shreyans Nov 04, 2009 at 14:29

Is there any way to control the junk posts like above? Please do something... these guys are annoying.

By the way-Great episode and thank you for that.


24. Boris Nov 04, 2009 at 18:47

Thanks Ryan for great Casts!
They truly open RoR for many people.

I think, you should stop presenting commentor's name as a link to provided site. This will repel all these buggers with their boots and replicas.

UGG boot seller: You are doing yourself a bad SEO here. In order to get any benefits from Link, it should be:
a) relevant to the rest of content on the page
b) people that read this content should want to read more and click your link

 None of this is happening here, why do you keep posting here? Spend your time reading about SEO and do the better job somewhere else more relevant to boots and replicas.


25. dani Nov 05, 2009 at 09:03

Pickle doesn't work form me!! I even download the episode source code and when i run "cucumber features", cucumber doesn't recognice the pickle steps!! Any suggestion?
 


26. Michael MacDonald Nov 06, 2009 at 04:17

@dani have you performed a ruby script/generate pickle? This will append pickle setup to features/support/env.rb and create a new file at features/step_definitions/pickle_steps.rb


27. Some Dude Nov 20, 2009 at 19:04

Can you do a railscast on how to block Ugg boot comment spam? That would be very helpful ;-)


28. 70-290 Nov 24, 2009 at 23:16

Thanks


29. John Ivanoff Dec 02, 2009 at 09:02

When I went from webrat 0.6.0 to 0.5.3 I didn't get

the undefined method `css_search' for Webrat::XML:Module (NoMethodError) (eval):2:in `table_at' error.

I saw a post on the IRC channel saying they removed css_search from webrat???
http://irclogger.com/cucumber/2009-10-28#1256763887

cheers


30. Niall Dec 17, 2009 at 00:41

Ryan your final tip was truly Steve Jobs-esque! Saving the best till last ;-)

Great episode as ever.


31. Torrent Search Engine Jan 13, 2010 at 05:46

Thanks for sharing, guys! You've done a good job indeed. To tell the truth, it took me much time to comprehend this information and to study all the codes thoroughly. I've learned much about table diffs indeed:) I like the intelligible way you present information so that it became comprehensible, transparent and accessible for ordinary people as I am. Well done!


32. Frank Lakatos Jan 16, 2010 at 08:43

Ryan, thanks for the video on this.

But how about addressing this with has many through? Right now, I am trying to make an account sign up form. My app has an Account which has_one company, Company has many users, and Account has many users through Company. I want this form to have fields for the Account, the Company, and the User. Rails is giving me all sort of problems trying to do this http://pastie.org/780854 . After seeing tons of people with the same question in forums with no answers, and not too much help in IRC, I think this would be a great talking point.

Thanks, let me know


33. jDeppen Feb 20, 2010 at 21:30

Initial setup problem was only a single quote issue:
Given a user exists with first_name: 'Jason'

this wouldn't work for me and I pulled my hair out just to find out that all I needed was double quotes:
Given a user exists with first_name: "Jason"

I submitted a lighthouse ticket:
http://is.gd/8QcDx


34. Philipp Kursawe Mar 03, 2010 at 23:46

Great screencast again.
The table_at does not seem to work anymore here.


35. Yuval Mar 14, 2010 at 21:50

For those of you wondering about aligning the table, it's a feature that comes with the textmate bundle. The most recent version does not support CMD+OPT+\ - instead hit CMD+S to save and align your tables.


36. SEO company Apr 30, 2010 at 23:19

Because Pickles (Cucumbers) were probably the first ones made...so it get its own name...and everything else is called pickled because they can't be called Pickles, but they are still referring to how they were made...the same process as reg. Pickles.


37. rehearsal dinner May 13, 2010 at 02:11

Because Pickles (Cucumbers) were probably the first ones made...so it get its own name...and everything else is called pickled because they can't be called Pickles, but they are still referring to how they were made...the same process as reg.


38. Senthil May 17, 2010 at 02:36

@Philipp Kursawe

Cucumber deprecated table_at and element at so do this:

html_table = tableish("table#products tr", "td" ).to_a

You're basically telling cucumber it is a table with product id, tr has header and td for columns.

And also looks like you don't need to escape symbols anymore.

GL.


39. Dog Supplies Jun 09, 2010 at 03:19

Very Very thanks for sharing


40. Hoca Jun 21, 2010 at 03:19

Great I think its wonderful


41. Connell Connor Jul 07, 2010 at 02:13

Have you ever bought a cucumber that doesn't have soft white seeds in the middle? I think they do need fertilising and that, perhaps, older varieties of cucumber did tend to become bitter.
<a href="http:/www.worldclik.com/">SEO</a>


42. Connell Connor Jul 07, 2010 at 02:15

Have you ever bought a cucumber that doesn't have soft white seeds in the middle? I think they do need fertilising and that, perhaps, older varieties of cucumber did tend to become bitter.


43. Connell Connor Jul 07, 2010 at 02:15

Have you ever bought a cucumber that doesn't have soft white seeds in the middle? I think they do need fertilising and that, perhaps, older varieties of cucumber did tend to become bitter.
 <a href="http:/www.worldclik.com/">SEO</a>


44. <a href="http://www.sportsjerseysshop.com">wholesale nfl jerseys</a> Jul 07, 2010 at 05:12

 it is interesting and informative article. This has been very helpful understanding a lot
of things. I’m sure a lot of other people will agree with me.


45. iPhone Ringtone Maker for mac Jul 20, 2010 at 18:47

this is a good one ahah


47. rapishare movie Jul 25, 2010 at 15:59

i really get what i need. thanks alot


47. Testking 642-832 Jul 26, 2010 at 03:30

thanks for sharing this useful information with us..


48. jerseys Jul 27, 2010 at 20:25

Really good post. thanks for share.


49. hotfile download Jul 27, 2010 at 23:28

its very useful and very need to my work. thanks


50. Sweet poems Jul 28, 2010 at 05:19

Its nice stuff.You done a great job.Thanks for sharing with us.Keep it up...


51. seo company Jul 30, 2010 at 05:18

Very helpful, thanks for sharing!


52. SEO Services Jul 31, 2010 at 11:38

Is there anywhere this information is available further? Such as a book or e-book?


53. timberlandbootsuk Aug 02, 2010 at 02:05

we provide our buyers with an efficient and manageable procurement process covering every phase of the international supply chain and

streamlining trade channels. Also welcome wholesaling, feedback now!


54. <a href=" http://www.maxexercises.com" > Wholesale cheap NHL, NFL,MLB, NBA jersey </a> Aug 03, 2010 at 00:26

it is really a great article. Thanks

 <a href=" http://www.maxexercises.com" > Wholesale cheap NHL, NFL,MLB, NBA jersey for sale </a>


55. Bar Tables and Chairs Aug 03, 2010 at 06:58

This is an excellent read, and some very helpful code. Thanks for that


56. sanejenny Aug 03, 2010 at 08:34

Cloud is a symbol of a weather, usually in a weather report they always use a cloud's picture as a symbol of any kinds of weather.


61. pool table Aug 05, 2010 at 02:30

Cloud is a symbol of a weather, usually in a weather report they always use a cloud's picture as a symbol of any kinds of weather.


62. cheap jerseys Aug 11, 2010 at 01:33

Nice post.Thank you for taking the time to publish this information very useful!
I’m still waiting for some interesting thoughts from your side in your next post thanks


63. search engine optimization services Aug 14, 2010 at 06:10

I really like how the theme of the website and how well you organized the content. It's a marvelous job I will come back and check you out sometime.


64. watch anime online Aug 15, 2010 at 04:17

the code is easy to understand.thanks for your efforts for writing this code


65. cheap jerseys Aug 15, 2010 at 19:32

Great article, I think you covered everything there. . . I would say freelancing is quite hard especially if you are not used to working on your own, can be quite hard to motivate yourself also. . . we all know what it is like to stare at the monitor.


66. error fix Aug 16, 2010 at 04:40

Your psychic powers are uncanny. Thanks for this and all the other extremely useful episodes.


67. Protein Powder Aug 18, 2010 at 12:36

Very different from anything I'm used to, but certainly appears to simplify things.


68. Jordan Air Retro Aug 19, 2010 at 00:07

This is an excellent read, and some very helpful code. I really like how the theme of the website and how well you organized the content.


69. 3 wire hall sensor Aug 20, 2010 at 05:52

Great post, thanks for the help!


70. wholesale new era hats Aug 20, 2010 at 20:20

I came to your article from another article and am really interested in this learning about this. , I feel strongly about information and love learning more on this. If possible, as you gain expertise, It is extremely helpful for me. would you mind updating your blog with more information?


71. replicahandbags Aug 23, 2010 at 18:05

I have always liked Outdoor movies, a child standing at the window, looked out from home to the following. Will be able to see the staff busy figure, a huge white cloth has a child hang up and soon will be able to see the movie.
<a href="http://www.breitlingreplicawatches.net/">breitling replica</a>


72. PDF to Images Converter Aug 24, 2010 at 23:09

Some times, to a certain need, we have to convert PDF to image for enjoyment.


73. Internet Marketing Aug 24, 2010 at 23:19

What about the book? Is there anywhere this information is available further?


74. Wholesale Electronics Aug 25, 2010 at 01:28

Discount Wholesale Electronics, Wholesale Cell Phones, Electronic Gadgets and More from the Best Dropship Wholesaler


75. louis vuitton shoes Aug 26, 2010 at 21:02

Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets


76. Sell Rentback Aug 27, 2010 at 07:10

Discuss the Clyde housing market prices….:smile:


77. Kerala Tour Packages Aug 28, 2010 at 01:17

I really like the theme of the website and how well you organized the content. It's a great job thanks


78. WillEric68 Aug 28, 2010 at 03:56

Popular railcasts stuff - I LIKE IT.


79. Funeral Insurance Aug 29, 2010 at 10:36

I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept.


80. louis vuitton neverfull Aug 29, 2010 at 22:52

Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets


81. snow boots Aug 30, 2010 at 20:43

By the way-Great episode and thank you for that.


82. roller blinds Aug 31, 2010 at 09:48

thanks dude, now you make it easy for me to understand and implement the concept.


83. irishpoetry Sep 01, 2010 at 04:29

I was very encouraged to find this site. I wanted to thank you for these useful tips. I definitely savored every little bit including all the comments and I have you bookmarked to check out new stuff you post.


84. louis vuitton sunglasses Sep 01, 2010 at 21:34

Very good post. Made me realize I was totally wrong about this issue. I figure that one learns something new everyday. Mrs Right learned her lesson! Nice, informative website by the way.


85. Personalised gifts Sep 02, 2010 at 06:10

Corporate gifts are given as a symbol of thanks. :lol:

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player
Give Back to Open Source