composable_operations 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/composable_operations.gemspec +1 -1
- data/lib/composable_operations/matcher/execution.rb +4 -2
- data/lib/composable_operations/matcher/utilize_operation.rb +8 -5
- data/lib/composable_operations/version.rb +1 -1
- data/spec/composable_operations/composed_operation_spec.rb +12 -24
- data/spec/composable_operations/control_flow_spec.rb +17 -20
- data/spec/composable_operations/exception_handling_spec.rb +13 -13
- data/spec/composable_operations/operation_input_forwarding_spec.rb +4 -7
- data/spec/composable_operations/operation_input_processing_spec.rb +14 -35
- data/spec/composable_operations/operation_spec.rb +12 -28
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e322ef724df070ae4f606346ec732d0931174a49
|
4
|
+
data.tar.gz: 7119c160bc2d4cb1bc4138bd6c2fe4f321ebfc89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22589a1c44ebf3c74e564f3286d2aa9136516ef29698047632f4124e9171caeb03bc2bc9a0d9d20de2645b9b727b1807e0d9c0e01cd5de9f69b38092a78746bf
|
7
|
+
data.tar.gz: 609dc3b474ea1d374dd705422d1a95129e309b31d5fabb70479a3f42a8d95d89dcf63ae13c83a4facf62a7a5c493e7d5bdce109c04233fad7ddeef9550acda0f
|
data/.travis.yml
ADDED
@@ -24,5 +24,5 @@ multiple of these operations in operation pipelines.}
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
spec.add_development_dependency "pry", "~> 0.9.0"
|
26
26
|
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec", "~>
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
28
|
end
|
@@ -75,9 +75,10 @@ module ComposableOperations
|
|
75
75
|
"the operation failed to perform for the following reason(s):\n#{failure_reasons}"
|
76
76
|
end
|
77
77
|
|
78
|
-
def
|
78
|
+
def failure_message_when_negated
|
79
79
|
"the operation succeeded unexpectedly"
|
80
80
|
end
|
81
|
+
alias negative_failure_message failure_message_when_negated
|
81
82
|
|
82
83
|
private
|
83
84
|
|
@@ -120,9 +121,10 @@ module ComposableOperations
|
|
120
121
|
"the operation did not fail to perform for the following reason(s):\n#{failure_reasons}"
|
121
122
|
end
|
122
123
|
|
123
|
-
def
|
124
|
+
def failure_message_when_negated
|
124
125
|
"the operation failed unexpectedly"
|
125
126
|
end
|
127
|
+
alias negative_failure_message failure_message_when_negated
|
126
128
|
|
127
129
|
protected
|
128
130
|
|
@@ -28,6 +28,7 @@ module ComposableOperations
|
|
28
28
|
end
|
29
29
|
|
30
30
|
class Matcher
|
31
|
+
include RSpec::Mocks::ExampleMethods
|
31
32
|
|
32
33
|
attr_reader :composite_operations
|
33
34
|
attr_reader :tested_operation
|
@@ -46,13 +47,14 @@ module ComposableOperations
|
|
46
47
|
@tested_instance = class_or_instance
|
47
48
|
end
|
48
49
|
|
49
|
-
Operation.
|
50
|
+
allow(Operation).to receive(:new).and_return(DummyOperation.new)
|
50
51
|
composite_operations.each do |composite_operation|
|
51
52
|
dummy_operation = DummyOperation.new
|
52
|
-
dummy_operation.
|
53
|
-
composite_operation.
|
53
|
+
expect(dummy_operation).to receive(:perform).and_call_original
|
54
|
+
expect(composite_operation).to receive(:new).and_return(dummy_operation)
|
54
55
|
end
|
55
|
-
tested_instance.
|
56
|
+
allow(tested_instance).to receive(:prepare).and_return(true)
|
57
|
+
allow(tested_instance).to receive(:finalize).and_return(true)
|
56
58
|
tested_instance.perform
|
57
59
|
|
58
60
|
tested_operation.operations == composite_operations
|
@@ -71,9 +73,10 @@ module ComposableOperations
|
|
71
73
|
message.join("\n\t")
|
72
74
|
end
|
73
75
|
|
74
|
-
def
|
76
|
+
def failure_message_when_negated
|
75
77
|
"Unexpected operation utilization"
|
76
78
|
end
|
79
|
+
alias negative_failure_message failure_message_when_negated
|
77
80
|
|
78
81
|
end
|
79
82
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe ComposableOperations::ComposedOperation do
|
4
|
-
|
5
4
|
let(:string_generator) do
|
6
5
|
Class.new(ComposableOperations::Operation) do
|
7
6
|
def self.name
|
@@ -52,7 +51,6 @@ describe ComposableOperations::ComposedOperation do
|
|
52
51
|
end
|
53
52
|
|
54
53
|
context "when composed of one operation that generates a string no matter the input" do
|
55
|
-
|
56
54
|
subject(:composed_operation) do
|
57
55
|
operation = string_generator
|
58
56
|
|
@@ -62,13 +60,11 @@ describe ComposableOperations::ComposedOperation do
|
|
62
60
|
end
|
63
61
|
|
64
62
|
it "should return this string as result" do
|
65
|
-
composed_operation.perform(nil).
|
63
|
+
expect(composed_operation.perform(nil)).to eq("chunky bacon")
|
66
64
|
end
|
67
|
-
|
68
65
|
end
|
69
66
|
|
70
67
|
context "when composed of two operations, one that generates a string and one that multiplies it" do
|
71
|
-
|
72
68
|
subject(:composed_operation) do
|
73
69
|
string_generator = self.string_generator
|
74
70
|
string_multiplier = self.string_multiplier
|
@@ -81,24 +77,19 @@ describe ComposableOperations::ComposedOperation do
|
|
81
77
|
end.new
|
82
78
|
end
|
83
79
|
|
84
|
-
it {
|
85
|
-
|
80
|
+
it { is_expected.to succeed_to_perform.and_return('chunky bacon - chunky bacon - chunky bacon') }
|
86
81
|
end
|
87
82
|
|
88
83
|
context "when composed of two operations using the factory method '.compose'" do
|
89
|
-
|
90
84
|
subject(:composed_operation) do
|
91
85
|
described_class.compose(string_generator, string_capitalizer).new
|
92
86
|
end
|
93
87
|
|
94
|
-
it {
|
95
|
-
|
96
|
-
it { should utilize_operations(string_generator, string_capitalizer) }
|
97
|
-
|
88
|
+
it { is_expected.to succeed_to_perform.and_return("CHUNKY BACON") }
|
89
|
+
it { is_expected.to utilize_operations(string_generator, string_capitalizer) }
|
98
90
|
end
|
99
91
|
|
100
92
|
context "when composed of two operations, one that generates a string and one that capitalizes strings, " do
|
101
|
-
|
102
93
|
subject(:composed_operation) do
|
103
94
|
operations = [string_generator, string_capitalizer]
|
104
95
|
|
@@ -109,31 +100,28 @@ describe ComposableOperations::ComposedOperation do
|
|
109
100
|
end
|
110
101
|
|
111
102
|
it "should return a capitalized version of the generated string" do
|
112
|
-
composed_operation.perform(nil).
|
103
|
+
expect(composed_operation.perform(nil)).to eq("CHUNKY BACON")
|
113
104
|
end
|
114
105
|
|
115
|
-
it {
|
116
|
-
|
106
|
+
it { is_expected.to utilize_operations(string_generator, string_capitalizer) }
|
117
107
|
end
|
118
108
|
|
119
109
|
context "when composed of three operations, one that generates a string, one that halts and one that capatalizes strings" do
|
120
|
-
|
121
110
|
subject(:composed_operation) do
|
122
111
|
described_class.compose(string_generator, halting_operation, string_capitalizer)
|
123
112
|
end
|
124
113
|
|
125
114
|
it "should return a capitalized version of the generated string" do
|
126
|
-
composed_operation.perform.
|
115
|
+
expect(composed_operation.perform).to eq(nil)
|
127
116
|
end
|
128
117
|
|
129
118
|
it "should only execute the first two operations" do
|
130
|
-
string_generator.
|
131
|
-
halting_operation.
|
132
|
-
string_capitalizer.
|
119
|
+
expect_any_instance_of(string_generator).to receive(:perform).and_call_original
|
120
|
+
expect_any_instance_of(halting_operation).to receive(:perform).and_call_original
|
121
|
+
expect_any_instance_of(string_capitalizer).not_to receive(:perform)
|
133
122
|
composed_operation.perform
|
134
123
|
end
|
135
|
-
|
136
|
-
it { should utilize_operations(string_generator, halting_operation, string_capitalizer) }
|
124
|
+
it { is_expected.to utilize_operations(string_generator, halting_operation, string_capitalizer) }
|
137
125
|
end
|
138
|
-
|
139
126
|
end
|
127
|
+
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "An operation with two before and two after filters =>" do
|
4
|
-
|
5
4
|
let(:test_operation) do
|
6
5
|
Class.new(ComposableOperations::Operation) do
|
7
6
|
|
@@ -52,22 +51,20 @@ describe "An operation with two before and two after filters =>" do
|
|
52
51
|
subject { test_operation.new }
|
53
52
|
before(:each) { subject.perform }
|
54
53
|
|
55
|
-
it ("should run 'initialize' first") { subject.trace[0].
|
56
|
-
it ("should run 'outer before' after 'initialize'") { subject.trace[1].
|
57
|
-
it ("should run 'inner before' after 'outer before'") { subject.trace[2].
|
58
|
-
it ("should start 'execute' after 'inner before'") { subject.trace[3].
|
59
|
-
it ("should stop 'execute' after it started 'execute'") { subject.trace[4].
|
60
|
-
it ("should run 'inner after' after 'execute'") { subject.trace[5].
|
61
|
-
it ("should run 'outer after' after 'inner after'") { subject.trace[6].
|
62
|
-
it ("should return :final_result as result") { subject.result.
|
63
|
-
it {
|
64
|
-
it {
|
65
|
-
it {
|
54
|
+
it ("should run 'initialize' first") { expect(subject.trace[0]).to eq(:initialize) }
|
55
|
+
it ("should run 'outer before' after 'initialize'") { expect(subject.trace[1]).to eq(:outer_before) }
|
56
|
+
it ("should run 'inner before' after 'outer before'") { expect(subject.trace[2]).to eq(:inner_before) }
|
57
|
+
it ("should start 'execute' after 'inner before'") { expect(subject.trace[3]).to eq(:execute_start) }
|
58
|
+
it ("should stop 'execute' after it started 'execute'") { expect(subject.trace[4]).to eq(:execute_stop) }
|
59
|
+
it ("should run 'inner after' after 'execute'") { expect(subject.trace[5]).to eq(:inner_after) }
|
60
|
+
it ("should run 'outer after' after 'inner after'") { expect(subject.trace[6]).to eq(:outer_after) }
|
61
|
+
it ("should return :final_result as result") { expect(subject.result).to eq(:final_result) }
|
62
|
+
it { is_expected.to be_succeeded }
|
63
|
+
it { is_expected.not_to be_failed }
|
64
|
+
it { is_expected.not_to be_halted }
|
66
65
|
end
|
67
66
|
|
68
|
-
|
69
67
|
# Now: TEST ALL! the possible code flows systematically
|
70
|
-
|
71
68
|
test_vectors = [
|
72
69
|
{
|
73
70
|
:context => "no complications =>",
|
@@ -147,11 +144,11 @@ describe "An operation with two before and two after filters =>" do
|
|
147
144
|
let(:input) { tv[:input] }
|
148
145
|
let(:trace) { subject.trace }
|
149
146
|
|
150
|
-
it("then its trace should be #{tv[:trace].inspect}") { subject.trace.
|
151
|
-
it("then its result should be #{tv[:output].inspect}") { subject.result.
|
152
|
-
it("then its succeeded? method should return #{(tv[:state] == :succeeded).inspect}") { subject.succeeded
|
153
|
-
it("then its failed? method should return #{(tv[:state] == :failed).inspect}") { subject.failed
|
154
|
-
it("then its halted? method should return #{(tv[:state] == :halted).inspect}") { subject.halted
|
147
|
+
it("then its trace should be #{tv[:trace].inspect}") { expect(subject.trace).to eq(tv[:trace]) }
|
148
|
+
it("then its result should be #{tv[:output].inspect}") { expect(subject.result).to eq(tv[:output]) }
|
149
|
+
it("then its succeeded? method should return #{(tv[:state] == :succeeded).inspect}") { expect(subject.succeeded?).to eq(tv[:state] == :succeeded) }
|
150
|
+
it("then its failed? method should return #{(tv[:state] == :failed).inspect}") { expect(subject.failed?).to eq(tv[:state] == :failed) }
|
151
|
+
it("then its halted? method should return #{(tv[:state] == :halted).inspect}") { expect(subject.halted?).to eq(tv[:state] == :halted) }
|
155
152
|
end
|
156
153
|
end
|
157
154
|
end
|
@@ -183,5 +180,5 @@ describe "An operation with two before and two after filters =>" do
|
|
183
180
|
expect { subject.perform }.to raise_error
|
184
181
|
end
|
185
182
|
end
|
186
|
-
|
187
183
|
end
|
184
|
+
|
@@ -22,25 +22,25 @@ describe ComposableOperations::Operation, "that always fails:" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should have nil as result" do
|
25
|
-
failing_operation_instance.result.
|
25
|
+
expect(failing_operation_instance.result).to be_nil
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should have failed" do
|
29
|
-
failing_operation_instance.
|
29
|
+
expect(failing_operation_instance).to be_failed
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should have a message" do
|
33
|
-
failing_operation_instance.message.
|
33
|
+
expect(failing_operation_instance.message).not_to be_nil
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should have an exception of type OperationError whose message is 'Operation failed'" do
|
37
|
-
failing_operation_instance.exception.
|
38
|
-
failing_operation_instance.exception.message.
|
37
|
+
expect(failing_operation_instance.exception).to be_kind_of(ComposableOperations::OperationError)
|
38
|
+
expect(failing_operation_instance.exception.message).to eq('Operation failed')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context "when extended with a finalizer" do
|
43
|
-
let(:supervisor) {
|
43
|
+
let(:supervisor) { double("Supervisor") }
|
44
44
|
|
45
45
|
let(:failing_operation_with_finalizer) do
|
46
46
|
supervisor = supervisor()
|
@@ -54,7 +54,7 @@ describe ComposableOperations::Operation, "that always fails:" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should execute the finalizers" do
|
57
|
-
supervisor.
|
57
|
+
expect(supervisor).to receive(:notify)
|
58
58
|
failing_operation_with_finalizer_instance.perform
|
59
59
|
end
|
60
60
|
end
|
@@ -83,8 +83,8 @@ describe ComposableOperations::Operation, "that always fails:" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should have an exception of the custom exception type whose message is 'Operation failed'" do
|
86
|
-
failing_operation_with_custom_default_exception_instance.exception.
|
87
|
-
failing_operation_with_custom_default_exception_instance.exception.message.
|
86
|
+
expect(failing_operation_with_custom_default_exception_instance.exception).to be_kind_of(custom_exception)
|
87
|
+
expect(failing_operation_with_custom_default_exception_instance.exception.message).to eq('Operation failed')
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -124,8 +124,8 @@ describe ComposableOperations::Operation, "that always fails:" do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should have an exception of the custom exception type whose message is 'Operation failed'" do
|
127
|
-
failing_operation_with_custom_exception_instance.exception.
|
128
|
-
failing_operation_with_custom_exception_instance.exception.message.
|
127
|
+
expect(failing_operation_with_custom_exception_instance.exception).to be_kind_of(custom_exception)
|
128
|
+
expect(failing_operation_with_custom_exception_instance.exception.message).to eq('Operation failed')
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -147,8 +147,8 @@ describe ComposableOperations::Operation, "that always fails:" do
|
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should have an exception of the custom exception type whose message is 'Operation failed'" do
|
150
|
-
failing_composed_operation_instance.exception.
|
151
|
-
failing_composed_operation_instance.exception.message.
|
150
|
+
expect(failing_composed_operation_instance.exception).to be_kind_of(custom_exception)
|
151
|
+
expect(failing_composed_operation_instance.exception.message).to eq('Operation failed')
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ComposableOperations::ComposedOperation, "input forwarding:" do
|
4
|
-
|
5
4
|
describe "An operation pipeline that first constructs an array with two elements and then passes it to an operation that accepts two input parameters and returns the second one" do
|
6
5
|
|
7
6
|
let(:array_generator) do
|
@@ -27,12 +26,11 @@ describe ComposableOperations::ComposedOperation, "input forwarding:" do
|
|
27
26
|
|
28
27
|
it "should return the correct element" do
|
29
28
|
result = pipeline.perform
|
30
|
-
result.
|
29
|
+
expect(result).to eq(:second_element)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
33
|
describe "An operation pipeline that first constructs an enumerator, then passes it from operation to operation and finally returns it as the result" do
|
35
|
-
|
36
34
|
let(:enum_generator) do
|
37
35
|
Class.new(ComposableOperations::Operation) do
|
38
36
|
def execute
|
@@ -56,12 +54,11 @@ describe ComposableOperations::ComposedOperation, "input forwarding:" do
|
|
56
54
|
|
57
55
|
it "should actually return an enumerator" do
|
58
56
|
result = pipeline.perform
|
59
|
-
result.
|
57
|
+
expect(result).to be_kind_of(Enumerator)
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
63
61
|
describe "An operation pipeline that first constructs an object that responds #to_a, then passes it from operation to operation and finally returns it as the result" do
|
64
|
-
|
65
62
|
let(:dummy) do
|
66
63
|
Object.new.tap do |o|
|
67
64
|
def o.to_a
|
@@ -94,8 +91,8 @@ describe ComposableOperations::ComposedOperation, "input forwarding:" do
|
|
94
91
|
|
95
92
|
it "should actually return this object" do
|
96
93
|
result = pipeline.perform
|
97
|
-
result.
|
94
|
+
expect(result).to eq(dummy)
|
98
95
|
end
|
99
96
|
end
|
100
|
-
|
101
97
|
end
|
98
|
+
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ComposableOperations::Operation, "input processing:" do
|
4
|
-
|
5
4
|
describe "An operation that takes a Hash as input" do
|
6
|
-
|
7
5
|
let(:input) { {food: "chunky bacon" } }
|
8
6
|
|
9
7
|
subject(:operation) do
|
@@ -15,12 +13,10 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
it {
|
19
|
-
|
16
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(input).and_return(input) }
|
20
17
|
end
|
21
18
|
|
22
19
|
describe "An operation that takes no arguments except for a Hash of additional options" do
|
23
|
-
|
24
20
|
subject(:operation) do
|
25
21
|
Class.new(described_class) do
|
26
22
|
def execute
|
@@ -29,13 +25,11 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
29
25
|
end
|
30
26
|
end
|
31
27
|
|
32
|
-
it {
|
33
|
-
it {
|
34
|
-
|
28
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(key: :value).and_return([]) }
|
29
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(1, 2, 3, key: :value).and_return([1, 2, 3]) }
|
35
30
|
end
|
36
31
|
|
37
32
|
describe "An operation that takes a Hash as input and an Hash of additional options" do
|
38
|
-
|
39
33
|
let(:input) { { food: nil } }
|
40
34
|
|
41
35
|
subject(:operation) do
|
@@ -49,13 +43,11 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
49
43
|
end
|
50
44
|
end
|
51
45
|
|
52
|
-
it {
|
53
|
-
it {
|
54
|
-
|
46
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(input, default_food: "bananas").and_return(food: "bananas") }
|
47
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(input).and_return(food: "chunky bacon") }
|
55
48
|
end
|
56
49
|
|
57
50
|
describe "An operation that takes two named arguments as input and sums them up" do
|
58
|
-
|
59
51
|
subject(:operation) do
|
60
52
|
Class.new(described_class) do
|
61
53
|
processes :first_operand, :second_operand
|
@@ -65,12 +57,10 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
65
57
|
end
|
66
58
|
end
|
67
59
|
|
68
|
-
it {
|
69
|
-
|
60
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(1, 2).and_return(3) }
|
70
61
|
end
|
71
62
|
|
72
63
|
describe "An operation that takes two named arguments as input and simply returns all input arguments as output" do
|
73
|
-
|
74
64
|
subject(:operation) do
|
75
65
|
Class.new(described_class) do
|
76
66
|
processes :first_operand, :second_operand
|
@@ -80,13 +70,11 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
80
70
|
end
|
81
71
|
end
|
82
72
|
|
83
|
-
it {
|
84
|
-
it {
|
85
|
-
|
73
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(1, 2).and_return([1, 2]) }
|
74
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(1, 2, 3).and_return([1, 2, 3]) }
|
86
75
|
end
|
87
76
|
|
88
77
|
describe "An operation that takes multiple arguments as input where the last of these arguments is a Hash" do
|
89
|
-
|
90
78
|
subject(:operation) do
|
91
79
|
Class.new(described_class) do
|
92
80
|
processes :first_operand, :second_operand
|
@@ -97,13 +85,11 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
97
85
|
end
|
98
86
|
end
|
99
87
|
|
100
|
-
it {
|
101
|
-
it {
|
102
|
-
|
88
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(1, 2).and_return(3) }
|
89
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(1, 2, operator: :*).and_return(2) }
|
103
90
|
end
|
104
91
|
|
105
92
|
describe "An operation that takes multiple arguments as input where the last of these arguments is a Hash, as well as, a Hash of additional options" do
|
106
|
-
|
107
93
|
subject(:operation) do
|
108
94
|
Class.new(described_class) do
|
109
95
|
processes :some_value, :yet_another_value, :a_hash
|
@@ -113,12 +99,10 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
113
99
|
end
|
114
100
|
end
|
115
101
|
|
116
|
-
it {
|
117
|
-
|
102
|
+
it { is_expected.to succeed_to_perform.when_initialized_with(1, 2, {food: "chunky bacon"}, { additional: :options }).and_return(food: "chunky bacon") }
|
118
103
|
end
|
119
104
|
|
120
105
|
describe "An operation that takes a named argument and uses the setter for the named argument" do
|
121
|
-
|
122
106
|
subject(:operation) do
|
123
107
|
Class.new(described_class) do
|
124
108
|
processes :some_value
|
@@ -129,16 +113,12 @@ describe ComposableOperations::Operation, "input processing:" do
|
|
129
113
|
end
|
130
114
|
end
|
131
115
|
|
132
|
-
it {
|
133
|
-
|
116
|
+
it { is_expected.to succeed_to_perform.when_initialized_with("unchanged").and_return("changed") }
|
134
117
|
end
|
135
|
-
|
136
118
|
end
|
137
119
|
|
138
120
|
describe ComposableOperations::ComposedOperation, "input processing:" do
|
139
|
-
|
140
121
|
describe "A composed operation that consists of a producer and a consumer" do
|
141
|
-
|
142
122
|
let(:producer) do
|
143
123
|
Class.new(ComposableOperations::Operation) do
|
144
124
|
def execute
|
@@ -166,8 +146,7 @@ describe ComposableOperations::ComposedOperation, "input processing:" do
|
|
166
146
|
end
|
167
147
|
end
|
168
148
|
|
169
|
-
it {
|
170
|
-
|
149
|
+
it { is_expected.to succeed_to_perform.and_return(3) }
|
171
150
|
end
|
172
|
-
|
173
151
|
end
|
152
|
+
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ComposableOperations::Operation do
|
4
|
-
|
5
4
|
context "that always returns nil when executed" do
|
6
|
-
|
7
5
|
subject(:nil_operation) do
|
8
6
|
class << (operation = described_class.new(''))
|
9
7
|
def execute
|
@@ -13,12 +11,10 @@ describe ComposableOperations::Operation do
|
|
13
11
|
operation
|
14
12
|
end
|
15
13
|
|
16
|
-
it {
|
17
|
-
|
14
|
+
it { is_expected.to succeed_to_perform.and_return(nil) }
|
18
15
|
end
|
19
16
|
|
20
17
|
context "that always halts and returns its original input" do
|
21
|
-
|
22
18
|
let(:halting_operation) do
|
23
19
|
Class.new(described_class) do
|
24
20
|
def execute
|
@@ -32,22 +28,20 @@ describe ComposableOperations::Operation do
|
|
32
28
|
end
|
33
29
|
|
34
30
|
it "should return the input value when executed using the class' method perform" do
|
35
|
-
halting_operation.perform("Test").
|
31
|
+
expect(halting_operation.perform("Test")).to be == "Test"
|
36
32
|
end
|
37
33
|
|
38
34
|
it "should return the input value when executed using the instance's peform method" do
|
39
|
-
halting_operation_instance.perform.
|
35
|
+
expect(halting_operation_instance.perform).to be == "Test"
|
40
36
|
end
|
41
37
|
|
42
38
|
it "should have halted after performing" do
|
43
39
|
halting_operation_instance.perform
|
44
|
-
halting_operation_instance.
|
40
|
+
expect(halting_operation_instance).to be_halted
|
45
41
|
end
|
46
|
-
|
47
42
|
end
|
48
43
|
|
49
44
|
context "that always returns something when executed" do
|
50
|
-
|
51
45
|
let(:simple_operation) do
|
52
46
|
Class.new(described_class) do
|
53
47
|
def execute
|
@@ -65,15 +59,14 @@ describe ComposableOperations::Operation do
|
|
65
59
|
end
|
66
60
|
|
67
61
|
it "should have a result" do
|
68
|
-
simple_operation_instance.result.
|
62
|
+
expect(simple_operation_instance.result).to be
|
69
63
|
end
|
70
64
|
|
71
65
|
it "should have succeeded" do
|
72
|
-
simple_operation_instance.
|
66
|
+
expect(simple_operation_instance).to be_succeeded
|
73
67
|
end
|
74
68
|
|
75
69
|
context "when extended with a preparator and a finalizer" do
|
76
|
-
|
77
70
|
let(:logger) { double("Logger") }
|
78
71
|
|
79
72
|
subject(:simple_operation_with_preparator_and_finalizer) do
|
@@ -85,29 +78,24 @@ describe ComposableOperations::Operation do
|
|
85
78
|
end
|
86
79
|
|
87
80
|
it "should execute the preparator and finalizer when performing" do
|
88
|
-
logger.
|
89
|
-
logger.
|
81
|
+
expect(logger).to receive(:info).ordered.with("preparing")
|
82
|
+
expect(logger).to receive(:info).ordered.with("finalizing")
|
90
83
|
simple_operation_with_preparator_and_finalizer.perform
|
91
84
|
end
|
92
|
-
|
93
85
|
end
|
94
86
|
|
95
87
|
context "when extended with a finalizer that checks that the result is not an empty string" do
|
96
|
-
|
97
88
|
subject(:simple_operation_with_sanity_check) do
|
98
89
|
Class.new(simple_operation) do
|
99
90
|
after { fail "the operational result is an empty string" if self.result == "" }
|
100
91
|
end
|
101
92
|
end
|
102
93
|
|
103
|
-
it {
|
104
|
-
|
94
|
+
it { is_expected.to fail_to_perform.because("the operational result is an empty string") }
|
105
95
|
end
|
106
|
-
|
107
96
|
end
|
108
97
|
|
109
98
|
context "that can be parameterized" do
|
110
|
-
|
111
99
|
subject(:string_multiplier) do
|
112
100
|
Class.new(described_class) do
|
113
101
|
processes :text
|
@@ -119,13 +107,11 @@ describe ComposableOperations::Operation do
|
|
119
107
|
end
|
120
108
|
end
|
121
109
|
|
122
|
-
it {
|
123
|
-
it {
|
124
|
-
|
110
|
+
it { is_expected.to succeed_to_perform.when_initialized_with("-").and_return("---") }
|
111
|
+
it { is_expected.to succeed_to_perform.when_initialized_with("-", multiplier: 5).and_return("-----") }
|
125
112
|
end
|
126
113
|
|
127
114
|
context "that processes two values (a string and a multiplier)" do
|
128
|
-
|
129
115
|
subject(:string_multiplier) do
|
130
116
|
Class.new(described_class) do
|
131
117
|
processes :string, :multiplier
|
@@ -136,9 +122,7 @@ describe ComposableOperations::Operation do
|
|
136
122
|
end
|
137
123
|
end
|
138
124
|
|
139
|
-
it {
|
140
|
-
|
125
|
+
it { is_expected.to succeed_to_perform.when_initialized_with("-", 3).and_return("---") }
|
141
126
|
end
|
142
|
-
|
143
127
|
end
|
144
128
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composable_operations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Tennhard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_properties
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.0'
|
83
83
|
description: |-
|
84
84
|
Composable Operations is a tool set for creating operations and assembling
|
85
85
|
multiple of these operations in operation pipelines.
|
@@ -90,6 +90,7 @@ extensions: []
|
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
92
|
- ".gitignore"
|
93
|
+
- ".travis.yml"
|
93
94
|
- Gemfile
|
94
95
|
- LICENSE.txt
|
95
96
|
- README.md
|
@@ -142,4 +143,3 @@ test_files:
|
|
142
143
|
- spec/composable_operations/operation_input_processing_spec.rb
|
143
144
|
- spec/composable_operations/operation_spec.rb
|
144
145
|
- spec/spec_helper.rb
|
145
|
-
has_rdoc:
|