2010-06-10 13:37:51 -04:00
|
|
|
require 'spec_helper'
|
2009-04-11 11:27:23 -04:00
|
|
|
|
|
|
|
require 'factory_girl/syntax/blueprint'
|
|
|
|
|
|
|
|
describe "a blueprint" do
|
|
|
|
before do
|
2012-04-23 16:46:42 -05:00
|
|
|
ActiveSupport::Deprecation.silenced = true
|
|
|
|
|
2012-03-09 17:20:38 -05:00
|
|
|
define_model('User', first_name: :string, last_name: :string, email: :string)
|
2010-11-12 14:58:25 -06:00
|
|
|
|
2012-03-09 17:45:42 -05:00
|
|
|
FactoryGirl.define do
|
|
|
|
sequence(:email) { |n| "somebody#{n}@example.com" }
|
|
|
|
end
|
|
|
|
|
2009-04-11 11:27:23 -04:00
|
|
|
User.blueprint do
|
2011-05-19 10:56:45 -04:00
|
|
|
first_name { 'Bill' }
|
|
|
|
last_name { 'Nye' }
|
|
|
|
email { FactoryGirl.generate(:email) }
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "after making an instance" do
|
|
|
|
before do
|
2012-03-09 17:20:38 -05:00
|
|
|
@instance = FactoryGirl.create(:user, last_name: 'Rye')
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2011-10-12 12:32:23 -06:00
|
|
|
it "uses attributes from the blueprint" do
|
2009-04-11 11:27:23 -04:00
|
|
|
@instance.first_name.should == 'Bill'
|
|
|
|
end
|
|
|
|
|
2011-10-12 12:32:23 -06:00
|
|
|
it "evaluates attribute blocks for each instance" do
|
2009-04-11 11:27:23 -04:00
|
|
|
@instance.email.should =~ /somebody\d+@example.com/
|
2011-01-26 20:55:06 -05:00
|
|
|
FactoryGirl.create(:user).email.should_not == @instance.email
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|