Skip to content

Commit

Permalink
Refactor definition_proxy_spec
Browse files Browse the repository at this point in the history
This introduces a couple of things: firstly, there's now a MockFactory
that allows for introspection instead of spying all over the place. This
should make tests a lot less brittle. Secondly, a couple of handy
matchers have been made available to perform assertions against the
mock.
  • Loading branch information
joshuaclayton committed Oct 14, 2011
1 parent 41f73b5 commit 180eb8b
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 140 deletions.
3 changes: 3 additions & 0 deletions lib/factory_girl/declaration.rb
Expand Up @@ -15,5 +15,8 @@ def ignore
def to_attributes
build
end

protected
attr_reader :ignored
end
end
8 changes: 8 additions & 0 deletions lib/factory_girl/declaration/association.rb
Expand Up @@ -6,6 +6,14 @@ def initialize(name, options)
@options = options
end

def ==(other)
name == other.name &&
options == other.options
end

protected
attr_reader :options

private

def build
Expand Down
9 changes: 9 additions & 0 deletions lib/factory_girl/declaration/dynamic.rb
Expand Up @@ -6,6 +6,15 @@ def initialize(name, ignored = false, block = nil)
@block = block
end

def ==(other)
name == other.name &&
ignored == other.ignored &&
block == other.block
end

protected
attr_reader :block

private

def build
Expand Down
9 changes: 9 additions & 0 deletions lib/factory_girl/declaration/implicit.rb
Expand Up @@ -6,6 +6,15 @@ def initialize(name, factory = nil, ignored = false)
@factory = factory
end

def ==(other)
name == other.name &&
factory == other.factory &&
ignored == other.ignored
end

protected
attr_reader :factory

private

def build
Expand Down
9 changes: 9 additions & 0 deletions lib/factory_girl/declaration/static.rb
Expand Up @@ -6,6 +6,15 @@ def initialize(name, value, ignored = false)
@value = value
end

def ==(other)
name == other.name &&
value == other.value &&
ignored == other.ignored
end

protected
attr_reader :value

private

def build
Expand Down
11 changes: 10 additions & 1 deletion lib/factory_girl/trait.rb
Expand Up @@ -5,9 +5,10 @@ class Trait
def initialize(name, &block) #:nodoc:
@name = name
@attribute_list = AttributeList.new
@block = block

proxy = FactoryGirl::DefinitionProxy.new(self)
proxy.instance_eval(&block) if block_given?
proxy.instance_eval(&@block) if block_given?
end

def declare_attribute(declaration)
Expand All @@ -33,5 +34,13 @@ def attributes
def names
[@name]
end

def ==(other)
name == other.name &&
block == other.block
end

protected
attr_reader :block
end
end

0 comments on commit 180eb8b

Please sign in to comment.