Permalink
Browse files

Converted to RR

  • Loading branch information...
jferris committed Apr 8, 2009
1 parent 0c902bd commit e1532145f8f61b0e4f97c87b75411df43bee379c
@@ -17,9 +17,10 @@ class AssociationAttributeTest < Test::Unit::TestCase
end
should "tell the proxy to associate when being added to a proxy" do
- proxy = mock('proxy')
- proxy.expects(:associate).with(@name, @factory, @overrides)
+ proxy = "proxy"
+ stub(proxy).associate
@attr.add_to(proxy)
+ assert_received(proxy) {|p| p.associate(@name, @factory, @overrides) }
end
end
View
@@ -13,9 +13,10 @@ class AttributeTest < Test::Unit::TestCase
end
should "do nothing when being added to a proxy" do
- @proxy = mock('proxy')
- @proxy.expects(:set).never
+ @proxy = "proxy"
+ stub(@proxy).set
@attr.add_to(@proxy)
+ assert_received(@proxy) {|p| p.set.never }
end
end
@@ -9,7 +9,7 @@ class AttributesForProxyTest < Test::Unit::TestCase
context "when asked to associate with another factory" do
setup do
- Factory.stubs(:create)
+ stub(Factory).create
@proxy.associate(:owner, :user, {})
end
@@ -23,8 +23,9 @@ class AttributesForProxyTest < Test::Unit::TestCase
end
should "not call Factory.create when building an association" do
- Factory.expects(:create).never
+ stub(Factory).create
assert_nil @proxy.association(:user)
+ assert_received(Factory) {|p| p.create.never }
end
should "always return nil when building an association" do
@@ -5,44 +5,45 @@ class BuildProxyTest < Test::Unit::TestCase
context "with a class to build" do
setup do
@class = Class.new
- @instance = mock('built-instance')
- @association = mock('associated-instance')
-
- @class. stubs(:new). returns(@instance)
- @instance.stubs(:attribute).returns('value')
- Factory. stubs(:create). returns(@association)
- @instance.stubs(:attribute=)
- @instance.stubs(:owner=)
+ @instance = "built-instance"
+ @association = "associated-instance"
+
+ stub(@class).new { @instance }
+ stub(@instance).attribute { 'value' }
+ stub(Factory).create { @association }
+ stub(@instance, :attribute=)
+ stub(@instance, :owner=)
end
context "the build proxy" do
setup do
@proxy = Factory::Proxy::Build.new(@class)
end
- before_should "instantiate the class" do
- @class.expects(:new).with().returns(@instance)
+ should "instantiate the class" do
+ assert_received(@class) {|p| p.new }
end
context "when asked to associate with another factory" do
setup do
@proxy.associate(:owner, :user, {})
end
- before_should "create the associated instance" do
- Factory.expects(:create).with(:user, {}).returns(@association)
+ should "create the associated instance" do
+ assert_received(Factory) {|p| p.create(:user, {}) }
end
- before_should "set the associated instance" do
- @instance.expects(:owner=).with(@association)
+ should "set the associated instance" do
+ assert_received(@instance) {|p| p.method_missing(:owner=, @association) }
end
end
should "call Factory.create when building an association" do
association = 'association'
attribs = { :first_name => 'Billy' }
- Factory.expects(:create).with(:user, attribs).returns(association)
+ stub(Factory).create { association }
assert_equal association, @proxy.association(:user, attribs)
+ assert_received(Factory) {|p| p.create(:user, attribs) }
end
should "return the built instance when asked for the result" do
@@ -51,11 +52,12 @@ class BuildProxyTest < Test::Unit::TestCase
context "when setting an attribute" do
setup do
+ stub(@instance).attribute = 'value'
@proxy.set(:attribute, 'value')
end
- before_should "set that value" do
- @instance.expects(:attribute=).with('value')
+ should "set that value" do
+ assert_received(@instance) {|p| p.method_missing(:attribute=, 'value') }
end
end
@@ -64,8 +66,8 @@ class BuildProxyTest < Test::Unit::TestCase
@result = @proxy.get(:attribute)
end
- before_should "ask the built class for the value" do
- @instance.expects(:attribute).with().returns('value')
+ should "ask the built class for the value" do
+ assert_received(@instance) {|p| p.attribute }
end
should "return the value for that attribute" do
@@ -5,54 +5,55 @@ class CreateProxyTest < Test::Unit::TestCase
context "with a class to build" do
setup do
@class = Class.new
- @instance = mock('built-instance')
- @association = mock('associated-instance')
-
- @class. stubs(:new). returns(@instance)
- Factory. stubs(:create). returns(@association)
- @instance.stubs(:attribute).returns('value')
- @instance.stubs(:attribute=)
- @instance.stubs(:owner=)
- @instance.stubs(:save!)
+ @instance = "built-instance"
+ @association = "associated-instance"
+
+ stub(@class).new { @instance }
+ stub(Factory).create { @association }
+ stub(@instance).attribute { 'value' }
+ stub(@instance, :attribute=)
+ stub(@instance, :owner=)
+ stub(@instance).save!
end
context "the create proxy" do
setup do
@proxy = Factory::Proxy::Create.new(@class)
end
- before_should "instantiate the class" do
- @class.expects(:new).with().returns(@instance)
+ should "instantiate the class" do
+ assert_received(@class) {|p| p.new }
end
context "when asked to associate with another factory" do
setup do
@proxy.associate(:owner, :user, {})
end
- before_should "create the associated instance" do
- Factory.expects(:create).with(:user, {}).returns(@association)
+ should "create the associated instance" do
+ assert_received(Factory) {|p| p.create(:user, {}) }
end
- before_should "set the associated instance" do
- @instance.expects(:owner=).with(@association)
+ should "set the associated instance" do
+ assert_received(@instance) {|p| p.method_missing(:owner=, @association) }
end
end
should "call Factory.create when building an association" do
association = 'association'
attribs = { :first_name => 'Billy' }
- Factory.expects(:create).with(:user, attribs).returns(association)
+ stub(Factory).create { association }
assert_equal association, @proxy.association(:user, attribs)
+ assert_received(Factory) {|p| p.create(:user, attribs) }
end
context "when asked for the result" do
setup do
@result = @proxy.result
end
- before_should "save the instance" do
- @instance.expects(:save!).with()
+ should "save the instance" do
+ assert_received(@instance) {|p| p.save! }
end
should "return the built instance" do
@@ -65,8 +66,8 @@ class CreateProxyTest < Test::Unit::TestCase
@proxy.set(:attribute, 'value')
end
- before_should "set that value" do
- @instance.expects(:attribute=).with('value')
+ should "set that value" do
+ assert_received(@instance) {|p| p.method_missing(:attribute=, 'value') }
end
end
@@ -75,8 +76,8 @@ class CreateProxyTest < Test::Unit::TestCase
@result = @proxy.get(:attribute)
end
- before_should "ask the built class for the value" do
- @instance.expects(:attribute).with().returns('value')
+ should "ask the built class for the value" do
+ assert_received(@instance) {|p| p.attribute }
end
should "return the value for that attribute" do
@@ -14,17 +14,19 @@ class DynamicAttributeTest < Test::Unit::TestCase
end
should "call the block to set a value" do
- @proxy = mock('proxy')
- @proxy.expects(:set).with(@name, 'value')
+ @proxy = "proxy"
+ stub(@proxy).set
@attr.add_to(@proxy)
+ assert_received(@proxy) {|p| p.set(@name, 'value') }
end
should "yield the proxy to the block when adding its value to a proxy" do
@block = lambda {|a| a }
@attr = Factory::Attribute::Dynamic.new(:user, @block)
- @proxy = mock('proxy')
- @proxy.expects(:set).with(:user, @proxy)
+ @proxy = "proxy"
+ stub(@proxy).set
@attr.add_to(@proxy)
+ assert_received(@proxy) {|p| p.set(:user, @proxy) }
end
end
Oops, something went wrong.

0 comments on commit e153214

Please sign in to comment.