Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds specs for factory_girl 2 functionality

  • Loading branch information...
commit d2a4ecb75aee349b8c56d9c30f102b9a0e9dde88 1 parent 787712d
@ianwhite authored
Showing with 33 additions and 17 deletions.
  1. +27 −13 spec/pickle/adapter_spec.rb
  2. +6 −4 spec/pickle/session_spec.rb
View
40 spec/pickle/adapter_spec.rb
@@ -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
@@ -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])
View
10 spec/pickle/session_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.