R – Cucumber: rails dynamic find not working in paths.rb

cucumberfindruby-on-rails

I am working on rails with rspec, rspec-rails, cucumber and webrat.
I am trying to learn BDD and testing in general.
I have a cucumber scenario like this:

  Scenario: Questions List
    Given quiz titled "Pearl Jam" has questions named "Corduroy, Dissident"
    When I go to the experiment page for quiz titled "Pearl Jam"
    Then I should see "Corduroy"
    And I should see "Dissident" 

I have alrady added step 1, where I create and save a quiz correctly (I tested through puts).
Now I am working on step 2. I am adding a new path in paths.rb

when /^the experiment page for quiz titled "(.*)"$/i 
  new_quiz_experiment_path(Quiz.find_by_title($1))  

For some reason find_by_title does not work. I get this error message:

new_quiz_experiment_url failed to generate from {:quiz_id=>nil, :action=>"new", :controller=>"experiments"}, expected: {:action=>"new", :controller=>"experiments"}, diff: {:quiz_id=>nil} (ActionController::RoutingError) 

I am sure the record is there, and correctly saved; if I insert

puts Quiz.find(1).title

I get "Pearl Jam". Looks like find_by is not working, which is quite weird since the cucumber generated file contains this example:

  #   when /^(.*)'s profile page$/i
  #     user_profile_path(User.find_by_login($1))     

I also tried a simpler find first with conditions, it doesn't work either.

Any idea?

Thanks in advance,
Davide

Best Answer

Thanks to ryanb's suggestion I was able to find the bug, which was in

Given quiz titled "Pearl Jam" has questions named "Corduroy, Dissident"

Basically I had parsed this step inconsisetntly; I had inserted the quotation marks in the 1st regex, so the tile got saved as

"Pearl Jam"

I guess I've lerned two things:

  • Be careful with quotation marks in step definitions
  • use method with the extra ! for more expressive error messages.