Setting Up And Testing Devise – Delicious Clone

by woody2shoes on January 21, 2011

Because I’m going to be testing in cucumber sections of the site that require a user to be logged in, I decided to get it out of the way. So, in this video, I write a cucumber feature to test login and round it off with a few tests on the devise generated user model to make sure it continues to behave as I expect it to as I update it throughout the process of building this application.

Download 191.8 MB
Download (iPhone & iPod) 87.2 MB

  • http://twitter.com/chris_gunther Chris Gunther

    Nice screencast. Looking forward to watching it through completion.

    Just to clarify, the validate_uniqueness_of matcher didn’t fail because it needed an explicit subject, but rather because it needed an existing row in the database to perform its test. Calling Factory.create within the subject block just happened to satisfied that dependency.

    See here: http://rdoc.info/gems/shoulda/2.11.3/Shoulda/ActiveRecord/Matchers#validate_uniqueness_of-instance_method

    Chris

    • http://teachmetocode.com Charles Max Wood

      That makes sense. Thanks for the clarification.

  • Anonymous

    Nice screencast. Looking forward to watching it through completion.

    Just to clarify, the validate_uniqueness_of matcher didn’t fail because it needed an explicit subject, but rather because it needed an existing row in the database to perform its test. Calling Factory.create within the subject block just happened to satisfied that dependency.

    See here: http://rdoc.info/gems/shoulda/2.11.3/Shoulda/ActiveRecord/Matchers#validate_uniqueness_of-instance_method

    Chris

    • http://teachmetocode.com Charles Max Wood

      That makes sense. Thanks for the clarification.

  • Pingback: Tweets that mention Setting Up And Testing Devise – Delicious Clone — Teach Me To Code -- Topsy.com

  • Anton

    Great, thanks!

    Although I would have used haml / sass instead of the ugly erb stuff :)

    • http://teachmetocode.com Charles Max Wood

      I am seriously considering making HAML/SASS my next episode. Sounds like you wouldn’t object.

  • Anton

    Great, thanks!

    Although I would have used haml / sass instead of the ugly erb stuff :)

    • http://teachmetocode.com Charles Max Wood

      I am seriously considering making HAML/SASS my next episode. Sounds like you wouldn’t object.

  • Anton

    The “I wonder why it has failed” used to get me so annoyed that I stored a screenshot and the HTML code if a test fails (this is for selenium, but a similar extension for cucumber / capybara should not be so difficult to implement – at least for the HTML output)

    class MyIntegrationTest < ActionController::IntegrationTet
    def teardown
    unless @test_passed
    Dir.mkdir("#{Rails.root}/tmp/testresults") unless File.exists?("#{Rails.root}/tmp/testresults")
    $cb.capture_screenshot("#{Rails.root}/tmp/testresults/#{@method_name}.png")
    # store the html of the failed page
    File.open("#{Rails.root}/tmp/testresults/#{@method_name}.html", 'w') {|f| f.write($cb.get_html_source()) }
    end
    end
    end

    • http://teachmetocode.com Charles Max Wood

      Interesting. You can do something similar with launchy. It loads the page into the browser and brings it into focus. It would be nice to get it to do that on failed tests automatically.

  • Anton

    The “I wonder why it has failed” used to get me so annoyed that I stored a screenshot and the HTML code if a test fails (this is for selenium, but a similar extension for cucumber / capybara should not be so difficult to implement – at least for the HTML output)

    class MyIntegrationTest < ActionController::IntegrationTet
    def teardown
    unless @test_passed
    Dir.mkdir("#{Rails.root}/tmp/testresults") unless File.exists?("#{Rails.root}/tmp/testresults")
    $cb.capture_screenshot("#{Rails.root}/tmp/testresults/#{@method_name}.png")
    # store the html of the failed page
    File.open("#{Rails.root}/tmp/testresults/#{@method_name}.html", 'w') {|f| f.write($cb.get_html_source()) }
    end
    end
    end

    • http://teachmetocode.com Charles Max Wood

      Interesting. You can do something similar with launchy. It loads the page into the browser and brings it into focus. It would be nice to get it to do that on failed tests automatically.

  • Anton

    What I forgot: When you record, please record in mono not only on the right channel ;)

    • http://teachmetocode.com Charles Max Wood

      Oh, yeah. I gotta fix that. :(

  • Anton

    What I forgot: When you record, please record in mono not only on the right channel ;)

    • http://teachmetocode.com Charles Max Wood

      Oh, yeah. I gotta fix that. :(

  • Madpixoo

    Thanks for your screencasts.

    Can you speak a little more louder please ?
    I always need to increase my sound to listen and when somebody talks to me on adium or else the tilt sound makes my brain explode :D

    Thanks !

    • http://teachmetocode.com Charles Max Wood

      I’ll see what I can do. Thanks.

  • Madpixoo

    Thanks for your screencasts.

    Can you speak a little more louder please ?
    I always need to increase my sound to listen and when somebody talks to me on adium or else the tilt sound makes my brain explode :D

    Thanks !

    • http://teachmetocode.com Charles Max Wood

      I’ll see what I can do. Thanks.

  • elf Pavlik

    Nice screencast!

    I would like to suggest you using spork =)
    After while watching rails env loading can get a bit boring ;)

    Looking forward the next episode!

    • http://teachmetocode.com Charles Max Wood

      You’re the second person to suggest spork. I’ll have to look at it and pickle and see what they can do for me.

  • elf Pavlik

    Nice screencast!

    I would like to suggest you using spork =)
    After while watching rails env loading can get a bit boring ;)

    Looking forward the next episode!

    • http://teachmetocode.com Charles Max Wood

      You’re the second person to suggest spork. I’ll have to look at it and pickle and see what they can do for me.

  • http://wwelves.org/perpetual-tripper elf Pavlik

    I also wonder what do you think about using pickle?…

  • http://wwelves.org/perpetual-tripper elf Pavlik

    I also wonder what do you think about using pickle?…

  • http://twitter.com/freaky_bug Manoj

    Thanks,Great Screencast!!
    As @anton and you pointed out, a HAML/SASS episode would be great.Looking forward to it.

  • http://twitter.com/freaky_bug Manoj

    Thanks,Great Screencast!!
    As @anton and you pointed out, a HAML/SASS episode would be great.Looking forward to it.

  • http://www.facebook.com/jonny.dalgleish Jonny T-Fest Dalgleish

    Love your screencasts. Cant wait for the next one…

  • http://www.facebook.com/jonny.dalgleish Jonny T-Fest Dalgleish

    Love your screencasts. Cant wait for the next one…

  • http://twitter.com/pithyless Norbert Wójtowicz

    It was really difficult to pay attention at first with my headphones on, since the screencast is recorded in only the right channel. For anyone else in the same situation, I found a solution for Mac OS X: System Preferences -> Universal Access -> Hearing -> “Play stereo audio as mono”. I didn’t find it at first, because I was looking under Audio preferences. Cheers and thanks for the great screencasts!

    • http://teachmetocode.com Charles Max Wood

      Norbert-

      I’ve added this to my todo list so I can re-export it in mono. I’ve fixed my recording setup so it doesn’t happen anymore. I should get to it next Thursday. (That’s the day I spend recording, etc.)

  • http://twitter.com/pithyless Norbert Wójtowicz

    It was really difficult to pay attention at first with my headphones on, since the screencast is recorded in only the right channel. For anyone else in the same situation, I found a solution for Mac OS X: System Preferences -> Universal Access -> Hearing -> “Play stereo audio as mono”. I didn’t find it at first, because I was looking under Audio preferences. Cheers and thanks for the great screencasts!

    • http://teachmetocode.com Charles Max Wood

      Norbert-

      I’ve added this to my todo list so I can re-export it in mono. I’ve fixed my recording setup so it doesn’t happen anymore. I should get to it next Thursday. (That’s the day I spend recording, etc.)

  • Ben

    Hi Charles, thanks for this screencast! One question: what is the basic scenarios I have to implement to fully test devise: log in (you do) and I think about testing sign up and password recovery.. That’s enough? do you see other things? Thanks!!

    • http://teachmetocode.com Charles Max Wood

      Ben, that depends on which functionality you’re leaning on devise for. Those are good things to test. I can’t think of other areas of functionality off the top of my head.

      • Ben

        Ok, thanks for your feedback!

  • Ben

    Hi Charles, thanks for this screencast! One question: what is the basic scenarios I have to implement to fully test devise: log in (you do) and I think about testing sign up and password recovery.. That’s enough? do you see other things? Thanks!!

    • http://teachmetocode.com Charles Max Wood

      Ben, that depends on which functionality you’re leaning on devise for. Those are good things to test. I can’t think of other areas of functionality off the top of my head.

      • Ben

        Ok, thanks for your feedback!

Previous post:

Next post: