No more "should"'s in the example descriptions.

Closes #216
This commit is contained in:
Justin Ko 2011-10-12 12:32:23 -06:00 committed by Joshua Clayton
parent 9fcd0b6b4e
commit 334b8a9449
8 changed files with 71 additions and 71 deletions

View File

@ -19,11 +19,11 @@ describe "a blueprint" do
@instance = FactoryGirl.create(:user, :last_name => 'Rye') @instance = FactoryGirl.create(:user, :last_name => 'Rye')
end end
it "should use attributes from the blueprint" do it "uses attributes from the blueprint" do
@instance.first_name.should == 'Bill' @instance.first_name.should == 'Bill'
end end
it "should evaluate attribute blocks for each instance" do it "evaluates attribute blocks for each instance" do
@instance.email.should =~ /somebody\d+@example.com/ @instance.email.should =~ /somebody\d+@example.com/
FactoryGirl.create(:user).email.should_not == @instance.email FactoryGirl.create(:user).email.should_not == @instance.email
end end

View File

@ -17,16 +17,16 @@ describe "a factory using generate syntax" do
end end
end end
it "should not raise an error when generating an invalid instance" do it "does not raise an error when generating an invalid instance" do
lambda { User.generate(:first_name => nil) }.should_not raise_error expect { User.generate(:first_name => nil) }.to_not raise_error
end end
it "should raise an error when forcefully generating an invalid instance" do it "raises an error when forcefully generating an invalid instance" do
lambda { User.generate!(:first_name => nil) }.should raise_error(ActiveRecord::RecordInvalid) expect { User.generate!(:first_name => nil) }.to raise_error(ActiveRecord::RecordInvalid)
end end
%w(generate generate! spawn).each do |method| %w(generate generate! spawn).each do |method|
it "should yield a generated instance when using #{method} with a block" do it "yields a generated instance when using #{method} with a block" do
saved_instance = nil saved_instance = nil
User.send(method) {|instance| saved_instance = instance } User.send(method) {|instance| saved_instance = instance }
saved_instance.should be_kind_of(User) saved_instance.should be_kind_of(User)
@ -37,20 +37,20 @@ describe "a factory using generate syntax" do
@instance = User.send(method, :last_name => 'Rye') @instance = User.send(method, :last_name => 'Rye')
end end
it "should use attributes from the factory" do it "uses attributes from the factory" do
@instance.first_name.should == 'Bill' @instance.first_name.should == 'Bill'
end end
it "should use attributes passed to generate" do it "uses attributes passed to generate" do
@instance.last_name.should == 'Rye' @instance.last_name.should == 'Rye'
end end
if method == 'spawn' if method == 'spawn'
it "should not save the record" do it "does not save the record" do
@instance.should be_new_record @instance.should be_new_record
end end
else else
it "should save the record" do it "does save the record" do
@instance.should_not be_new_record @instance.should_not be_new_record
end end
end end

View File

@ -19,15 +19,15 @@ describe "a factory using make syntax" do
@instance = User.make(:last_name => 'Rye') @instance = User.make(:last_name => 'Rye')
end end
it "should use attributes from the factory" do it "uses attributes from the factory" do
@instance.first_name.should == 'Bill' @instance.first_name.should == 'Bill'
end end
it "should use attributes passed to make" do it "uses attributes passed to make" do
@instance.last_name.should == 'Rye' @instance.last_name.should == 'Rye'
end end
it "should build the record" do it "builds the record" do
@instance.should be_new_record @instance.should be_new_record
end end
end end
@ -37,15 +37,15 @@ describe "a factory using make syntax" do
@instance = User.make!(:last_name => 'Rye') @instance = User.make!(:last_name => 'Rye')
end end
it "should use attributes from the factory" do it "uses attributes from the factory" do
@instance.first_name.should == 'Bill' @instance.first_name.should == 'Bill'
end end
it "should use attributes passed to make" do it "uses attributes passed to make" do
@instance.last_name.should == 'Rye' @instance.last_name.should == 'Rye'
end end
it "should save the record" do it "saves the record" do
@instance.should_not be_new_record @instance.should_not be_new_record
end end
end end

View File

@ -28,15 +28,15 @@ describe "a factory using sham syntax" do
@instance = FactoryGirl.create(:user, :last_name => 'Rye') @instance = FactoryGirl.create(:user, :last_name => 'Rye')
end end
it "should support a sham called 'name'" do it "supports a sham called 'name'" do
@instance.first_name.should == 'Name' @instance.first_name.should == 'Name'
end end
it "should support shams with starting values" do it "supports shams with starting values" do
@instance.username.should == 'User-FOO' @instance.username.should == 'User-FOO'
end end
it "should use the sham for the email" do it "uses the sham for the email" do
@instance.email.should =~ /somebody\d@example.com/ @instance.email.should =~ /somebody\d@example.com/
end end
end end

View File

@ -29,29 +29,29 @@ describe "vintage syntax" do
end end
end end
it "should raise an ArgumentError when trying to use a non-existent strategy" do it "raises an ArgumentError when trying to use a non-existent strategy" do
lambda { expect {
Factory.define(:object, :default_strategy => :nonexistent) {} Factory.define(:object, :default_strategy => :nonexistent) {}
}.should raise_error(ArgumentError) }.to raise_error(ArgumentError)
end end
it "should raise Factory::SequenceAbuseError" do it "raises Factory::SequenceAbuseError" do
Factory.define :sequence_abuser, :class => User do |factory| Factory.define :sequence_abuser, :class => User do |factory|
factory.first_name { Factory.sequence(:name) } factory.first_name { Factory.sequence(:name) }
end end
lambda { expect {
Factory(:sequence_abuser) Factory(:sequence_abuser)
}.should raise_error(FactoryGirl::SequenceAbuseError) }.to raise_error(FactoryGirl::SequenceAbuseError)
end end
end end
describe Factory, "referencing a nonexistent factory as a parent" do describe Factory, "referencing a nonexistent factory as a parent" do
it "should raise an ArgumentError when trying to use a non-existent factory as parent" do it "raises an ArgumentError when trying to use a non-existent factory as parent" do
lambda { expect {
Factory.define(:child, :parent => :nonexsitent) {} Factory.define(:child, :parent => :nonexsitent) {}
Factory.build(:child) Factory.build(:child)
}.should raise_error(ArgumentError) }.to raise_error(ArgumentError)
end end
end end
@ -65,13 +65,13 @@ describe "defining a factory" do
FactoryGirl::DefinitionProxy.stubs(:new => @proxy) FactoryGirl::DefinitionProxy.stubs(:new => @proxy)
end end
it "should create a new factory using the specified name and options" do it "creates a new factory using the specified name and options" do
FactoryGirl::Factory.stubs(:new => @factory) FactoryGirl::Factory.stubs(:new => @factory)
Factory.define(@name, @options) {|f| } Factory.define(@name, @options) {|f| }
FactoryGirl::Factory.should have_received(:new).with(@name, @options) FactoryGirl::Factory.should have_received(:new).with(@name, @options)
end end
it "should pass the factory do the block" do it "passes the factory do the block" do
yielded = nil yielded = nil
Factory.define(@name) do |y| Factory.define(@name) do |y|
yielded = y yielded = y
@ -79,7 +79,7 @@ describe "defining a factory" do
yielded.should == @proxy yielded.should == @proxy
end end
it "should add the factory to the list of factories" do it "adds the factory to the list of factories" do
Factory.define(@name) {|f| } Factory.define(@name) {|f| }
@factory.should == FactoryGirl.factory_by_name(@name) @factory.should == FactoryGirl.factory_by_name(@name)
end end
@ -93,48 +93,48 @@ describe "after defining a factory" do
FactoryGirl.register_factory(@factory) FactoryGirl.register_factory(@factory)
end end
it "should use Proxy::AttributesFor for Factory.attributes_for" do it "uses Proxy::AttributesFor for Factory.attributes_for" do
@factory.stubs(:run => "result") @factory.stubs(:run => "result")
Factory.attributes_for(@name, :attr => 'value').should == 'result' Factory.attributes_for(@name, :attr => 'value').should == 'result'
@factory.should have_received(:run).with(FactoryGirl::Proxy::AttributesFor, :attr => 'value') @factory.should have_received(:run).with(FactoryGirl::Proxy::AttributesFor, :attr => 'value')
end end
it "should use Proxy::Build for Factory.build" do it "uses Proxy::Build for Factory.build" do
@factory.stubs(:run => "result") @factory.stubs(:run => "result")
Factory.build(@name, :attr => 'value').should == 'result' Factory.build(@name, :attr => 'value').should == 'result'
@factory.should have_received(:run).with(FactoryGirl::Proxy::Build, :attr => 'value') @factory.should have_received(:run).with(FactoryGirl::Proxy::Build, :attr => 'value')
end end
it "should use Proxy::Create for Factory.create" do it "uses Proxy::Create for Factory.create" do
@factory.stubs(:run => "result") @factory.stubs(:run => "result")
Factory.create(@name, :attr => 'value').should == 'result' Factory.create(@name, :attr => 'value').should == 'result'
@factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value') @factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value')
end end
it "should use Proxy::Stub for Factory.stub" do it "uses Proxy::Stub for Factory.stub" do
@factory.stubs(:run => "result") @factory.stubs(:run => "result")
Factory.stub(@name, :attr => 'value').should == 'result' Factory.stub(@name, :attr => 'value').should == 'result'
@factory.should have_received(:run).with(FactoryGirl::Proxy::Stub, :attr => 'value') @factory.should have_received(:run).with(FactoryGirl::Proxy::Stub, :attr => 'value')
end end
it "should use default strategy option as Factory.default_strategy" do it "uses default strategy option as Factory.default_strategy" do
@factory.stubs(:default_strategy => :create, :run => "result") @factory.stubs(:default_strategy => :create, :run => "result")
Factory.default_strategy(@name, :attr => 'value').should == 'result' Factory.default_strategy(@name, :attr => 'value').should == 'result'
@factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value') @factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value')
end end
it "should use the default strategy for the global Factory method" do it "uses the default strategy for the global Factory method" do
@factory.stubs(:default_strategy => :create, :run => "result") @factory.stubs(:default_strategy => :create, :run => "result")
Factory(@name, :attr => 'value').should == 'result' Factory(@name, :attr => 'value').should == 'result'
@factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value') @factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value')
end end
[:build, :create, :attributes_for, :stub].each do |method| [:build, :create, :attributes_for, :stub].each do |method|
it "should raise an ArgumentError on #{method} with a nonexistent factory" do it "raises an ArgumentError on #{method} with a nonexistent factory" do
lambda { Factory.send(method, :bogus) }.should raise_error(ArgumentError) expect { Factory.send(method, :bogus) }.to raise_error(ArgumentError)
end end
it "should recognize either 'name' or :name for Factory.#{method}" do it "recognizes either 'name' or :name for Factory.#{method}" do
@factory.stubs(:run) @factory.stubs(:run)
lambda { Factory.send(method, @name.to_s) }.should_not raise_error lambda { Factory.send(method, @name.to_s) }.should_not raise_error
lambda { Factory.send(method, @name.to_sym) }.should_not raise_error lambda { Factory.send(method, @name.to_sym) }.should_not raise_error
@ -147,17 +147,17 @@ describe "defining a sequence" do
@name = :count @name = :count
end end
it "should create a new sequence" do it "creates a new sequence" do
Factory.sequence(@name) Factory.sequence(@name)
Factory.next(@name).should == 1 Factory.next(@name).should == 1
end end
it "should use the supplied block as the sequence generator" do it "uses the supplied block as the sequence generator" do
Factory.sequence(@name) {|n| "user-#{n}" } Factory.sequence(@name) {|n| "user-#{n}" }
Factory.next(@name).should == "user-1" Factory.next(@name).should == "user-1"
end end
it "should use the supplied start_value as the sequence start_value" do it "uses the supplied start_value as the sequence start_value" do
Factory.sequence(@name, "A") Factory.sequence(@name, "A")
Factory.next(@name).should == "A" Factory.next(@name).should == "A"
end end
@ -175,12 +175,12 @@ describe "after defining a sequence" do
Factory.sequence(@name) {} Factory.sequence(@name) {}
end end
it "should call next on the sequence when sent next" do it "calls next on the sequence when sent next" do
Factory.next(@name) Factory.next(@name)
@sequence.should have_received(:next) @sequence.should have_received(:next)
end end
it "should return the value from the sequence" do it "returns the value from the sequence" do
Factory.next(@name).should == @value Factory.next(@name).should == @value
end end
end end
@ -196,7 +196,7 @@ describe "an attribute generated by an in-line sequence" do
@username = Factory.attributes_for(:user)[:username] @username = Factory.attributes_for(:user)[:username]
end end
it "should match the correct format" do it "matches the correct format" do
@username.should =~ /^username\d+$/ @username.should =~ /^username\d+$/
end end
@ -205,11 +205,11 @@ describe "an attribute generated by an in-line sequence" do
@another_username = Factory.attributes_for(:user)[:username] @another_username = Factory.attributes_for(:user)[:username]
end end
it "should match the correct format" do it "matches the correct format" do
@username.should =~ /^username\d+$/ @username.should =~ /^username\d+$/
end end
it "should not be the same as the first generated value" do it "is not the same as the first generated value" do
@another_username.should_not == @username @another_username.should_not == @username
end end
end end

View File

@ -4,7 +4,7 @@ describe FactoryGirl::DefinitionProxy do
let(:factory) { FactoryGirl::Factory.new(:object) } let(:factory) { FactoryGirl::Factory.new(:object) }
subject { FactoryGirl::DefinitionProxy.new(factory) } subject { FactoryGirl::DefinitionProxy.new(factory) }
it "should add a static attribute when an attribute is defined with a value" do it "adds a static attribute when an attribute is defined with a value" do
attribute = stub('attribute', :name => :name) attribute = stub('attribute', :name => :name)
FactoryGirl::Attribute::Static.stubs(:new => attribute) FactoryGirl::Attribute::Static.stubs(:new => attribute)
factory.stubs(:define_attribute) factory.stubs(:define_attribute)
@ -14,7 +14,7 @@ describe FactoryGirl::DefinitionProxy do
FactoryGirl::Attribute::Static.should have_received(:new).with(:name, "value", false) FactoryGirl::Attribute::Static.should have_received(:new).with(:name, "value", false)
end end
it "should add a dynamic attribute when an attribute is defined with a block" do it "adds a dynamic attribute when an attribute is defined with a block" do
attribute = stub('attribute', :name => :name) attribute = stub('attribute', :name => :name)
block = lambda {} block = lambda {}
FactoryGirl::Attribute::Dynamic.stubs(:new => attribute) FactoryGirl::Attribute::Dynamic.stubs(:new => attribute)
@ -25,16 +25,16 @@ describe FactoryGirl::DefinitionProxy do
factory.should have_received(:define_attribute).with(attribute) factory.should have_received(:define_attribute).with(attribute)
end end
it "should raise for an attribute with a value and a block" do it "raises for an attribute with a value and a block" do
lambda { expect {
subject.add_attribute(:name, 'value') {} subject.add_attribute(:name, 'value') {}
}.should raise_error(FactoryGirl::AttributeDefinitionError) }.to raise_error(FactoryGirl::AttributeDefinitionError)
end end
describe "child factories" do describe "child factories" do
its(:child_factories) { should == [] } its(:child_factories) { should == [] }
it "should be able to add child factories" do it "is be able to add child factories" do
block = lambda {} block = lambda {}
subject.factory(:admin, { :aliases => [:great] }, &block) subject.factory(:admin, { :aliases => [:great] }, &block)
subject.child_factories.should == [[:admin, { :aliases => [:great] }, block]] subject.child_factories.should == [[:admin, { :aliases => [:great] }, block]]
@ -42,13 +42,13 @@ describe FactoryGirl::DefinitionProxy do
end end
describe "adding an attribute using a in-line sequence" do describe "adding an attribute using a in-line sequence" do
it "should create the sequence" do it "creates the sequence" do
FactoryGirl::Sequence.stubs(:new) FactoryGirl::Sequence.stubs(:new)
subject.sequence(:name) {} subject.sequence(:name) {}
FactoryGirl::Sequence.should have_received(:new).with(:name, 1) FactoryGirl::Sequence.should have_received(:new).with(:name, 1)
end end
it "should create the sequence with a custom default value" do it "creates the sequence with a custom default value" do
FactoryGirl::Sequence.stubs(:new) FactoryGirl::Sequence.stubs(:new)
subject.sequence(:name, "A") {} subject.sequence(:name, "A") {}
FactoryGirl::Sequence.should have_received(:new).with(:name, "A") FactoryGirl::Sequence.should have_received(:new).with(:name, "A")

View File

@ -8,7 +8,7 @@ describe FactoryGirl::Factory do
FactoryGirl.register_factory(@factory) FactoryGirl.register_factory(@factory)
end end
it "should have a factory name" do it "has a factory name" do
@factory.name.should == @name @factory.name.should == @name
end end
@ -16,11 +16,11 @@ describe FactoryGirl::Factory do
@factory.factory_name.should == @name @factory.factory_name.should == @name
end end
it "should have a build class" do it "has a build class" do
@factory.build_class.should == @class @factory.build_class.should == @class
end end
it "should have a default strategy" do it "has a default strategy" do
@factory.default_strategy.should == :create @factory.default_strategy.should == :create
end end
@ -36,7 +36,7 @@ describe FactoryGirl::Factory do
proxy.should have_received(:result).with(block) proxy.should have_received(:result).with(block)
end end
it "should return associations" do it "returns associations" do
factory = FactoryGirl::Factory.new(:post) factory = FactoryGirl::Factory.new(:post)
FactoryGirl.register_factory(FactoryGirl::Factory.new(:admin)) FactoryGirl.register_factory(FactoryGirl::Factory.new(:admin))
factory.declare_attribute(FactoryGirl::Declaration::Association.new(:author, {})) factory.declare_attribute(FactoryGirl::Declaration::Association.new(:author, {}))
@ -48,7 +48,7 @@ describe FactoryGirl::Factory do
factory.associations.size.should == 3 factory.associations.size.should == 3
end end
it "should raise for a self referencing association" do it "raises for a self referencing association" do
factory = FactoryGirl::Factory.new(:post) factory = FactoryGirl::Factory.new(:post)
lambda { lambda {
factory.declare_attribute(FactoryGirl::Declaration::Association.new(:parent, { :factory => :post })) factory.declare_attribute(FactoryGirl::Declaration::Association.new(:parent, { :factory => :post }))
@ -63,20 +63,20 @@ describe FactoryGirl::Factory do
@hash = { @name => @value } @hash = { @name => @value }
end end
it "should return the overridden value in the generated attributes" do it "returns the overridden value in the generated attributes" do
declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!') declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!')
@factory.declare_attribute(declaration) @factory.declare_attribute(declaration)
result = @factory.run(FactoryGirl::Proxy::AttributesFor, @hash) result = @factory.run(FactoryGirl::Proxy::AttributesFor, @hash)
result[@name].should == @value result[@name].should == @value
end end
it "should not call a lazy attribute block for an overridden attribute" do it "does not call a lazy attribute block for an overridden attribute" do
declaration = FactoryGirl::Declaration::Dynamic.new(@name, lambda { flunk }) declaration = FactoryGirl::Declaration::Dynamic.new(@name, lambda { flunk })
@factory.declare_attribute(declaration) @factory.declare_attribute(declaration)
result = @factory.run(FactoryGirl::Proxy::AttributesFor, @hash) result = @factory.run(FactoryGirl::Proxy::AttributesFor, @hash)
end end
it "should override a symbol parameter with a string parameter" do it "overrides a symbol parameter with a string parameter" do
declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!') declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!')
@factory.declare_attribute(declaration) @factory.declare_attribute(declaration)
@hash = { @name.to_s => @value } @hash = { @name.to_s => @value }
@ -93,26 +93,26 @@ describe FactoryGirl::Factory do
:test_alias => 'new') :test_alias => 'new')
end end
it "should use the passed in value for the alias" do it "uses the passed in value for the alias" do
@result[:test_alias].should == 'new' @result[:test_alias].should == 'new'
end end
it "should discard the predefined value for the attribute" do it "discards the predefined value for the attribute" do
@result[:test].should be_nil @result[:test].should be_nil
end end
end end
it "should guess the build class from the factory name" do it "guesses the build class from the factory name" do
@factory.build_class.should == User @factory.build_class.should == User
end end
it "should create a new factory using the class of the parent" do it "creates a new factory using the class of the parent" do
child = FactoryGirl::Factory.new(:child, :parent => @factory.name) child = FactoryGirl::Factory.new(:child, :parent => @factory.name)
child.ensure_compiled child.ensure_compiled
child.build_class.should == @factory.build_class child.build_class.should == @factory.build_class
end end
it "should create a new factory while overriding the parent class" do it "creates a new factory while overriding the parent class" do
child = FactoryGirl::Factory.new(:child, :class => String, :parent => @factory.name) child = FactoryGirl::Factory.new(:child, :class => String, :parent => @factory.name)
child.ensure_compiled child.ensure_compiled
child.build_class.should == String child.build_class.should == String

View File

@ -78,7 +78,7 @@ describe "definition loading" do
describe "with several factories files under #{dir}/factories in non-alphabetical order" do describe "with several factories files under #{dir}/factories in non-alphabetical order" do
in_directory_with_files File.join(dir, 'factories', 'b.rb'), in_directory_with_files File.join(dir, 'factories', 'b.rb'),
File.join(dir, 'factories', 'a.rb') File.join(dir, 'factories', 'a.rb')
it "should load the files in the right order" do it "loads the files in the right order" do
FactoryGirl.stubs(:load) FactoryGirl.stubs(:load)
sorted_load_order = sequence("load order") sorted_load_order = sequence("load order")
FactoryGirl.expects(:load).with(includes("a.rb")).in_sequence(sorted_load_order) FactoryGirl.expects(:load).with(includes("a.rb")).in_sequence(sorted_load_order)