Skip to content

Commit

Permalink
Adds specs for factory_girl 2 functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Jul 15, 2011
1 parent 787712d commit d2a4ecb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
40 changes: 27 additions & 13 deletions spec/pickle/adapter_spec.rb
Expand Up @@ -67,23 +67,35 @@
end
end
end


end

describe 'FactoryGirl' do
before do
Pickle::Adapter::FactoryGirl.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
@orig_factories, Factory.factories = Factory.factories, {}

Factory.define(:one, :class => @klass1) {}
Factory.define(:two, :class => @klass2) {}
@factory1 = Factory.factories[:one]
@factory2 = Factory.factories[:two]

if defined? ::FactoryGirl
@orig_factories = ::FactoryGirl.factories.dup
::FactoryGirl.factories.clear
::FactoryGirl::Syntax::Default::DSL.new.factory(:one, :class => @klass1) {}
::FactoryGirl::Syntax::Default::DSL.new.factory(:two, :class => @klass2) {}
@factory1 = ::FactoryGirl.factories[:one]
@factory2 = ::FactoryGirl.factories[:two]
else
@orig_factories, Factory.factories = Factory.factories, {}
Factory.define(:one, :class => @klass1) {}
Factory.define(:two, :class => @klass2) {}
@factory1 = Factory.factories[:one]
@factory2 = Factory.factories[:two]
end
end

after do
Factory.factories = @orig_factories
if defined? ::FactoryGirl
::FactoryGirl.factories.clear
@orig_factories.each {|f| ::FactoryGirl.factories.add(f) }
else
Factory.factories = @orig_factories
end
end

it ".factories should create one for each factory" do
Expand All @@ -105,13 +117,15 @@
@factory.klass.should == @klass1
end

it "#create(attrs) should call Factory(<:key>, attrs)" do
Factory.should_receive(:create).with("one", {:key => "val"})
@factory.create(:key => "val")
unless defined? ::FactoryGirl
it "#create(attrs) should call Factory(<:key>, attrs)" do
Factory.should_receive(:create).with("one", {:key => "val"})
@factory.create(:key => "val")
end
end
end
end

describe 'Machinist' do
before do
Pickle::Adapter::Machinist.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
Expand Down
10 changes: 6 additions & 4 deletions spec/pickle/session_spec.rb
Expand Up @@ -282,10 +282,12 @@ class Model
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\' (super_admin is factory that returns users)' do
let(:fred) { mock("fred", :class => user_class, :id => 2) }
let(:shirl) { mock("shirl", :class => user_class, :id => 3) }
let(:noname) { mock("noname", :class => user_class, :is => 4) }

let(:super_admin_factory) do
Pickle::Adapter::FactoryGirl.new(mock(:build_class => user_class, :factory_name => :super_admin))
let(:noname) { mock("noname", :class => user_class, :id => 4) }

if defined? ::FactoryGirl
let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(mock(:build_class => user_class, :name => :super_admin)) }
else
let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(mock(:build_class => user_class, :factory_name => :super_admin)) }
end

before do
Expand Down

0 comments on commit d2a4ecb

Please sign in to comment.