From d0149b1c8f382fd9733a1445ed904ac467e2d2cd Mon Sep 17 00:00:00 2001 From: Jeff Casimir Date: Thu, 26 Mar 2015 23:21:37 -0600 Subject: [PATCH] Rewrite some of the .stub calls to use allow --- spec/draper/decoratable_spec.rb | 2 +- spec/draper/factory_spec.rb | 6 +++--- spec/draper/helper_proxy_spec.rb | 2 +- spec/generators/decorator/decorator_generator_spec.rb | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/draper/decoratable_spec.rb b/spec/draper/decoratable_spec.rb index c8f5619..6f608f4 100644 --- a/spec/draper/decoratable_spec.rb +++ b/spec/draper/decoratable_spec.rb @@ -162,7 +162,7 @@ module Draper context "for ActiveModel classes" do it "infers the decorator from the model name" do - Product.stub(:model_name).and_return("Other") + allow(Product).to receive(:model_name){"Other"} expect(Product.decorator_class).to be OtherDecorator end diff --git a/spec/draper/factory_spec.rb b/spec/draper/factory_spec.rb index 3936f10..03a4296 100644 --- a/spec/draper/factory_spec.rb +++ b/spec/draper/factory_spec.rb @@ -99,7 +99,7 @@ module Draper options = {foo: "bar"} worker = Factory::Worker.new(double, object) decorator = ->(*){} - worker.stub decorator: decorator + allow(worker).to receive(:decorator){ decorator } decorator.should_receive(:call).with(object, options).and_return(:decorated) expect(worker.call(options)).to be :decorated @@ -227,8 +227,8 @@ module Draper it "returns the .decorate_collection method from the object's decorator" do object = [] decorator_class = Class.new(Decorator) - object.stub decorator_class: decorator_class - object.stub decorate: nil + allow(object).to receive(:decorator_class){ decorator_class } + allow(object).to receive(:decorate){ nil } worker = Factory::Worker.new(nil, object) decorator_class.should_receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated) diff --git a/spec/draper/helper_proxy_spec.rb b/spec/draper/helper_proxy_spec.rb index a2b184e..ce5312b 100644 --- a/spec/draper/helper_proxy_spec.rb +++ b/spec/draper/helper_proxy_spec.rb @@ -52,7 +52,7 @@ module Draper view_context = double helper_proxy = HelperProxy.new(view_context) - view_context.stub(:capture) { |*args, &block| [*args, block.call] } + allow(view_context).to receive(:capture) { |*args, &block| [*args, block.call] } expect(helper_proxy.capture(:first_arg, :second_arg){:yielded}).to \ be_eql [:first_arg, :second_arg, :yielded] end diff --git a/spec/generators/decorator/decorator_generator_spec.rb b/spec/generators/decorator/decorator_generator_spec.rb index fc0bff6..08a9601 100644 --- a/spec/generators/decorator/decorator_generator_spec.rb +++ b/spec/generators/decorator/decorator_generator_spec.rb @@ -40,8 +40,9 @@ describe Rails::Generators::DecoratorGenerator do context "with an ApplicationDecorator" do before do - Object.any_instance.stub(:require).with("application_decorator").and_return ( - stub_const "ApplicationDecorator", Class.new) + allow_any_instance_of(Object).to receive(:require).with("application_decorator").and_return( + stub_const "ApplicationDecorator", Class.new + ) end before { run_generator %w(YourModel) }