www.francisfish.com

Click Bookshop to see my novels. Buddhist, father of 2, Ruby on Rails programmer for money, and fiction writer.

    follow me on Twitter

    Debugging cucumber scripts, cucumber and devise authentication

    Non Rails/Ruby people may as well ignore this one!

    Sometimes you need to see what the web server is sending back, when I'm working on rspec scripts I can print things out (which messes up the pretty output) but then see where my assumptions are wrong. I needed to be able to see what was in the response so that I could work out what was wrong. It's annoyingly easy when you work out how. You need to add a step that looks like this:

    When /^I dumped the response$/ do
         puts response.body
    end

    Then, in the features that are giving trouble:

    Scenario: creator restores fragment
      When fragment 1 exists
      And I am the fragment owner
      And I am on the fragment
      And I dumped the response
      # ...

    This allows you to do some debugging on that error you can't fathom out. It helped me greatly when I put in devise authentication and discovered that my code was looping back to the login screen because of a duff password.

    Devise

    I love this plugin - takes away a ton of work

    (Thanks Colin)

    This should get you started with cucumber. Note that password is a helper method that just returns something like 'test123'. My code has user roles (I do it differently from the way the devise guys do it) and I took it out, so it may not run straight away as it's untested. Caveat emptor.

    def create_my_user(params)
      unless user = User.find_by_email(params[:email])
        params[:password_confirmation] = params[:password]
        user = User.create!(params)
        # This makes the user look 'confirmed'
        user.update_attribute(:confirmation_token,nil)
        user.update_attribute(:confirmed_at,Time.now)
      end
      user
    end

    Given /^I am logged in as (.*)$/ do |email|
      @current_user = create_my_user(:email => email, :password => password )
      visit new_user_session_path
      fill_in("Email", :with => email )
      fill_in("Password", :with => password )
      click_button("Sign in")
      response.body.should =~ /My Lovely App/m
    end
     

    Comments (0) . Thursday, 4 March 2010

    Comment left on review for Feeble Paradox

    http://www.newstatesman.com/television/2009/11/high-drama-flint-king-paradox

    This is the Beeb's feeble response to Flash Forward - can't be bother with that either, but at least they have writers who can write.

    Best bit was trying to wake the sleeping tanker driver  by standing 50 metres away and shouting, instead of driving right up to the bridge and using the car's horn like a normal person would. But then Tamzin's hair might have got mussed and the cheesy special effect would have been harder to do.

    The closing sequence with more photos sent from "the aliens", including her lover looking pretty dead was so clichéd I burst out laughing.

    Comments (0) . Sunday, 29 November 2009