spec/draper/factory_spec.rb in draper-3.0.0.pre1 vs spec/draper/factory_spec.rb in draper-3.0.0
- old
+ new
@@ -25,67 +25,67 @@
it "calls a worker" do
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
it "passes the object to the worker" do
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
context "when the :with option was given" do
it "passes the decorator class to the worker" do
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
context "when the :with option was omitted" do
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
it "passes options to the call" do
factory = Factory.new
worker = ->(*){}
- Factory::Worker.stub new: worker
+ allow(Factory::Worker).to receive(:new).and_return(worker)
options = {foo: "bar"}
- worker.should_receive(:call).with(options)
+ allow(worker).to receive(:call).with(options)
factory.decorate(double, options)
end
context "when the :context option was given" do
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
end
@@ -97,65 +97,65 @@
it "calls the decorator method" do
object = double
options = {foo: "bar"}
worker = Factory::Worker.new(double, object)
decorator = ->(*){}
- allow(worker).to receive(:decorator){ decorator }
+ allow(worker).to receive(:decorator){ decorator }
- decorator.should_receive(:call).with(object, options).and_return(:decorated)
+ allow(decorator).to receive(:call).with(object, options).and_return(:decorated)
expect(worker.call(options)).to be :decorated
end
context "when the :context option is callable" do
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
context "when the :context option is not callable" do
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
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
describe "#decorator" do
@@ -174,11 +174,11 @@
it "returns the object's #decorate method" do
object = double
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
context "and the object is not decoratable" do
@@ -229,10 +229,10 @@
decorator_class = Class.new(Decorator)
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)
+ 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
context "and the object is not decoratable" do