From 036be08ded836504f1cd4c94d689928b14b1121d Mon Sep 17 00:00:00 2001 From: Matt Casper Date: Thu, 21 May 2015 09:53:15 -0700 Subject: [PATCH] Update the rest of the specs to rspec3 syntax --- spec/draper/collection_decorator_spec.rb | 18 ++--- spec/draper/decoratable_spec.rb | 20 +++--- spec/draper/decorated_association_spec.rb | 12 ++-- spec/draper/decorates_assigned_spec.rb | 8 +-- spec/draper/decorator_spec.rb | 72 +++++++++---------- spec/draper/factory_spec.rb | 46 ++++++------ spec/draper/finders_spec.rb | 42 +++++------ spec/draper/helper_proxy_spec.rb | 4 +- spec/draper/lazy_helpers_spec.rb | 4 +- .../view_context/build_strategy_spec.rb | 8 +-- spec/draper/view_context_spec.rb | 42 +++++------ .../controller/controller_generator_spec.rb | 2 +- .../decorator/decorator_generator_spec.rb | 18 ++--- spec/support/shared_examples/view_helpers.rb | 16 ++--- 14 files changed, 156 insertions(+), 156 deletions(-) diff --git a/spec/draper/collection_decorator_spec.rb b/spec/draper/collection_decorator_spec.rb index d2e256c..39e3e38 100644 --- a/spec/draper/collection_decorator_spec.rb +++ b/spec/draper/collection_decorator_spec.rb @@ -63,7 +63,7 @@ module Draper it "does not trigger decoration" do decorator = CollectionDecorator.new([]) - decorator.should_not_receive(:decorated_collection) + expect(decorator).not_to receive(:decorated_collection) decorator.context = {other: "context"} end @@ -110,12 +110,12 @@ module Draper protect_class ProductsDecorator it "defaults the :to option to :object" do - Object.should_receive(:delegate).with(:foo, :bar, to: :object) + expect(Object).to receive(:delegate).with(:foo, :bar, to: :object) ProductsDecorator.delegate :foo, :bar end it "does not overwrite the :to option if supplied" do - Object.should_receive(:delegate).with(:foo, :bar, to: :baz) + expect(Object).to receive(:delegate).with(:foo, :bar, to: :baz) ProductsDecorator.delegate :foo, :bar, to: :baz end end @@ -125,7 +125,7 @@ module Draper it "decorates Enumerable#find" do decorator = CollectionDecorator.new([]) - decorator.decorated_collection.should_receive(:find).and_return(:delegated) + expect(decorator.decorated_collection).to receive(:find).and_return(:delegated) expect(decorator.find{|p| p.title == "title"}).to be :delegated end end @@ -136,7 +136,7 @@ module Draper found = double(decorate: :decorated) decorator = CollectionDecorator.new(object) - object.should_receive(:find).and_return(found) + expect(object).to receive(:find).and_return(found) ActiveSupport::Deprecation.silence do expect(decorator.find(1)).to be :decorated end @@ -149,7 +149,7 @@ module Draper it "delegates to the decorated collection" do decorator = CollectionDecorator.new([]) - decorator.decorated_collection.should_receive(:to_ary).and_return(:delegated) + expect(decorator.decorated_collection).to receive(:to_ary).and_return(:delegated) expect(decorator.to_ary).to be :delegated end end @@ -157,7 +157,7 @@ module Draper it "delegates array methods to the decorated collection" do decorator = CollectionDecorator.new([]) - decorator.decorated_collection.should_receive(:[]).with(42).and_return(:delegated) + expect(decorator.decorated_collection).to receive(:[]).with(42).and_return(:delegated) expect(decorator[42]).to be :delegated end @@ -267,14 +267,14 @@ module Draper describe '#kind_of?' do it 'asks the kind of its decorated collection' do decorator = ProductsDecorator.new([]) - decorator.decorated_collection.should_receive(:kind_of?).with(Array).and_return("true") + expect(decorator.decorated_collection).to receive(:kind_of?).with(Array).and_return("true") expect(decorator.kind_of?(Array)).to eq "true" end context 'when asking the underlying collection returns false' do it 'asks the CollectionDecorator instance itself' do decorator = ProductsDecorator.new([]) - decorator.decorated_collection.stub(:kind_of?).with(::Draper::CollectionDecorator).and_return(false) + allow(decorator.decorated_collection).to receive(:kind_of?).with(::Draper::CollectionDecorator).and_return(false) expect(decorator.kind_of?(::Draper::CollectionDecorator)).to be true end end diff --git a/spec/draper/decoratable_spec.rb b/spec/draper/decoratable_spec.rb index 6f608f4..b6de4b9 100644 --- a/spec/draper/decoratable_spec.rb +++ b/spec/draper/decoratable_spec.rb @@ -22,7 +22,7 @@ module Draper it "uses the #decorator_class" do product = Product.new - product.stub decorator_class: OtherDecorator + allow(product).to receive_messages decorator_class: OtherDecorator expect(product.decorate).to be_an_instance_of OtherDecorator end @@ -70,7 +70,7 @@ module Draper it "delegates to .decorator_class" do product = Product.new - Product.should_receive(:decorator_class).and_return(:some_decorator) + expect(Product).to receive(:decorator_class).and_return(:some_decorator) expect(product.decorator_class).to be :some_decorator end end @@ -83,14 +83,14 @@ module Draper it "is true when #== is true" do product = Product.new - product.should_receive(:==).and_return(true) + expect(product).to receive(:==).and_return(true) expect(product === :anything).to be_truthy end it "is false when #== is false" do product = Product.new - product.should_receive(:==).and_return(false) + expect(product).to receive(:==).and_return(false) expect(product === :anything).to be_falsey end end @@ -132,17 +132,17 @@ module Draper it "calls #decorate_collection on .decorator_class" do scoped = [Product.new] - Product.stub scoping_method => scoped + allow(Product).to receive_messages scoping_method => scoped - Product.decorator_class.should_receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection) + expect(Product.decorator_class).to receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection) expect(Product.decorate).to be :decorated_collection end it "accepts options" do options = {with: ProductDecorator, context: {some: "context"}} - Product.stub scoping_method => [] + allow(Product).to receive_messages scoping_method => [] - Product.decorator_class.should_receive(:decorate_collection).with([], options) + expect(Product.decorator_class).to receive(:decorate_collection).with([], options) Product.decorate(options) end end @@ -177,7 +177,7 @@ module Draper context "for ActiveModel classes" do it "infers the decorator from the model name" do - Namespaced::Product.stub(:model_name).and_return("Namespaced::Other") + allow(Namespaced::Product).to receive(:model_name).and_return("Namespaced::Other") expect(Namespaced::Product.decorator_class).to be Namespaced::OtherDecorator end @@ -192,7 +192,7 @@ module Draper context "when an unrelated NameError is thrown" do it "re-raises that error" do - String.any_instance.stub(:constantize) { Draper::Base } + allow_any_instance_of(String).to receive(:constantize) { Draper::Base } expect{Product.decorator_class}.to raise_error NameError, /Draper::Base/ end end diff --git a/spec/draper/decorated_association_spec.rb b/spec/draper/decorated_association_spec.rb index 3bd2de6..daf3532 100644 --- a/spec/draper/decorated_association_spec.rb +++ b/spec/draper/decorated_association_spec.rb @@ -16,20 +16,20 @@ module Draper it "creates a factory" do options = {with: Decorator, context: {foo: "bar"}} - Factory.should_receive(:new).with(options) + expect(Factory).to receive(:new).with(options) DecoratedAssociation.new(double, :association, options) end describe ":with option" do it "defaults to nil" do - Factory.should_receive(:new).with(with: nil, context: anything()) + expect(Factory).to receive(:new).with(with: nil, context: anything()) DecoratedAssociation.new(double, :association, {}) end end describe ":context option" do it "defaults to the identity function" do - Factory.should_receive(:new) do |options| + expect(Factory).to receive(:new) do |options| options[:context].call(:anything) == :anything end DecoratedAssociation.new(double, :association, {}) @@ -48,7 +48,7 @@ module Draper decorated_association = DecoratedAssociation.new(owner, :association, {}) decorated = double - factory.should_receive(:decorate).with(associated, context_args: owner_context).and_return(decorated) + expect(factory).to receive(:decorate).with(associated, context_args: owner_context).and_return(decorated) expect(decorated_association.call).to be decorated end @@ -59,7 +59,7 @@ module Draper decorated_association = DecoratedAssociation.new(owner, :association, {}) decorated = double - factory.should_receive(:decorate).once.and_return(decorated) + expect(factory).to receive(:decorate).once.and_return(decorated) expect(decorated_association.call).to be decorated expect(decorated_association.call).to be decorated end @@ -74,7 +74,7 @@ module Draper decorated_association = DecoratedAssociation.new(owner, :association, scope: :applied_scope) decorated = double - factory.should_receive(:decorate).with(scoped, anything()).and_return(decorated) + expect(factory).to receive(:decorate).with(scoped, anything()).and_return(decorated) expect(decorated_association.call).to be decorated end end diff --git a/spec/draper/decorates_assigned_spec.rb b/spec/draper/decorates_assigned_spec.rb index 9694ca5..2ac2074 100644 --- a/spec/draper/decorates_assigned_spec.rb +++ b/spec/draper/decorates_assigned_spec.rb @@ -28,14 +28,14 @@ module Draper end it "creates a factory" do - Factory.should_receive(:new).once + expect(Factory).to receive(:new).once controller_class.decorates_assigned :article, :author end it "passes options to the factory" do options = {foo: "bar"} - Factory.should_receive(:new).with(options) + expect(Factory).to receive(:new).with(options) controller_class.decorates_assigned :article, :author, options end @@ -49,7 +49,7 @@ module Draper controller = controller_class.new controller.instance_variable_set "@article", object - factory.should_receive(:decorate).with(object, context_args: controller).and_return(:decorated) + expect(factory).to receive(:decorate).with(object, context_args: controller).and_return(:decorated) expect(controller.article).to be :decorated end @@ -60,7 +60,7 @@ module Draper controller_class.decorates_assigned :article controller = controller_class.new - factory.should_receive(:decorate).once + expect(factory).to receive(:decorate).once controller.article controller.article end diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index 36eb83e..b1af6b9 100755 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -73,7 +73,7 @@ module Draper decorated = OtherDecorator.new(Decorator.new(Model.new)) warning_message = nil - Object.any_instance.stub(:warn) { |instance, message| warning_message = message } + allow_any_instance_of(Object).to receive(:warn) { |instance, message| warning_message = message } expect{Decorator.new(decorated)}.to change{warning_message} expect(warning_message).to start_with "Reapplying Draper::Decorator" @@ -82,7 +82,7 @@ module Draper it "decorates anyway" do decorated = OtherDecorator.new(Decorator.new(Model.new)) - Object.any_instance.stub(:warn) + allow_any_instance_of(Object).to receive(:warn) redecorated = Decorator.decorate(decorated) expect(redecorated.object).to be decorated @@ -102,7 +102,7 @@ module Draper describe ".decorate_collection" do describe "options validation" do - before { CollectionDecorator.stub(:new) } + before { allow(CollectionDecorator).to receive(:new) } it "does not raise error on valid options" do valid_options = {with: OtherDecorator, context: {}} @@ -118,14 +118,14 @@ module Draper it "creates a CollectionDecorator using itself for each item" do object = [Model.new] - CollectionDecorator.should_receive(:new).with(object, with: Decorator) + expect(CollectionDecorator).to receive(:new).with(object, with: Decorator) Decorator.decorate_collection(object) end it "passes options to the collection decorator" do options = {with: OtherDecorator, context: {some: "context"}} - CollectionDecorator.should_receive(:new).with([], options) + expect(CollectionDecorator).to receive(:new).with([], options) Decorator.decorate_collection([], options) end end @@ -134,21 +134,21 @@ module Draper it "creates a custom collection decorator using itself for each item" do object = [Model.new] - ProductsDecorator.should_receive(:new).with(object, with: ProductDecorator) + expect(ProductsDecorator).to receive(:new).with(object, with: ProductDecorator) ProductDecorator.decorate_collection(object) end it "passes options to the collection decorator" do options = {with: OtherDecorator, context: {some: "context"}} - ProductsDecorator.should_receive(:new).with([], options) + expect(ProductsDecorator).to receive(:new).with([], options) ProductDecorator.decorate_collection([], options) end end context "when a NameError is thrown" do it "re-raises that error" do - String.any_instance.stub(:constantize) { Draper::DecoratedEnumerableProxy } + allow_any_instance_of(String).to receive(:constantize) { Draper::DecoratedEnumerableProxy } expect{ProductDecorator.decorate_collection([])}.to raise_error NameError, /Draper::DecoratedEnumerableProxy/ end end @@ -208,7 +208,7 @@ module Draper context "when an unrelated NameError is thrown" do it "re-raises that error" do - String.any_instance.stub(:constantize) { SomethingThatDoesntExist } + allow_any_instance_of(String).to receive(:constantize) { SomethingThatDoesntExist } expect{ProductDecorator.object_class}.to raise_error NameError, /SomethingThatDoesntExist/ end end @@ -221,19 +221,19 @@ module Draper describe ".object_class?" do it "returns truthy when .object_class is set" do - Decorator.stub(:object_class).and_return(Model) + allow(Decorator).to receive(:object_class).and_return(Model) expect(Decorator.object_class?).to be_truthy end it "returns false when .object_class is not inferrable" do - Decorator.stub(:object_class).and_raise(UninferrableSourceError.new(Decorator)) + allow(Decorator).to receive(:object_class).and_raise(UninferrableSourceError.new(Decorator)) expect(Decorator.object_class?).to be_falsey end it "is aliased to .source_class?" do - Decorator.stub(:object_class).and_return(Model) + allow(Decorator).to receive(:object_class).and_return(Model) expect(Decorator.source_class?).to be_truthy end @@ -243,7 +243,7 @@ module Draper protect_class Decorator describe "options validation" do - before { DecoratedAssociation.stub(:new).and_return(->{}) } + before { allow(DecoratedAssociation).to receive(:new).and_return(->{}) } it "does not raise error on valid options" do valid_options = {with: Class, scope: :sorted, context: {}} @@ -261,7 +261,7 @@ module Draper Decorator.decorates_association :children, options decorator = Decorator.new(Model.new) - DecoratedAssociation.should_receive(:new).with(decorator, :children, options).and_return(->{}) + expect(DecoratedAssociation).to receive(:new).with(decorator, :children, options).and_return(->{}) decorator.children end @@ -269,7 +269,7 @@ module Draper Decorator.decorates_association :children decorator = Decorator.new(Model.new) - DecoratedAssociation.should_receive(:new).once.and_return(->{}) + expect(DecoratedAssociation).to receive(:new).once.and_return(->{}) decorator.children decorator.children end @@ -278,9 +278,9 @@ module Draper Decorator.decorates_association :children decorator = Decorator.new(Model.new) decorated_association = ->{} - DecoratedAssociation.stub(:new).and_return(decorated_association) + allow(DecoratedAssociation).to receive(:new).and_return(decorated_association) - decorated_association.should_receive(:call).and_return(:decorated) + expect(decorated_association).to receive(:call).and_return(:decorated) expect(decorator.children).to be :decorated end end @@ -290,16 +290,16 @@ module Draper protect_class Decorator it "decorates each of the associations" do - Decorator.should_receive(:decorates_association).with(:friends, {}) - Decorator.should_receive(:decorates_association).with(:enemies, {}) + expect(Decorator).to receive(:decorates_association).with(:friends, {}) + expect(Decorator).to receive(:decorates_association).with(:enemies, {}) Decorator.decorates_associations :friends, :enemies end it "dispatches options" do options = {with: Class.new, scope: :foo, context: {}} - Decorator.should_receive(:decorates_association).with(:friends, options) - Decorator.should_receive(:decorates_association).with(:enemies, options) + expect(Decorator).to receive(:decorates_association).with(:friends, options) + expect(Decorator).to receive(:decorates_association).with(:enemies, options) Decorator.decorates_associations :friends, :enemies, options end end @@ -480,7 +480,7 @@ module Draper describe "#attributes" do it "returns only the object's attributes that are implemented by the decorator" do decorator = Decorator.new(double(attributes: {foo: "bar", baz: "qux"})) - decorator.stub(:foo) + allow(decorator).to receive(:foo) expect(decorator.attributes).to eq({foo: "bar"}) end @@ -488,7 +488,7 @@ module Draper describe ".model_name" do it "delegates to the source class" do - Decorator.stub object_class: double(model_name: :delegated) + allow(Decorator).to receive_messages object_class: double(model_name: :delegated) expect(Decorator.model_name).to be :delegated end @@ -514,7 +514,7 @@ module Draper decorator = Decorator.new(object) other = double(object: Model.new) - object.should_receive(:==).with(other).and_return(true) + expect(object).to receive(:==).with(other).and_return(true) expect(decorator == other).to be_truthy end @@ -523,7 +523,7 @@ module Draper decorator = Decorator.new(object) other = double(object: Model.new) - object.should_receive(:==).with(other).and_return(false) + expect(object).to receive(:==).with(other).and_return(false) expect(decorator == other).to be_falsey end end @@ -538,7 +538,7 @@ module Draper it "is false when #== is false" do decorator = Decorator.new(Model.new) - decorator.stub(:==).with(:anything).and_return(false) + allow(decorator).to receive(:==).with(:anything).and_return(false) expect(decorator === :anything).to be_falsey end @@ -574,12 +574,12 @@ module Draper protect_class Decorator it "defaults the :to option to :object" do - Object.should_receive(:delegate).with(:foo, :bar, to: :object) + expect(Object).to receive(:delegate).with(:foo, :bar, to: :object) Decorator.delegate :foo, :bar end it "does not overwrite the :to option if supplied" do - Object.should_receive(:delegate).with(:foo, :bar, to: :baz) + expect(Object).to receive(:delegate).with(:foo, :bar, to: :baz) Decorator.delegate :foo, :bar, to: :baz end end @@ -606,7 +606,7 @@ module Draper it "passes blocks to delegated methods" do object = Model.new - object.stub(:hello_world) { |*args, &block| block.call } + allow(object).to receive(:hello_world) { |*args, &block| block.call } decorator = Decorator.new(object) expect(decorator.hello_world{:yielded}).to be :yielded @@ -620,7 +620,7 @@ module Draper it "delegates already-delegated methods" do object = Class.new{ delegate :bar, to: :foo }.new - object.stub foo: double(bar: :delegated) + allow(object).to receive_messages foo: double(bar: :delegated) decorator = Decorator.new(object) expect(decorator.bar).to be :delegated @@ -652,14 +652,14 @@ module Draper context "with a source class" do it "delegates methods that exist on the source class" do object_class = Class.new - object_class.stub hello_world: :delegated - Decorator.stub object_class: object_class + allow(object_class).to receive_messages hello_world: :delegated + allow(Decorator).to receive_messages object_class: object_class expect(Decorator.hello_world).to be :delegated end it "does not delegate methods that do not exist on the source class" do - Decorator.stub object_class: Class.new + allow(Decorator).to receive_messages object_class: Class.new expect{Decorator.hello_world}.to raise_error NoMethodError end @@ -713,13 +713,13 @@ module Draper context "with a source class" do it "returns true for its own class methods" do Decorator.class_eval{def self.hello_world; end} - Decorator.stub object_class: Class.new + allow(Decorator).to receive_messages object_class: Class.new expect(Decorator).to respond_to :hello_world end it "returns true for the source's class methods" do - Decorator.stub object_class: double(hello_world: :delegated) + allow(Decorator).to receive_messages object_class: double(hello_world: :delegated) expect(Decorator).to respond_to :hello_world end @@ -737,7 +737,7 @@ module Draper describe ".respond_to_missing?" do it "allows .method to be called on delegated class methods" do - Decorator.stub object_class: double(hello_world: :delegated) + allow(Decorator).to receive_messages object_class: double(hello_world: :delegated) expect(Decorator.method(:hello_world)).not_to be_nil end diff --git a/spec/draper/factory_spec.rb b/spec/draper/factory_spec.rb index 03a4296..6560ad2 100644 --- a/spec/draper/factory_spec.rb +++ b/spec/draper/factory_spec.rb @@ -27,7 +27,7 @@ module Draper factory = Factory.new worker = ->(*){ :decorated } - Factory::Worker.should_receive(:new).and_return(worker) + expect(Factory::Worker).to receive(:new).and_return(worker) expect(factory.decorate(double)).to be :decorated end @@ -35,7 +35,7 @@ module Draper factory = Factory.new object = double - Factory::Worker.should_receive(:new).with(anything(), object).and_return(->(*){}) + expect(Factory::Worker).to receive(:new).with(anything(), object).and_return(->(*){}) factory.decorate(object) end @@ -44,7 +44,7 @@ module Draper decorator_class = double factory = Factory.new(with: decorator_class) - Factory::Worker.should_receive(:new).with(decorator_class, anything()).and_return(->(*){}) + expect(Factory::Worker).to receive(:new).with(decorator_class, anything()).and_return(->(*){}) factory.decorate(double) end end @@ -53,7 +53,7 @@ module Draper it "passes nil to the worker" do factory = Factory.new - Factory::Worker.should_receive(:new).with(nil, anything()).and_return(->(*){}) + expect(Factory::Worker).to receive(:new).with(nil, anything()).and_return(->(*){}) factory.decorate(double) end end @@ -61,10 +61,10 @@ module Draper it "passes options to the call" do factory = Factory.new worker = ->(*){} - Factory::Worker.stub new: worker + allow(Factory::Worker).to receive_messages new: worker options = {foo: "bar"} - worker.should_receive(:call).with(options) + expect(worker).to receive(:call).with(options) factory.decorate(double, options) end @@ -72,18 +72,18 @@ module Draper it "sets the passed context" do factory = Factory.new(context: {foo: "bar"}) worker = ->(*){} - Factory::Worker.stub new: worker + allow(Factory::Worker).to receive_messages new: worker - worker.should_receive(:call).with(baz: "qux", context: {foo: "bar"}) + expect(worker).to receive(:call).with(baz: "qux", context: {foo: "bar"}) factory.decorate(double, {baz: "qux"}) end it "is overridden by explicitly-specified context" do factory = Factory.new(context: {foo: "bar"}) worker = ->(*){} - Factory::Worker.stub new: worker + allow(Factory::Worker).to receive_messages new: worker - worker.should_receive(:call).with(context: {baz: "qux"}) + expect(worker).to receive(:call).with(context: {baz: "qux"}) factory.decorate(double, context: {baz: "qux"}) end end @@ -101,7 +101,7 @@ module Draper decorator = ->(*){} allow(worker).to receive(:decorator){ decorator } - decorator.should_receive(:call).with(object, options).and_return(:decorated) + expect(decorator).to receive(:call).with(object, options).and_return(:decorated) expect(worker.call(options)).to be :decorated end @@ -109,29 +109,29 @@ module Draper it "calls it" do worker = Factory::Worker.new(double, double) decorator = ->(*){} - worker.stub decorator: decorator + allow(worker).to receive_messages decorator: decorator context = {foo: "bar"} - decorator.should_receive(:call).with(anything(), context: context) + expect(decorator).to receive(:call).with(anything(), context: context) worker.call(context: ->{ context }) end it "receives arguments from the :context_args option" do worker = Factory::Worker.new(double, double) - worker.stub decorator: ->(*){} + allow(worker).to receive_messages decorator: ->(*){} context = ->{} - context.should_receive(:call).with(:foo, :bar) + expect(context).to receive(:call).with(:foo, :bar) worker.call(context: context, context_args: [:foo, :bar]) end it "wraps non-arrays passed to :context_args" do worker = Factory::Worker.new(double, double) - worker.stub decorator: ->(*){} + allow(worker).to receive_messages decorator: ->(*){} context = ->{} hash = {foo: "bar"} - context.should_receive(:call).with(hash) + expect(context).to receive(:call).with(hash) worker.call(context: context, context_args: hash) end end @@ -140,10 +140,10 @@ module Draper it "doesn't call it" do worker = Factory::Worker.new(double, double) decorator = ->(*){} - worker.stub decorator: decorator + allow(worker).to receive_messages decorator: decorator context = {foo: "bar"} - decorator.should_receive(:call).with(anything(), context: context) + expect(decorator).to receive(:call).with(anything(), context: context) worker.call(context: context) end end @@ -151,9 +151,9 @@ module Draper it "does not pass the :context_args option to the decorator" do worker = Factory::Worker.new(double, double) decorator = ->(*){} - worker.stub decorator: decorator + allow(worker).to receive_messages decorator: decorator - decorator.should_receive(:call).with(anything(), foo: "bar") + expect(decorator).to receive(:call).with(anything(), foo: "bar") worker.call(foo: "bar", context_args: []) end end @@ -176,7 +176,7 @@ module Draper options = {foo: "bar"} worker = Factory::Worker.new(nil, object) - object.should_receive(:decorate).with(options).and_return(:decorated) + expect(object).to receive(:decorate).with(options).and_return(:decorated) expect(worker.decorator.call(object, options)).to be :decorated end end @@ -231,7 +231,7 @@ module Draper 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) + expect(decorator_class).to receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated) expect(worker.decorator.call(object, foo: "bar")).to be :decorated end end diff --git a/spec/draper/finders_spec.rb b/spec/draper/finders_spec.rb index 5717d8e..131903e 100644 --- a/spec/draper/finders_spec.rb +++ b/spec/draper/finders_spec.rb @@ -7,20 +7,20 @@ module Draper describe ".find" do it "proxies to the model class" do - Product.should_receive(:find).with(1) + expect(Product).to receive(:find).with(1) ProductDecorator.find(1) end it "decorates the result" do found = Product.new - Product.stub(:find).and_return(found) + allow(Product).to receive(:find).and_return(found) decorator = ProductDecorator.find(1) expect(decorator).to be_a ProductDecorator expect(decorator.object).to be found end it "passes context to the decorator" do - Product.stub(:find) + allow(Product).to receive(:find) context = {some: "context"} decorator = ProductDecorator.find(1, context: context) @@ -30,40 +30,40 @@ module Draper describe ".find_by_(x)" do it "proxies to the model class" do - Product.should_receive(:find_by_name).with("apples") + expect(Product).to receive(:find_by_name).with("apples") ProductDecorator.find_by_name("apples") end it "decorates the result" do found = Product.new - Product.stub(:find_by_name).and_return(found) + allow(Product).to receive(:find_by_name).and_return(found) decorator = ProductDecorator.find_by_name("apples") expect(decorator).to be_a ProductDecorator expect(decorator.object).to be found end it "proxies complex ProductDecorators" do - Product.should_receive(:find_by_name_and_size).with("apples", "large") + expect(Product).to receive(:find_by_name_and_size).with("apples", "large") ProductDecorator.find_by_name_and_size("apples", "large") end it "proxies find_last_by_(x) ProductDecorators" do - Product.should_receive(:find_last_by_name_and_size).with("apples", "large") + expect(Product).to receive(:find_last_by_name_and_size).with("apples", "large") ProductDecorator.find_last_by_name_and_size("apples", "large") end it "proxies find_or_initialize_by_(x) ProductDecorators" do - Product.should_receive(:find_or_initialize_by_name_and_size).with("apples", "large") + expect(Product).to receive(:find_or_initialize_by_name_and_size).with("apples", "large") ProductDecorator.find_or_initialize_by_name_and_size("apples", "large") end it "proxies find_or_create_by_(x) ProductDecorators" do - Product.should_receive(:find_or_create_by_name_and_size).with("apples", "large") + expect(Product).to receive(:find_or_create_by_name_and_size).with("apples", "large") ProductDecorator.find_or_create_by_name_and_size("apples", "large") end it "passes context to the decorator" do - Product.stub(:find_by_name_and_size) + allow(Product).to receive(:find_by_name_and_size) context = {some: "context"} decorator = ProductDecorator.find_by_name_and_size("apples", "large", context: context) @@ -73,13 +73,13 @@ module Draper describe ".find_all_by_" do it "proxies to the model class" do - Product.should_receive(:find_all_by_name_and_size).with("apples", "large").and_return([]) + expect(Product).to receive(:find_all_by_name_and_size).with("apples", "large").and_return([]) ProductDecorator.find_all_by_name_and_size("apples", "large") end it "decorates the result" do found = [Product.new, Product.new] - Product.stub(:find_all_by_name).and_return(found) + allow(Product).to receive(:find_all_by_name).and_return(found) decorator = ProductDecorator.find_all_by_name("apples") expect(decorator).to be_a Draper::CollectionDecorator @@ -88,7 +88,7 @@ module Draper end it "passes context to the decorator" do - Product.stub(:find_all_by_name) + allow(Product).to receive(:find_all_by_name) context = {some: "context"} decorator = ProductDecorator.find_all_by_name("apples", context: context) @@ -99,7 +99,7 @@ module Draper describe ".all" do it "returns a decorated collection" do found = [Product.new, Product.new] - Product.stub all: found + allow(Product).to receive_messages all: found decorator = ProductDecorator.all expect(decorator).to be_a Draper::CollectionDecorator @@ -108,7 +108,7 @@ module Draper end it "passes context to the decorator" do - Product.stub(:all) + allow(Product).to receive(:all) context = {some: "context"} decorator = ProductDecorator.all(context: context) @@ -118,20 +118,20 @@ module Draper describe ".first" do it "proxies to the model class" do - Product.should_receive(:first) + expect(Product).to receive(:first) ProductDecorator.first end it "decorates the result" do first = Product.new - Product.stub(:first).and_return(first) + allow(Product).to receive(:first).and_return(first) decorator = ProductDecorator.first expect(decorator).to be_a ProductDecorator expect(decorator.object).to be first end it "passes context to the decorator" do - Product.stub(:first) + allow(Product).to receive(:first) context = {some: "context"} decorator = ProductDecorator.first(context: context) @@ -141,20 +141,20 @@ module Draper describe ".last" do it "proxies to the model class" do - Product.should_receive(:last) + expect(Product).to receive(:last) ProductDecorator.last end it "decorates the result" do last = Product.new - Product.stub(:last).and_return(last) + allow(Product).to receive(:last).and_return(last) decorator = ProductDecorator.last expect(decorator).to be_a ProductDecorator expect(decorator.object).to be last end it "passes context to the decorator" do - Product.stub(:last) + allow(Product).to receive(:last) context = {some: "context"} decorator = ProductDecorator.last(context: context) diff --git a/spec/draper/helper_proxy_spec.rb b/spec/draper/helper_proxy_spec.rb index ce5312b..de4d030 100644 --- a/spec/draper/helper_proxy_spec.rb +++ b/spec/draper/helper_proxy_spec.rb @@ -18,7 +18,7 @@ module Draper view_context = double helper_proxy = HelperProxy.new(view_context) - view_context.stub(:foo) { |arg| arg } + allow(view_context).to receive(:foo) { |arg| arg } expect(helper_proxy.foo(:passed)).to be :passed end @@ -26,7 +26,7 @@ module Draper view_context = double helper_proxy = HelperProxy.new(view_context) - view_context.stub(:foo) { |&block| block.call } + allow(view_context).to receive(:foo) { |&block| block.call } expect(helper_proxy.foo{:yielded}).to be :yielded end diff --git a/spec/draper/lazy_helpers_spec.rb b/spec/draper/lazy_helpers_spec.rb index e150602..e53c618 100644 --- a/spec/draper/lazy_helpers_spec.rb +++ b/spec/draper/lazy_helpers_spec.rb @@ -8,12 +8,12 @@ module Draper end it "proxies methods to #helpers" do - decorator.helpers.stub(:foo) { |arg| arg } + allow(decorator.helpers).to receive(:foo) { |arg| arg } expect(decorator.foo(:passed)).to be :passed end it "passes blocks" do - decorator.helpers.stub(:foo) { |&block| block.call } + allow(decorator.helpers).to receive(:foo) { |&block| block.call } expect(decorator.foo{:yielded}).to be :yielded end end diff --git a/spec/draper/view_context/build_strategy_spec.rb b/spec/draper/view_context/build_strategy_spec.rb index abb154c..df7d311 100644 --- a/spec/draper/view_context/build_strategy_spec.rb +++ b/spec/draper/view_context/build_strategy_spec.rb @@ -14,7 +14,7 @@ module Draper context "when a current controller is set" do it "returns the controller's view context" do view_context = fake_view_context - ViewContext.stub controller: fake_controller(view_context) + allow(ViewContext).to receive_messages controller: fake_controller(view_context) strategy = ViewContext::BuildStrategy::Full.new expect(strategy.call).to be view_context @@ -33,7 +33,7 @@ module Draper it "adds a request if one is not defined" do controller = Class.new(ActionController::Base).new - ViewContext.stub controller: controller + allow(ViewContext).to receive_messages controller: controller strategy = ViewContext::BuildStrategy::Full.new expect(controller.request).to be_nil @@ -47,7 +47,7 @@ module Draper end it "adds methods to the view context from the constructor block" do - ViewContext.stub controller: fake_controller + allow(ViewContext).to receive_messages controller: fake_controller strategy = ViewContext::BuildStrategy::Full.new do def a_helper_method; end end @@ -57,7 +57,7 @@ module Draper it "includes modules into the view context from the constructor block" do view_context = Object.new - ViewContext.stub controller: fake_controller(view_context) + allow(ViewContext).to receive_messages controller: fake_controller(view_context) helpers = Module.new do def a_helper_method; end end diff --git a/spec/draper/view_context_spec.rb b/spec/draper/view_context_spec.rb index b1f06af..1816cd1 100644 --- a/spec/draper/view_context_spec.rb +++ b/spec/draper/view_context_spec.rb @@ -7,7 +7,7 @@ module Draper let(:controller) { Class.new(base) { include ViewContext } } it "saves the superclass's view context" do - ViewContext.should_receive(:current=).with(:controller_view_context) + expect(ViewContext).to receive(:current=).with(:controller_view_context) controller.new.view_context end @@ -18,7 +18,7 @@ module Draper describe ".controller" do it "returns the stored controller from RequestStore" do - RequestStore.stub store: {current_controller: :stored_controller} + allow(RequestStore).to receive_messages store: {current_controller: :stored_controller} expect(ViewContext.controller).to be :stored_controller end @@ -27,7 +27,7 @@ module Draper describe ".controller=" do it "stores a controller in RequestStore" do store = {} - RequestStore.stub store: store + allow(RequestStore).to receive_messages store: store ViewContext.controller = :stored_controller expect(store[:current_controller]).to be :stored_controller @@ -36,25 +36,25 @@ module Draper describe ".current" do it "returns the stored view context from RequestStore" do - RequestStore.stub store: {current_view_context: :stored_view_context} + allow(RequestStore).to receive_messages store: {current_view_context: :stored_view_context} expect(ViewContext.current).to be :stored_view_context end context "when no view context is stored" do it "builds a view context" do - RequestStore.stub store: {} - ViewContext.stub build_strategy: ->{ :new_view_context } - HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy) + allow(RequestStore).to receive_messages store: {} + allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context } + allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy) expect(ViewContext.current).to be :new_helper_proxy end it "stores the built view context" do store = {} - RequestStore.stub store: store - ViewContext.stub build_strategy: ->{ :new_view_context } - HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy) + allow(RequestStore).to receive_messages store: store + allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context } + allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy) ViewContext.current expect(store[:current_view_context]).to be :new_helper_proxy @@ -65,8 +65,8 @@ module Draper describe ".current=" do it "stores a helper proxy for the view context in RequestStore" do store = {} - RequestStore.stub store: store - HelperProxy.stub(:new).with(:stored_view_context).and_return(:stored_helper_proxy) + allow(RequestStore).to receive_messages store: store + allow(HelperProxy).to receive(:new).with(:stored_view_context).and_return(:stored_helper_proxy) ViewContext.current = :stored_view_context expect(store[:current_view_context]).to be :stored_helper_proxy @@ -76,7 +76,7 @@ module Draper describe ".clear!" do it "clears the stored controller and view controller" do store = {current_controller: :stored_controller, current_view_context: :stored_view_context} - RequestStore.stub store: store + allow(RequestStore).to receive_messages store: store ViewContext.clear! expect(store).not_to have_key :current_controller @@ -86,7 +86,7 @@ module Draper describe ".build" do it "returns a new view context using the build strategy" do - ViewContext.stub build_strategy: ->{ :new_view_context } + allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context } expect(ViewContext.build).to be :new_view_context end @@ -94,17 +94,17 @@ module Draper describe ".build!" do it "returns a helper proxy for the new view context" do - ViewContext.stub build_strategy: ->{ :new_view_context } - HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy) + allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context } + allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy) expect(ViewContext.build!).to be :new_helper_proxy end it "stores the helper proxy" do store = {} - RequestStore.stub store: store - ViewContext.stub build_strategy: ->{ :new_view_context } - HelperProxy.stub(:new).with(:new_view_context).and_return(:new_helper_proxy) + allow(RequestStore).to receive_messages store: store + allow(ViewContext).to receive_messages build_strategy: ->{ :new_view_context } + allow(HelperProxy).to receive(:new).with(:new_view_context).and_return(:new_helper_proxy) ViewContext.build! expect(store[:current_view_context]).to be :new_helper_proxy @@ -131,7 +131,7 @@ module Draper end it "passes a block to the strategy" do - ViewContext::BuildStrategy::Fast.stub(:new) { |&block| block.call } + allow(ViewContext::BuildStrategy::Fast).to receive(:new) { |&block| block.call } expect(ViewContext.test_strategy(:fast){:passed}).to be :passed end @@ -144,7 +144,7 @@ module Draper end it "passes a block to the strategy" do - ViewContext::BuildStrategy::Full.stub(:new) { |&block| block.call } + allow(ViewContext::BuildStrategy::Full).to receive(:new) { |&block| block.call } expect(ViewContext.test_strategy(:full){:passed}).to be :passed end diff --git a/spec/generators/controller/controller_generator_spec.rb b/spec/generators/controller/controller_generator_spec.rb index af77c1f..96cfe9f 100644 --- a/spec/generators/controller/controller_generator_spec.rb +++ b/spec/generators/controller/controller_generator_spec.rb @@ -16,7 +16,7 @@ describe Rails::Generators::ControllerGenerator do describe "naming" do before { run_generator %w(YourModels) } - it { should contain "class YourModelDecorator" } + it { is_expected.to contain "class YourModelDecorator" } end end end \ No newline at end of file diff --git a/spec/generators/decorator/decorator_generator_spec.rb b/spec/generators/decorator/decorator_generator_spec.rb index 08a9601..f8344c8 100644 --- a/spec/generators/decorator/decorator_generator_spec.rb +++ b/spec/generators/decorator/decorator_generator_spec.rb @@ -15,27 +15,27 @@ describe Rails::Generators::DecoratorGenerator do describe "naming" do before { run_generator %w(YourModel) } - it { should contain "class YourModelDecorator" } + it { is_expected.to contain "class YourModelDecorator" } end describe "namespacing" do subject { file("app/decorators/namespace/your_model_decorator.rb") } before { run_generator %w(Namespace::YourModel) } - it { should contain "class Namespace::YourModelDecorator" } + it { is_expected.to contain "class Namespace::YourModelDecorator" } end describe "inheritance" do context "by default" do before { run_generator %w(YourModel) } - it { should contain "class YourModelDecorator < Draper::Decorator" } + it { is_expected.to contain "class YourModelDecorator < Draper::Decorator" } end context "with the --parent option" do before { run_generator %w(YourModel --parent=FooDecorator) } - it { should contain "class YourModelDecorator < FooDecorator" } + it { is_expected.to contain "class YourModelDecorator < FooDecorator" } end context "with an ApplicationDecorator" do @@ -47,7 +47,7 @@ describe Rails::Generators::DecoratorGenerator do before { run_generator %w(YourModel) } - it { should contain "class YourModelDecorator < ApplicationDecorator" } + it { is_expected.to contain "class YourModelDecorator < ApplicationDecorator" } end end end @@ -59,14 +59,14 @@ describe Rails::Generators::DecoratorGenerator do describe "naming" do before { run_generator %w(YourModel -t=rspec) } - it { should contain "describe YourModelDecorator" } + it { is_expected.to contain "describe YourModelDecorator" } end describe "namespacing" do subject { file("spec/decorators/namespace/your_model_decorator_spec.rb") } before { run_generator %w(Namespace::YourModel -t=rspec) } - it { should contain "describe Namespace::YourModelDecorator" } + it { is_expected.to contain "describe Namespace::YourModelDecorator" } end end end @@ -78,14 +78,14 @@ describe Rails::Generators::DecoratorGenerator do describe "naming" do before { run_generator %w(YourModel -t=test_unit) } - it { should contain "class YourModelDecoratorTest < Draper::TestCase" } + it { is_expected.to contain "class YourModelDecoratorTest < Draper::TestCase" } end describe "namespacing" do subject { file("test/decorators/namespace/your_model_decorator_test.rb") } before { run_generator %w(Namespace::YourModel -t=test_unit) } - it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" } + it { is_expected.to contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" } end end end diff --git a/spec/support/shared_examples/view_helpers.rb b/spec/support/shared_examples/view_helpers.rb index f7d0621..dad202e 100644 --- a/spec/support/shared_examples/view_helpers.rb +++ b/spec/support/shared_examples/view_helpers.rb @@ -1,38 +1,38 @@ shared_examples_for "view helpers" do |subject| describe "#helpers" do it "returns the current view context" do - Draper::ViewContext.stub current: :current_view_context + allow(Draper::ViewContext).to receive_messages current: :current_view_context expect(subject.helpers).to be :current_view_context end it "is aliased to #h" do - Draper::ViewContext.stub current: :current_view_context + allow(Draper::ViewContext).to receive_messages current: :current_view_context expect(subject.h).to be :current_view_context end end describe "#localize" do it "delegates to #helpers" do - subject.stub helpers: double - subject.helpers.should_receive(:localize).with(:an_object, some: "parameter") + allow(subject).to receive_messages helpers: double + expect(subject.helpers).to receive(:localize).with(:an_object, some: "parameter") subject.localize(:an_object, some: "parameter") end it "is aliased to #l" do - subject.stub helpers: double - subject.helpers.should_receive(:localize).with(:an_object, some: "parameter") + allow(subject).to receive_messages helpers: double + expect(subject.helpers).to receive(:localize).with(:an_object, some: "parameter") subject.l(:an_object, some: "parameter") end end describe ".helpers" do it "returns the current view context" do - Draper::ViewContext.stub current: :current_view_context + allow(Draper::ViewContext).to receive_messages current: :current_view_context expect(subject.class.helpers).to be :current_view_context end it "is aliased to .h" do - Draper::ViewContext.stub current: :current_view_context + allow(Draper::ViewContext).to receive_messages current: :current_view_context expect(subject.class.h).to be :current_view_context end end