0

这是我的测试:

require 'spec_helper'

describe "user signs in", focus: true do
  it "allows users to sign in with their email address and password" do
    user = FactoryGirl.create(:user)
    visit "/"
    click_link "SIGN IN"
    fill_in "user_email", with: user.email
    fill_in "user_password", with: user.password
    click_button "#sign-in-btn"
    page.should have_content "Vitals"
  end
end

这是错误:

  1) user signs in allows users to sign in with their email address and password
     Failure/Error: visit "/"
     ActionView::Template::Error:
       Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
     # ./app/views/devise/registrations/_form.html.erb:2:in `block in _app_views_devise_registrations__form_html_erb__3809420936711950801_70201058646680'
     # ./app/views/devise/registrations/_form.html.erb:1:in `_app_views_devise_registrations__form_html_erb__3809420936711950801_70201058646680'
     # ./app/views/shared/modals/_sign_up.html.erb:39:in `_app_views_shared_modals__sign_up_html_erb___493445099205594204_70201081251380'
     # ./app/views/shared/_modals.html.erb:2:in `_app_views_shared__modals_html_erb__2261979984426842788_70201058520760'
     # ./app/views/layouts/home.html.erb:16:in `_app_views_layouts_home_html_erb__3485816781407765933_70201082986040'
     # ./app/controllers/pages_controller.rb:18:in `home'
     # ./spec/requests/user_registration_spec.rb:8:in `block (2 levels) in <top (required)>'

这是我的索引方法:

  def home
    @user = User.new
    @account_type = AccountType.legend
    render layout: 'home'
  end

问题是,当访问主页时,有几个实例变量需要可用于页面上的其他项目......我如何解释我的登录测试中的那些?

4

1 回答 1

1

不要担心设置实例变量。实际的主场行动将受到打击。因此,只需创建执行操作所需的所有数据。

我认为在您的情况下是 AccountType。在您的测试中为“传奇”创建一个帐户类型,我认为您应该很好

于 2013-09-04T16:23:47.477 回答