Rspec失败测试 - FactoryGirl

时间:2014-09-21 01:46:24

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

这是我的规格:

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

这是factories.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

我不断收到此错误消息:

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

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

的ActiveRecord :: RecordInvalid:

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

我很困惑。当我在factory.rb中设置呼号时,为什么会抱怨呼号是空白的?

1 个答案:

答案 0 :(得分:0)

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