Skip to content

Instantly share code, notes, and snippets.

@memaker
Created December 7, 2016 21:20
Show Gist options
  • Save memaker/18c23964e93ff92d5ae8073cc2b6b104 to your computer and use it in GitHub Desktop.
Save memaker/18c23964e93ff92d5ae8073cc2b6b104 to your computer and use it in GitHub Desktop.
# spec/models/person_spec.rb
require 'rails_helper'
RSpec.describe Person, type: :model do
it "has a valid factory" do
#person = FactoryGirl.build(:person) it is also valid
expect(FactoryGirl.build(:person)).to be_valid
end
it "is invalid without a name" do
person = FactoryGirl.build(:person, name: nil)
expect(person).not_to be_valid
end
it "is invalid without an age" do
person = FactoryGirl.build(:person, age: nil)
expect(person).not_to be_valid
end
it "returns a person's identifier as a string" do
person = FactoryGirl.build(:person, name: "Johnny", age: 12)
expect(person.identifier).to eq("Johnny 12")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment