spec/ballast/operations_chain_spec.rb in ballast-1.5.3 vs spec/ballast/operations_chain_spec.rb in ballast-1.6.0
- old
+ new
@@ -5,29 +5,57 @@
require "spec_helper"
describe Ballast::OperationsChain do
describe ".perform" do
- before(:each) do
- expect_any_instance_of(Ballast::OperationsChain).to receive(:perform)
+ class SuccessOperation < Ballast::Operation
+ def perform
+ response[:result] ||= 0
+ response[:result] += 1
+ end
end
- it "should initialize with the set of operations and the first argument as context" do
- context = Ballast::Context.new
- expect(Ballast::Context).not_to receive(:build)
- expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
- Ballast::OperationsChain.perform(context, [:A, :B, :C])
+ class FailureOperation < Ballast::Operation
+ def perform
+ fail!
+ end
end
- it "shuold use the provided owner and context" do
- context = Ballast::Context.new
- expect(Ballast::Context).not_to receive(:build)
- expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
- Ballast::OperationsChain.perform(nil, [:A, :B, :C], context: context)
+ class FinalOperation < Ballast::Operation
+ def perform
+ response[:result] = "#{response[:result]}F"
+ end
end
- it "should created the context on the fly if needed" do
- expect(Ballast::Context).to receive(:build).with("A", {a: 1})
- Ballast::OperationsChain.perform("A", [:A, :B, :C], params: {a: 1})
+ describe ".perform" do
+ before(:each) do
+ expect_any_instance_of(Ballast::OperationsChain).to receive(:perform)
+ end
+
+ it "should initialize with the set of operations and the first argument as context" do
+ context = Ballast::Context.new
+ expect(Ballast::Context).not_to receive(:build)
+ expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
+ Ballast::OperationsChain.perform(context, [:A, :B, :C])
+ end
+
+ it "should use the provided owner and context" do
+ context = Ballast::Context.new
+ expect(Ballast::Context).not_to receive(:build)
+ expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
+ Ballast::OperationsChain.perform(nil, [:A, :B, :C], context: context)
+ end
+
+ it "should created the context on the fly if needed" do
+ expect(Ballast::Context).to receive(:build).with("A", {a: 1})
+ Ballast::OperationsChain.perform("A", [:A, :B, :C], params: {a: 1})
+ end
+ end
+
+ describe "#perform" do
+ it "should execute the operations unless they fail" do
+ expect(Ballast::OperationsChain.perform(nil, [SuccessOperation, FinalOperation]).response[:result]).to eq("1F")
+ expect(Ballast::OperationsChain.perform(nil, [SuccessOperation, FailureOperation, FinalOperation]).response[:result].to_s).not_to match(/F$/)
+ end
end
end
end
\ No newline at end of file