#159
Apr 27, 2009

More on Cucumber

There is a lot more to Cucumber than I showed in an earlier episode. See how to refactor complex scenarios in this episode.
Tags: testing tools
Download (31.6 MB, 18:56)
alternative download for iPod & Apple TV (22.5 MB, 18:56)

Resources

sudo rake gems:install RAILS_ENV=test
cucumber features -n -t focus
cucumber features -n -t \~focus
@focus
Feature: Manage Users
  In order to manage user details
  As a security enthusiast
  I want to edit user profiles only when authorized
  
  Scenario Outline: Show or hide edit profile link
    Given the following user records
      | username | password | admin |
      | bob      | secret   | false |
      | admin    | secret   | true  |
    Given I am logged in as "<login>" with password "secret"
    When I visit profile for "<profile>"
    Then I should <action>
    
    Examples:
      | login | profile | action                 |
      | admin | bob     | see "Edit Profile"     |
      | bob   | bob     | see "Edit Profile"     |
      |       | bob     | not see "Edit Profile" |
      | bob   | admin   | not see "Edit Profile" |
# config/environments/test.rb
config.gem "cucumber", :lib => false, :version => ">=0.3.0"

# features/support/env.rb
require "#{Rails.root}/spec/factories"

# features/support/paths.rb
World(NavigationHelpers)

# features/step_definitions/user_steps.rb
Given /^the following (.+) records?$/ do |factory, table|
  table.hashes.each do |hash|
    Factory(factory, hash)
  end
end

Given /^I am logged in as "([^\"]*)" with password "([^\"]*)"$/ do |username, password|
  unless username.blank?
    visit login_url
    fill_in "Username", :with => username
    fill_in "Password", :with => password
    click_button "Log in"
  end
end

When /^I visit profile for "([^\"]*)"$/ do |username|
  user = User.find_by_username!(username)
  visit user_url(user)
end
<% if current_user && current_user.admin? || current_user == @user %>
  <p><%= link_to "Edit Profile", edit_user_path(@user) %></p>
<% end %>

RSS Feed for Episode Comments 52 comments

1. Jim Black Apr 27, 2009 at 01:16

Really cool! (As a cucumber!)


2. Ryan Apr 27, 2009 at 01:42

Thanks Ryan! Another great screencast! I actually get excited to wake up on mondays to see what you've covered!


3. Madan Kumar Rajan Apr 27, 2009 at 01:44

@Ryanb

BDD is fine. But it takes too much time when compared to TDD. Cucumber looks cool. But is there any real value of using it, when you are sure of the requirements? Because, it slows down the process so much.

Thanks,
Madan Kumar Rajan


4. Guillaume Apr 27, 2009 at 02:03

*sigh* When I think that I was just starting to enjoy Cucumber, its getting even more awesome... Thanks for the great(est?) cast !


5. RailsCasts Fan Apr 27, 2009 at 03:44

Thanks Ryan for this greeeat screencast!
For my new web application, I will definitely use Cucumber, it's just so... amazing and powerful! ;)


6. Florian Apr 27, 2009 at 04:02

Hi Ryan!

Awesome screencast!
You clearly showed a lot of advantages of cucumber.

Thanks,
- Florian


7. Aslak Hellesøy Apr 27, 2009 at 04:55

Couldn't have done it better myself. Awesome job again Ryan! I'm really happy that you're showing people how to use Cucumber!


8. George Apr 27, 2009 at 07:18

Very nice screencast. I knew that there is more to Cucumber. Thanks


9. Andy Ferra Apr 27, 2009 at 07:51

It's 0.3 not 3.0. :)


10. Tim Apr 27, 2009 at 08:24

Hi Ryan -
Great stuff, but be careful.
Its lucky all your passwords are 'secret'.
You set up a table in the Outline, but you use literal text in the steps!


11. Mark Wilden Apr 27, 2009 at 11:27

In the line

if current_user && current_user.admin? || current_user == @user

you should parenthesize the ||, else if there is no current_user and @user is nil, then the viewer could edit the profile. Probably @user could never be nil, of course.


12. Rodreegez Apr 28, 2009 at 02:43

Thanks so much Ryan, Scenario Outlines... who knew?


13. Camilo Apr 28, 2009 at 03:25

World class screencast! Many thanks.


14. QuBiT Apr 28, 2009 at 07:55

Thanks for the screencasts. great one again.

@ryan
maybe you want to add my Netbeans Plugin for Cucumber to your show notes, since i've added the support for 0.3.0 today ;)

Plugin @ my webpage
http://members.chello.at/server/modules.html

Plugin @ Netbeans
http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=17939

It will help Windows users who are using Netbeans (there is a ruby/rails edition) to write their Features.


15. Zasheir Apr 30, 2009 at 20:12

Hi Ryan,

Any Idea on how to implement the same kind of test using machinist & nifty_auth?


16. Roman May 07, 2009 at 20:34

isn`t it hard to add
format.html { redirect_to(posts_url) }
to your comment_controller?

i`m serfing without javascript


17. V May 16, 2009 at 04:30

Hey, I'm getting "missing argument: -n (OptionParser::MissingArgument)" when I try to run cucumber features -n

Any ideas about this?


18. Aslak Hellesøy May 18, 2009 at 02:02

V: Since version 0.3.3 -n is an alias for --name, and it expects an argument. Run cucumber --help. Also, read the History.txt file.


19. maicroft May 30, 2009 at 05:12

Thanks for screencast!


20. darkheaving Jun 02, 2009 at 06:46

Many thanks.


21. tyrok_xxx Jun 03, 2009 at 14:05

World class screencast!


22. Jacob Jun 05, 2009 at 08:54

This is a wonderful screencast but I would love it if you could dig a little deeper. As soon as I try to use it for myself I hit walls such as, how do you match '/charts/3/observations/new' in paths.rb when the 3 is dynamic?

I run into similar problems when I try to use Factory Girl with anything more than a trivial association.

Would you consider a 202 level screencast for cucumber and Factory Girl?


23. Valeriya Jun 14, 2009 at 19:11

Cool stuff, as always...Thanks!!


24. Sig Jun 16, 2009 at 15:11

I'm new to cucumber and I'm trying to understand some best practices.
For instance after executing an action should I use something like
"then I should be redirect to home_page" or should I concentrate my attention to the page content, such as "then I should see 'welcome to the home page'"?

Thanks
 


25. Ольга Jun 18, 2009 at 01:27

Thx Ryan! it's very good


26. ico Jun 24, 2009 at 08:21

to Zasheir

with machinist you need to change your step definitions as following
Given /^(.+) records$/ do |model, table|
  model = model.gsub(/\s/,'_').singularize
  klass = eval(model.camelize)
  klass.transaction do
    klass.destroy_all
    table.hashes.each { |hash| klass.make(hash) }
  end
end


27. pulkit Jun 25, 2009 at 06:57

Hey Guys,
Don't panic if you are getting below error when you tried to run "cucumber features -n":

missing argument: -n (OptionParser::MissingArgument)

You are getting this error because cucumber version is now updated.

Try to run "cucumber features" and it will work fine!!!


28. mike Jul 01, 2009 at 10:56

I am trying to require factories but i keep getting this message.

no such file to load -- /Volumes/Work/visbid/spec/factories

any help? thanks


29. deffzp Jul 14, 2009 at 20:33

Hey Guys,
Don't panic if you are getting below error when you tried to run "cucumber features -n":

missing argument: -n (OptionParser::MissingArgument)

You are getting this error because cucumber version is now updated.

Try to run "cucumber features" and it will work fine!!!


30. confused Jul 15, 2009 at 13:06

I am not fully grasping what cucumber is doing behind the scenes here. While scenarios are being "passed" - all in green - nothing is being saved to the test database, correct? So how do we REALLY know they are passing?


31. guru Jul 17, 2009 at 13:31

BDD is fine. But it takes too much time when compared to TDD. Cucumber looks cool. But is there any real value of using it, when you are sure of the requirements? Because, it slows down the process so much.


32. Chris Oct 08, 2009 at 21:46

Same problem as Mike:

no such file to load -- /Users/Foo/Projects/test/Rails/blog/spec/factories (MissingSourceFile)


33. Chris Oct 08, 2009 at 21:48

Ah, I see - add the code from http://railscasts.com/episodes/158-factories-not-fixtures


34. Extenze Oct 23, 2009 at 12:35

Nice post, thanks for sharing..


35. Colon Cleanse Oct 23, 2009 at 12:36

Nice One!


36. powerleveling Nov 02, 2009 at 20:46

Very nice!!!!


38. fe Nov 08, 2009 at 21:09

<a href="http://www.efes.com">sedde</a>
[url=http://www.efes.org]esed[/url]
hkj


39. msas Nov 12, 2009 at 04:25

<a href="http://flashgames.viviti.com/">1</a>
<a href="http://flashgames.viviti.com/games">2</a>
<a href="http://flashgames.viviti.com/pc-games">3</a>
<a href="http://flashgames.viviti.com/program">4</a>
<a href="http://falshgames.bravehost.com/index.html">5</a>
<a href="http://falshgames.bravehost.com/banat.html">6</a>
<a href="http://falshgames.bravehost.com/games.html">7</a>
<a href="http://falshgames.bravehost.com/mobile.html">8</a>
<a href="http://sites.google.com/site/brameggawal/home">9</a>
<a href="http://sites.google.com/site/brameggawal/bramg">10</a>
<a href="http://sites.google.com/site/brameggawal/brameg">11</a>
<a href="http://sites.google.com/site/brameggawal/games">12</a>
<a href="http://bramej.weebly.com/games.html">13</a>
<a href="http://bramej.weebly.com/index.html">14</a>
<a href="http://bramej.weebly.com/banat.html">15</a>
<a href="http://bramej.weebly.com/mobile-games.html">16</a>
<a href="http://bramj.7p.com/">17</a>
<a href="http://bramj.7p.com/bramej.html">18</a>
<a href="http://bramj.7p.com/games.html">19</a>
<a href="http://bramj.7p.com/girls.html">20</a>
<a href="http://dataway1.fortunecity.com/blog/entry4.html">21</a>
<a href="http://dataway1.fortunecity.com/blog/entry3.html">22</a>
<a href="http://dataway1.fortunecity.com/blog/entry2.html">23</a>
<a href="http://dataway1.fortunecity.com/blog/entry1.html">24</a>
<a href="http://mobilegame.piczo.com/?cr=3">25</a>
<a href="http://mobilegame.piczo.com/flashgames?cr=3&linkvar=000044">26</a>
<a href="http://mobilegame.piczo.com/mobilegames?cr=3&linkvar=000044">27</a>
<a href="http://mobilegame.piczo.com/girls?cr=3&linkvar=000044">28</a>
<a href="http://3arabsoft.i8.com/">29</a>
<a href="http://3arabsoft.i8.com/rich_text.html">30</a>
<a href="http://3arabsoft.i8.com/rich_text_1.html">31</a>
<a href="http://3arabsoft.i8.com/rich_text_2.html">32</a>
<a href="http://3arabsoft.yolasite.com/">33</a>
<a href="http://3arabsoft.yolasite.com/games.php">34</a>
<a href="http://3arabsoft.yolasite.com/girls.php">35</a>
<a href="http://3arabsoft.yolasite.com/mobilegames.php">36</a>
<a href="http://banat.moonfruit.com/">37</a>
<a href="http://banat.moonfruit.com/#/page/4536615914">38</a>
<a href="http://banat.moonfruit.com/#/page/4536615907">39</a>
<a href="http://banat.moonfruit.com/#/page/4536615893">40</a>
<a href="http://www.arabsoft.741.com/">41</a>
<a href="http://www.arabsoft.741.com/sub.htm">42</a>
<a href="http://www.arabsoft.741.com/mobile.htm">43</a>
<a href="http://www.arabsoft.741.com/download.htm">44</a>
<a href="http://www.arabsoft.350.com/">45</a>
<a href="http://www.arabsoft.350.com/games.htm">46</a>
<a href="http://www.arabsoft.350.com/banat.htm">47</a>
<a href="http://arabsoft.stormpages.com/">48</a>
<a href="http://www.stormpages.com/arabsoft/games.html">49</a>
<a href="http://www.stormpages.com/arabsoft/home.html">50</a>
<a href="http://www.stormpages.com/arabsoft/mobile.html">51</a>
<a href="http://www.stormloader.com/users/arabsoft/">52</a>
<a href="http://www.stormloader.com/users/arabsoft/bramej.html">53</a>
<a href="http://www.stormloader.com/users/arabsoft/games.html">54</a>
<a href="http://www.stormloader.com/users/arabsoft/mobile.html">55</a>
<a href="http://www.arabsoft.zoomshare.com/">56</a>
<a href="http://www.arabsoft.zoomshare.com/1.html">57</a>
<a href="http://www.arabsoft.zoomshare.com/2.html">58</a>
<a href="http://arabsoft.20megsfree.com/index.html">59</a>
<a href="http://arabsoft.20megsfree.com/rich_text.html">60</a>
<a href="http://arabsoft.20megsfree.com/rich_text_2.html">61</a>
<a href="http://arabsoft.20megsfree.com/rich_text_1.html">62</a>
<a href="http://arabsoft.freecyberzone.com/index.html">63</a>
<a href="http://arabsoft.freecyberzone.com/games.html">64</a>
<a href="http://arabsoft.freecyberzone.com/wwe.html">65</a>
<a href="http://arabsoft.freecyberzone.com/mobile.html">66</a>
<a href="http://arabsoft.00server.com/">67</a>
<a href="http://arabsoft.00server.com/bramej.html">68</a>
<a href="http://arabsoft.00server.com/girls.html">69</a>
<a href="http://arabsoft.00server.com/mobile.html">70</a>
<a href="http://demod.multiply.com/journal">71</a>
<a href="http://arabsoft.1colony.com/index.html">72</a>
<a href="http://arabsoft.1colony.com/bramej.html">73</a>
<a href="http://arabsoft.1colony.com/girls.html">74</a>
<a href="http://arabsoft.1colony.com/games.html">75</a>
<a href="http://arabsoft.20fr.com/index.html">76</a>
<a href="http://arabsoft.20fr.com/games.html">77</a>
<a href="http://arabsoft.20fr.com/girls.html">78</a>
<a href="http://arabsoft.20fr.com/mobile.html">79</a>
<a href="http://arabsoft.00cd.com/">80</a>
<a href="http://arabsoft.00cd.com/games.html">81</a>
<a href="http://arabsoft.00cd.com/girls.html">82</a>
<a href="http://arabsoft.00cd.com/mobile.html">83</a>
<a href="http://arabsoft.worldbreak.com/">84</a>
<a href="http://arabsoft.worldbreak.com/games.html">85</a>
<a href="http://arabsoft.worldbreak.com/girls.html">86</a>
<a href="http://arabsoft.worldbreak.com/mobile.html">87</a>
<a href="http://www.joes.com/home/3arabsoft/">88</a>
<a href="http://www.arabsoft.ewebsite.com/page/brameg">89</a>
<a href="http://www.arabsoft.ewebsite.com/page/games">90</a>
<a href="http://www.arabsoft.ewebsite.com/page/mobile">91</a>
<a href="http://www.arabsoft.ewebsite.com/page/girls">92</a>
<a href="http://arabsoft.mvhosted.com/index.html">93</a>
<a href="http://arabsoft.mvhosted.com/games.html">94</a>
<a href="http://arabsoft.mvhosted.com/flashgames.html">95</a>
<a href="http://arabsoft.mvhosted.com/mobilesoft.html">96</a>
<a href="http://3arabsoft.ios.st/Front/Pages/pages.asp?id=194941">97</a>
<a href="http://3arabsoft.ios.st/Front/Pages/pages.asp?id=194942">98</a>
<a href="http://3arabsoft.ios.st/Front/Pages/pages.asp?id=194943">99</a>
<a href="http://3arabsoft.ios.st/Front/Pages/pages.asp?id=194944">100</a>
<a href="http://3arabsoft.20m.com/index.html">101</a>
<a href="http://3arabsoft.20m.com/games.html">102</a>
<a href="http://3arabsoft.20m.com/wwe.html">103</a>
<a href="http://3arabsoft.20m.com/girls.html">104</a>
<a href="http://arabsoft.blog.homepagenow.com/blog.shtml">105</a>
<a href="http://3arabsoft.9k.com/">106</a>
<a href="http://3arabsoft.9k.com/games.html">107</a>
<a href="http://3arabsoft.9k.com/wwe.html">108</a>
<a href="http://3arabsoft.9k.com/girls.html">109</a>


39. ahmet maranki Nov 12, 2009 at 15:43

thanx niracles


40. islami sohbet Nov 16, 2009 at 13:47

teşekkürler admin nice post i like


41. Kevin Nov 17, 2009 at 23:25

Hey Ryan, would you care to share the textmate magic that you use to align the table?


42. oyunlar Nov 24, 2009 at 11:14

thank you very much.


43. Invisalign Birmingham Nov 25, 2009 at 10:12

Thanks for the source code.. ill see where can i fit that in my applicaiton


44. Mikrofaser Fleece Bettwäsche Dec 03, 2009 at 10:25

It was a very nice idea!


45. Kevin Monk Dec 10, 2009 at 04:43

Hi Ryan,

You got a real spam problem with your comments. Why don't you add some CAPTCHA or a simple question field?

Thanks for the casts. I've built quite a few hardworking apps with no testing whatsoever. I'm not sure if I should feel proud or ashamed. I don know that they work and every time I look at testing it seems like an unnecessary hindrance.I guess the only way to find out what I'm missing is to get stuck in and see how much it benefits me.

Regards,

Kevin.


46. nike sb shoes Dec 18, 2009 at 21:45

As someone that can never manage to keep fewer than 7 guitars around even when I try, I agree with #2. This is a bad idea for any instrument that you want to keep in good shape. I have one guitar that I hang, and it's in my living room in an out of the way place mounted into a stud.


47. Links of London jewelry Jan 11, 2010 at 21:27

I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day!


48. wholesale nike shoes Jan 13, 2010 at 21:50

Thanks for the casts. I've built quite a few hardworking apps with no testing whatsoever. I'm not sure if I should feel proud or ashamed


49. glavsstok Jan 18, 2010 at 04:35

I thank! I searched for a long time for it


50. Madame Alexander Doll Jan 23, 2010 at 04:08

else if there is no current_user and @user is nil, then the viewer could edit the profile. Probably @user could never be nil, of course.


51. links of london sale Jan 28, 2010 at 01:27

The same links of london collections, but I can find the cheap links of london on the internet, I have ordered some links of london necklaces and links of london earrings.


52. cheap adidas shoes Jan 31, 2010 at 19:16

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


53. Новости игровой индустрии Feb 03, 2010 at 00:18

Не знаю как вы, но мы уже давно скачиваем игры в нормальных местах =)

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