【问题标题】:Rspec failing test - FactoryGirlRspec 测试失败 - FactoryGirl
【发布时间】:2014-09-21 16:21:15
【问题描述】:

这是我的规格:

require 'spec_helper'

describe "User pages" do

  let(:user) { FactoryGirl.create(:user) }

  subject { page }

  describe "for non-signed-in user" do

    describe "profile page" do

      before do
        visit user_path(user)
      end

      it { should have_content("Sign in") }
      it { should have_title("Sign in") }
    end
  end
end

这是 factory.rb:

FactoryGirl.define do

  factory :user do
    sequence(:name)     { |n| "User #{n}" }
    sequence(:email)    { |n| "user_#{n}@example.com" }
    sequence(:callsign) { |n| "user_#{n}" }
    password "foobar"
    password_confirmation "foobar"

    factory :admin do
      admin true
    end
  end
end

我不断收到此错误消息:

未登录用户个人资料页面的用户页面

失败/错误:let(:user) { FactoryGirl.create(:user) }

ActiveRecord::RecordInvalid:

验证失败:呼号不能为空,呼号无效

我很困惑。为什么我在 factory.rb 中设置呼号为空,为什么会报错?

【问题讨论】:

    标签: ruby-on-rails rspec factory-bot


    【解决方案1】:

    我是个白痴。我只需要重新启动 spork。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多