簡體   English   中英

用Rails編寫capybara / rspec測試…稱為id表示無錯誤

[英]Writing capybara/rspec tests with Rails… called id for nil error

這是我的測試:

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

問題是,當訪問主頁時,頁面上的其他項目需要使用幾個實例變量...如何在登錄測試中說明這些變量?

不用擔心設置實例變量。 實際的家庭動作將被擊中。 因此,只需創建執行操作所需的所有數據即可。

我認為您的情況是AccountType。 在測試中為“傳奇”創建一個帳戶類型,我認為您應該很好

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM