Rewrite some of the .stub calls to use allow

This commit is contained in:
Jeff Casimir 2015-03-26 23:21:37 -06:00
parent 3d775502c8
commit d0149b1c8f
4 changed files with 8 additions and 7 deletions

View File

@ -162,7 +162,7 @@ module Draper
context "for ActiveModel classes" do context "for ActiveModel classes" do
it "infers the decorator from the model name" 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 expect(Product.decorator_class).to be OtherDecorator
end end

View File

@ -99,7 +99,7 @@ module Draper
options = {foo: "bar"} options = {foo: "bar"}
worker = Factory::Worker.new(double, object) worker = Factory::Worker.new(double, object)
decorator = ->(*){} decorator = ->(*){}
worker.stub decorator: decorator allow(worker).to receive(:decorator){ decorator }
decorator.should_receive(:call).with(object, options).and_return(:decorated) decorator.should_receive(:call).with(object, options).and_return(:decorated)
expect(worker.call(options)).to be :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 it "returns the .decorate_collection method from the object's decorator" do
object = [] object = []
decorator_class = Class.new(Decorator) decorator_class = Class.new(Decorator)
object.stub decorator_class: decorator_class allow(object).to receive(:decorator_class){ decorator_class }
object.stub decorate: nil allow(object).to receive(:decorate){ nil }
worker = Factory::Worker.new(nil, object) worker = Factory::Worker.new(nil, object)
decorator_class.should_receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated) decorator_class.should_receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated)

View File

@ -52,7 +52,7 @@ module Draper
view_context = double view_context = double
helper_proxy = HelperProxy.new(view_context) 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 \ expect(helper_proxy.capture(:first_arg, :second_arg){:yielded}).to \
be_eql [:first_arg, :second_arg, :yielded] be_eql [:first_arg, :second_arg, :yielded]
end end

View File

@ -40,8 +40,9 @@ describe Rails::Generators::DecoratorGenerator do
context "with an ApplicationDecorator" do context "with an ApplicationDecorator" do
before do before do
Object.any_instance.stub(:require).with("application_decorator").and_return ( allow_any_instance_of(Object).to receive(:require).with("application_decorator").and_return(
stub_const "ApplicationDecorator", Class.new) stub_const "ApplicationDecorator", Class.new
)
end end
before { run_generator %w(YourModel) } before { run_generator %w(YourModel) }