Topic: error in controller action only in cucumber, not in browser...

Cucumber log:

Feature: User Sessions

  So that I can have proper access
  As a registered user
  I want to log in and log out

  Scenario: log in               # features/user_sessions.feature:7
    Given I am a registered user # features/step_definitions/user_sessions_steps.rb:16
    And I am on the homepage     # features/step_definitions/web_steps.rb:14
      undefined method `name' for nil:NilClass (NoMethodError)
      ./app/controllers/webpages_controller.rb:23:in `show'
      /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
      (eval):2:in `visit'
      ./features/step_definitions/web_steps.rb:15:in `/^(?:|I )am on (.+)$/'
      features/user_sessions.feature:9:in `And I am on the homepage'

Failing Scenarios:
cucumber features/user_sessions.feature:7 # Scenario: log in

1 scenario (1 failed)
2 steps (1 failed, 1 passed)
0m0.243s
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby /Library/Ruby/Gems/1.8/gems/cucumber-0.6.2/bin/cucumber --format pretty --format rerun --out /var/folders/SY/SYCFBso-HzCi-GcKlkw3UE+++TI/-Tmp-/autotest-cucumber20100213-660-1tvfy3h-0 features/user_sessions.feature:7 features/step_definitions features/support

controller show action:

      @webpage = Webpage.find_by_home_page(true)
      @permalink = @webpage.name # <-- this is what is failing

console test:

>> Webpage.find_by_home_page(true).name
  Webpage Load (0.3ms)   SELECT * FROM `webpages` WHERE (`webpages`.`home_page` = 1) LIMIT 1
=> "Home"

cucumber feature:

  Scenario: log in
    Given I am a registered user
    And I am on the homepage

features/support/paths:

 def path_to(page_name)
    case page_name
    
    when /the homepage/
      '/'

...

going to localhost:3000/ works fine in the browser...

-patrick

Last edited by patrick99e99 (2010-02-14 01:01:22)

Re: error in controller action only in cucumber, not in browser...

when you view the site via the browser you are connecting to your development database

when you run your tests it is using your test database and deleting all the data and then only loading the data from your fixture files before executing the test

so @webpage = Webpage.find_by_home_page(true)
cannot find the record in the test database and so it is nil?

Re: error in controller action only in cucumber, not in browser...

oops!  Yeah, that would make sense.  So I created a webpage factory and now it's passing fine.  Cool..  Thank you!

-p