#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 35 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. yeni müzik Dec 29, 2009 at 15:46

This is one of those "clever" solutions that will only cause


33. 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!


33. 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


34. manolo blahnik Jan 24, 2010 at 23:04

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!


35. cheap adidas shoes Jan 31, 2010 at 19:10

Adidas Shoes Online Shop-Hot Selling Adidas Shoes & Cheap Adidas Shoes.
like

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