Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Registries are named

This allows for easier debugging when code attempts to access traits,
sequences, or factories and doesn't find what it was looking for.

Closes #212
  • Loading branch information...
commit 7fdf1a8858c5185e9a38d21348c8ec0fba404f22 1 parent 65fc7d7
@joshuaclayton joshuaclayton authored
View
6 lib/factory_girl.rb
@@ -44,7 +44,7 @@ class InvalidCallbackNameError < RuntimeError; end
class DuplicateDefinitionError < RuntimeError; end
def self.factories
- @factories ||= Registry.new
+ @factories ||= Registry.new("Factory")
end
def self.register_factory(factory)
@@ -56,7 +56,7 @@ def self.factory_by_name(name)
end
def self.sequences
- @sequences ||= Registry.new
+ @sequences ||= Registry.new("Sequence")
end
def self.register_sequence(sequence)
@@ -68,7 +68,7 @@ def self.sequence_by_name(name)
end
def self.traits
- @traits ||= Registry.new
+ @traits ||= Registry.new("Trait")
end
def self.register_trait(trait)
View
7 lib/factory_girl/registry.rb
@@ -2,7 +2,8 @@ module FactoryGirl
class Registry
include Enumerable
- def initialize
+ def initialize(name)
+ @name = name
@items = {}
end
@@ -12,7 +13,7 @@ def add(item)
end
def find(name)
- @items[name.to_sym] or raise ArgumentError.new("Not registered: #{name.to_s}")
+ @items[name.to_sym] or raise ArgumentError.new("#{@name} not registered: #{name.to_s}")
end
def each(&block)
@@ -35,7 +36,7 @@ def clear
def add_as(name, item)
if registered?(name)
- raise DuplicateDefinitionError, "Already defined: #{name}"
+ raise DuplicateDefinitionError, "#{@name} already registered: #{name}"
else
@items[name.to_sym] = item
end
View
2  spec/acceptance/modify_factories_spec.rb
@@ -39,7 +39,7 @@
it "doesn't allow the factory to be subsequently defined" do
expect do
FactoryGirl.define { factory :user }
- end.to raise_error(FactoryGirl::DuplicateDefinitionError)
+ end.to raise_error(FactoryGirl::DuplicateDefinitionError, "Factory already registered: user")
end
it "does allow the factory to be subsequently modified" do
View
2  spec/acceptance/traits_spec.rb
@@ -165,6 +165,6 @@
context "factory outside of scope" do
subject { FactoryGirl.create(:user_without_admin_scoping) }
- it { expect { subject }.to raise_error(ArgumentError, "Not registered: admin_trait") }
+ it { expect { subject }.to raise_error(ArgumentError, "Trait not registered: admin_trait") }
end
end
View
7 spec/factory_girl/registry_spec.rb
@@ -6,8 +6,9 @@
let(:factory) { FactoryGirl::Factory.new(:object) }
let(:other_factory) { FactoryGirl::Factory.new(:string) }
let(:factory_with_aliases) { FactoryGirl::Factory.new(:string, :aliases => aliases) }
+ let(:registry_name) { "Factory" }
- subject { FactoryGirl::Registry.new }
+ subject { FactoryGirl::Registry.new(registry_name) }
it { should be_kind_of(Enumerable) }
@@ -17,7 +18,7 @@
end
it "raises when finding an unregistered factory" do
- expect { subject.find(:bogus) }.to raise_error(ArgumentError)
+ expect { subject.find(:bogus) }.to raise_error(ArgumentError, "Factory not registered: bogus")
end
it "adds and returns a factory" do
@@ -62,7 +63,7 @@
it "doesn't allow a duplicate name" do
expect { 2.times { subject.add(factory) } }.
- to raise_error(FactoryGirl::DuplicateDefinitionError)
+ to raise_error(FactoryGirl::DuplicateDefinitionError, "Factory already registered: object")
end
it "registers aliases" do
Please sign in to comment.
Something went wrong with that request. Please try again.