在黄瓜测试期间调用id为nil,这将错误地为4

时间:2013-07-23 14:07:05

标签: ruby-on-rails cucumber

manish@ubuntu:~/change/artfacedev2_15july$ bundle exec cucumber features/home_page.feature 
Using the default profile...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Checking for old unconfirmed users
2013-07-23 19:29:38 +0530
Updating CurrencyValue
2013-07-23 19:29:38 +0530
Feature: homepage

  Background: I am on the homepage # features/home_page.feature:3
    Given I am on the homepage     # features/step_definitions/home_page_steps.rb:1
      Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id (RuntimeError)
      ./app/controllers/static_controller.rb:31:in `home'
      ./features/step_definitions/home_page_steps.rb:2:in `/^I am on the homepage$/'
      features/home_page.feature:4:in `Given I am on the homepage'
"Exception"
"undefined method `update_attribute' for nil:NilClass"

..........................
in home_page.feature
Feature: homepage 

  Background: I am on the homepage
  Given I am on the homepage
..........................
in home_page_step.rb
Given /^I am on the homepage$/ do
  visit "/"
end
...........................
path.rb is 
module NavigationHelpers
  def path_to(page_name)
    case page_name
    when /the homepage/
      '/'
    when /users section in backend panel/
      '/backend/users/'
    when /backend login page/
      '/backend/af_login/'
    else
      raise "Can't find mapping from \"#{page_name}\" to a path.\n"
    end
  end
end
World(NavigationHelpers)

1 个答案:

答案 0 :(得分:0)

static_controller.rb的第31行在您希望成为id对象的内容上调用ActiveRecord,但实际上是nil。找出原因。

(错误消息指出nil,而不是ActiveRecord对象,只有Ruby内部id字段,4字段始终为nil {1}})。