Topic: FactoryGirl
i am trying to upgrade my test to use FactoryGirl but they are not passing
my old test looks like
require 'spec_helper'
describe User do
before do
@user = User.new( email: "moisesz@email.com", password: "foobar", password_confirmation: "foobar", remember_me: true, username: "moiseszaragoza", first_name: "Moises", last_name: "Zaragoza", account_id: 1)
end
subject { @user }
it { should respond_to(:email) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:remember_me) }
it { should respond_to(:username) }
it { should respond_to(:first_name) }
it { should respond_to(:last_name) }
it { should respond_to(:account_id) }
describe "when email format is invalid" do
it "should be invalid" do
addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
addresses.each do |invalid_address|
@user.email = invalid_address
@user.should_not be_valid
end
end
end
describe "when First Name is too long" do
before { subject.first_name = "a" * 21 }
it { should_not be_valid }
end
describe "when Last Name is too long" do
before { subject..last_name = "a" * 21 }
it { should_not be_valid }
end
describe "when Username is too long" do
before { subject..username = "a" * 21 }
it { should_not be_valid }
end
endand this test works just perfect
my new test
equire 'spec_helper'
describe User do
subject { FactoryGirl.create(:user) }
it { should respond_to(:email) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:remember_me) }
it { should respond_to(:username) }
it { should respond_to(:first_name) }
it { should respond_to(:last_name) }
it { should respond_to(:account_id) }
describe "when email format is invalid" do
it "should be invalid" do
addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
addresses.each do |invalid_address|
@user.email = invalid_address
@user.should_not be_valid
end
end
end
describe "when First Name is too long" do
before { User.first_name = "a" * 21 }
it { should_not be_valid }
end
describe "when Last Name is too long" do
before { @user.last_name = "a" * 21 }
it { should_not be_valid }
end
describe "when Username is too long" do
before { @user.username = "a" * 21 }
it { should_not be_valid }
end
endi cant get it started