LoginSignup
3
3

More than 5 years have passed since last update.

RSpec3でバリデーションのテスト

Last updated at Posted at 2016-01-05

Faker, FactoryGirl, RSpec3を使って単純にやってみると

spec/factories/users.rb
FactoryGirl.define do
  factory :user, class: User do
    email { Faker::Internet.email }
    password { Faker::Internet.password }
  end
end
spec/models/user_spec.rb
require 'spec_helper'

describe User do
  it "should be invalid" do
    user = build(:user, { email: nil })
    expect(user.errors[:email]).to be_valid
  end
end

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3