0

我有一个非常简单的水豚脚本,用于使用设计的自定义注册表单:

  scenario "allow me to register and should take me to the new partner page" do
    visit '/registrations/become_partner'
    response.should be_success
  end

当我尝试运行测试时,出现以下错误:

     ActionView::Template::Error:
       undefined method `first_name' for #<User:0x00000004d259e8>

即使此方法已定义。我的模型中有attr_accesible集合,页面呈现,我可以从 rails 控制台调用这个方法。当其他地方没有问题时,为什么水豚会抛出这个错误?

4

1 回答 1

2

看起来您的测试环境还不知道该属性-显然您已first_name在开发环境中添加了该字段,但尚未在测试环境中添加。

要更新您的测试环境,只需运行

rake db:test:prepare

它会起作用。您应该在运行迁移后始终执行此操作,这是一个常见的错误。

于 2013-02-15T14:18:58.407 回答