1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Merge branch 'mcasper/update_to_rspec_3_syntax'

Conflicts:
	spec/draper/collection_decorator_spec.rb
	spec/draper/decoratable_spec.rb
	spec/draper/decorated_association_spec.rb
	spec/draper/decorates_assigned_spec.rb
	spec/draper/decorator_spec.rb
	spec/draper/factory_spec.rb
	spec/draper/finders_spec.rb
	spec/draper/helper_proxy_spec.rb
	spec/draper/view_context/build_strategy_spec.rb
	spec/draper/view_context_spec.rb
	spec/support/shared_examples/view_helpers.rb
This commit is contained in:
Morgan Lieberthal 2015-08-27 02:17:36 -06:00
commit 66bc7ad6fc
10 changed files with 13 additions and 56 deletions

View file

@ -63,7 +63,7 @@ module Draper
it "does not trigger decoration" do
decorator = CollectionDecorator.new([])
expect(decorator).to_not receive(:decorated_collection)
expect(decorator).not_to receive(:decorated_collection)
decorator.context = {other: "context"}
end

View file

@ -23,8 +23,6 @@ module Draper
it "uses the #decorator_class" do
product = Product.new
allow(product).to receive(:decorator_class) { OtherDecorator }
# product.stub decorator_class: OtherDecorator
expect(product.decorate).to be_an_instance_of OtherDecorator
end
end
@ -134,7 +132,6 @@ module Draper
it "calls #decorate_collection on .decorator_class" do
scoped = [Product.new]
allow(Product).to receive(scoping_method).and_return(scoped)
# Product.stub scoping_method => scoped
expect(Product.decorator_class).to receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection)
expect(Product.decorate).to be :decorated_collection

View file

@ -17,14 +17,12 @@ module Draper
options = {with: Decorator, context: {foo: "bar"}}
expect(Factory).to receive(:new).with(options)
# Factory.should_receive(:new).with(options)
DecoratedAssociation.new(double, :association, options)
end
describe ":with option" do
it "defaults to nil" do
expect(Factory).to receive(:new).with(with: nil, context: anything())
# Factory.should_receive(:new).with(with: nil, context: anything())
DecoratedAssociation.new(double, :association, {})
end
end
@ -61,7 +59,7 @@ module Draper
decorated_association = DecoratedAssociation.new(owner, :association, {})
decorated = double
allow(factory).to 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

View file

@ -29,7 +29,6 @@ module Draper
it "creates a factory" do
expect(Factory).to receive(:new).once
# Factory.should_receive(:new).once
controller_class.decorates_assigned :article, :author
end
@ -50,7 +49,7 @@ module Draper
controller = controller_class.new
controller.instance_variable_set "@article", object
allow(factory).to 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

View file

@ -82,9 +82,7 @@ module Draper
it "decorates anyway" do
decorated = OtherDecorator.new(Decorator.new(Model.new))
allow_any_instance_of(Object).to receive(:warn)
# Object.any_instance.stub(:warn)
redecorated = Decorator.decorate(decorated)
expect(redecorated.object).to be decorated
@ -104,10 +102,7 @@ module Draper
describe ".decorate_collection" do
describe "options validation" do
before do
allow(CollectionDecorator).to receive(:new)
end
# before { CollectionDecorator.stub(:new) }
before { allow(CollectionDecorator).to receive(:new) }
it "does not raise error on valid options" do
valid_options = {with: OtherDecorator, context: {}}
@ -124,7 +119,6 @@ module Draper
object = [Model.new]
expect(CollectionDecorator).to receive(:new).with(object, with: Decorator)
# CollectionDecorator.should_receive(:new).with(object, with: Decorator)
Decorator.decorate_collection(object)
end
@ -155,7 +149,6 @@ module Draper
context "when a NameError is thrown" do
it "re-raises that error" do
allow_any_instance_of(String).to receive(:constantize) { Draper::DecoratedEnumerableProxy }
# String.any_instance.stub(:constantize) { Draper::DecoratedEnumerableProxy }
expect{ProductDecorator.decorate_collection([])}.to raise_error NameError, /Draper::DecoratedEnumerableProxy/
end
end
@ -216,7 +209,6 @@ module Draper
context "when an unrelated NameError is thrown" do
it "re-raises that error" do
allow_any_instance_of(String).to receive(:constantize) { SomethingThatDoesntExist }
# String.any_instance.stub(:constantize) { SomethingThatDoesntExist }
expect{ProductDecorator.object_class}.to raise_error NameError, /SomethingThatDoesntExist/
end
end
@ -230,21 +222,18 @@ module Draper
describe ".object_class?" do
it "returns truthy when .object_class is set" do
allow(Decorator).to receive(:object_class).and_return(Model)
# Decorator.stub(:object_class).and_return(Model)
expect(Decorator.object_class?).to be_truthy
end
it "returns false when .object_class is not inferrable" do
allow(Decorator).to receive(:object_class).and_raise(UninferrableSourceError.new(Decorator))
# Decorator.stub(:object_class).and_raise(UninferrableSourceError.new(Decorator))
expect(Decorator.object_class?).to be_falsey
end
it "is aliased to .source_class?" do
allow(Decorator).to receive(:object_class).and_return(Model)
# Decorator.stub(:object_class).and_return(Model)
expect(Decorator.source_class?).to be_truthy
end
@ -254,10 +243,7 @@ module Draper
protect_class Decorator
describe "options validation" do
before do
allow(DecoratedAssociation).to receive(:new).and_return(->{})
end
before { allow(DecoratedAssociation).to receive(:new).and_return(->{}) }
it "does not raise error on valid options" do
valid_options = {with: Class, scope: :sorted, context: {}}
@ -276,7 +262,6 @@ module Draper
decorator = Decorator.new(Model.new)
expect(DecoratedAssociation).to receive(:new).with(decorator, :children, options).and_return(->{})
# DecoratedAssociation.should_receive(:new).with(decorator, :children, options).and_return(->{})
decorator.children
end
@ -285,7 +270,6 @@ module Draper
decorator = Decorator.new(Model.new)
expect(DecoratedAssociation).to receive(:new).once.and_return(->{})
# DecoratedAssociation.should_receive(:new).once.and_return(->{})
decorator.children
decorator.children
end
@ -297,7 +281,6 @@ module Draper
allow(DecoratedAssociation).to receive(:new).and_return(decorated_association)
expect(decorated_association).to receive(:call).and_return(:decorated)
# decorated_association.should_receive(:call).and_return(:decorated)
expect(decorator.children).to be :decorated
end
end
@ -309,8 +292,6 @@ module Draper
it "decorates each of the associations" do
expect(Decorator).to receive(:decorates_association).with(:friends, {})
expect(Decorator).to receive(:decorates_association).with(:enemies, {})
# Decorator.should_receive(:decorates_association).with(:friends, {})
# Decorator.should_receive(:decorates_association).with(:enemies, {})
Decorator.decorates_associations :friends, :enemies
end
@ -319,8 +300,6 @@ module Draper
expect(Decorator).to receive(:decorates_association).with(:friends, options)
expect(Decorator).to receive(:decorates_association).with(:enemies, options)
# Decorator.should_receive(:decorates_association).with(:friends, options)
# Decorator.should_receive(:decorates_association).with(:enemies, options)
Decorator.decorates_associations :friends, :enemies, options
end
end
@ -502,8 +481,6 @@ module Draper
it "returns only the object's attributes that are implemented by the decorator" do
decorator = Decorator.new(double(attributes: {foo: "bar", baz: "qux"}))
allow(decorator).to receive(:foo)
# decorator.stub(:foo)
expect(decorator.attributes).to eq({foo: "bar"})
end
end
@ -511,7 +488,6 @@ module Draper
describe ".model_name" do
it "delegates to the source class" do
allow(Decorator).to receive(:object_class) { double(model_name: :delegated) }
# Decorator.stub object_class: double(model_name: :delegated)
expect(Decorator.model_name).to be :delegated
end
@ -562,7 +538,6 @@ module Draper
it "is false when #== is false" do
decorator = Decorator.new(Model.new)
allow(decorator).to receive(:==).with(:anything).and_return(false)
# decorator.stub(:==).with(:anything).and_return(false)
expect(decorator === :anything).to be_falsey
end
@ -645,7 +620,6 @@ module Draper
it "delegates already-delegated methods" do
object = Class.new{ delegate :bar, to: :foo }.new
allow(object).to receive(:foo) { double(bar: :delegated) }
# object.stub foo: double(bar: :delegated)
decorator = Decorator.new(object)
expect(decorator.bar).to be :delegated
@ -678,7 +652,6 @@ module Draper
it "delegates methods that exist on the source class" do
object_class = Class.new
allow(object_class).to receive(:hello_world).and_return(:delegated)
# object_class.stub hello_world: :delegated
allow(Decorator).to receive(:object_class).and_return(object_class)
expect(Decorator.hello_world).to be :delegated
@ -686,8 +659,6 @@ module Draper
it "does not delegate methods that do not exist on the source class" do
allow(Decorator).to receive(:object_class) { Class.new }
# Decorator.stub object_class: Class.new
expect{Decorator.hello_world}.to raise_error NoMethodError
end
end
@ -765,7 +736,6 @@ module Draper
describe ".respond_to_missing?" do
it "allows .method to be called on delegated class methods" do
allow(Decorator).to receive(:object_class) { double(hello_world: :delegated) }
# Decorator.stub object_class: double(hello_world: :delegated)
expect(Decorator.method(:hello_world)).not_to be_nil
end

View file

@ -27,7 +27,7 @@ module Draper
factory = Factory.new
worker = ->(*){ :decorated }
allow(Factory::Worker).to 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
allow(Factory::Worker).to 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)
allow(Factory::Worker).to 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
allow(Factory::Worker).to receive(:new).with(nil, anything()).and_return(->(*){})
expect(Factory::Worker).to receive(:new).with(nil, anything()).and_return(->(*){})
factory.decorate(double)
end
end
@ -101,7 +101,7 @@ module Draper
decorator = ->(*){}
allow(worker).to receive(:decorator){ decorator }
allow(decorator).to 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
@ -176,7 +176,7 @@ module Draper
options = {foo: "bar"}
worker = Factory::Worker.new(nil, object)
allow(object).to 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)
allow(decorator_class).to 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

View file

@ -19,7 +19,6 @@ module Draper
helper_proxy = HelperProxy.new(view_context)
allow(view_context).to receive(:foo) { |arg| arg }
# view_context.stub(:foo) { |arg| arg }
expect(helper_proxy.foo(:passed)).to be :passed
end
@ -28,7 +27,6 @@ module Draper
helper_proxy = HelperProxy.new(view_context)
allow(view_context).to receive(:foo) { |&block| block.call }
# view_context.stub(:foo) { |&block| block.call }
expect(helper_proxy.foo{:yielded}).to be :yielded
end

View file

@ -15,7 +15,6 @@ module Draper
it "returns the controller's view context" do
view_context = fake_view_context
allow(ViewContext).to receive(:controller) { fake_controller(view_context) }
# ViewContext.stub controller: fake_controller(view_context)
strategy = ViewContext::BuildStrategy::Full.new
expect(strategy.call).to be view_context

View file

@ -17,7 +17,7 @@ RSpec.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

View file

@ -4,12 +4,10 @@ RSpec.shared_examples_for "view helpers" do |subject|
describe "#helpers" do
it "returns the current view context" do
allow(Draper::ViewContext).to receive(:current) { :current_view_context }
# Draper::ViewContext.stub 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(:current) { :current_view_context }
expect(subject.h).to be :current_view_context
end
@ -37,13 +35,11 @@ RSpec.shared_examples_for "view helpers" do |subject|
describe ".helpers" do
it "returns the current view context" do
allow(Draper::ViewContext).to receive(:current) { :current_view_context }
# Draper::ViewContext.stub current: :current_view_context
expect(subject.class.helpers).to be :current_view_context
end
it "is aliased to .h" do
allow(Draper::ViewContext).to receive(:current) { :current_view_context }
# Draper::ViewContext.stub current: :current_view_context
expect(subject.class.h).to be :current_view_context
end
end