Permalink
Browse files

Refactor definition_proxy_spec

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...
1 parent 41f73b5 commit 180eb8bec704558a52cf3a13ec2c88d9d9758bcb @joshuaclayton joshuaclayton committed Oct 14, 2011
@@ -15,5 +15,8 @@ def ignore
def to_attributes
build
end
+
+ protected
+ attr_reader :ignored
end
end
@@ -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
@@ -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
@@ -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
@@ -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
View
@@ -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)
@@ -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
Oops, something went wrong.

0 comments on commit 180eb8b

Please sign in to comment.