composable_operations 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e322ef724df070ae4f606346ec732d0931174a49
4
- data.tar.gz: 7119c160bc2d4cb1bc4138bd6c2fe4f321ebfc89
3
+ metadata.gz: 237f6bf42a1d019c2f0de93dd8baa18c187fa276
4
+ data.tar.gz: 1c8648513871178ab2d34127fa29b1799adbee28
5
5
  SHA512:
6
- metadata.gz: 22589a1c44ebf3c74e564f3286d2aa9136516ef29698047632f4124e9171caeb03bc2bc9a0d9d20de2645b9b727b1807e0d9c0e01cd5de9f69b38092a78746bf
7
- data.tar.gz: 609dc3b474ea1d374dd705422d1a95129e309b31d5fabb70479a3f42a8d95d89dcf63ae13c83a4facf62a7a5c493e7d5bdce109c04233fad7ddeef9550acda0f
6
+ metadata.gz: 1f241f35e8737eb4b1aa2a585921ec97d44ccaf62210d7eb9b166e74933cbfb8a9d147c6aee31d36bcf13fca4acf8475ed3bdcb3bde30aa9115bab8c91e645fd
7
+ data.tar.gz: 483847be976d67e1afdcd24dd5a5cf28237a1598e4b1419de1ccb48dd623a318b1ec137b68688172d77c4ff6c17056c92dce1413a678bbf631258adb08270fdd
@@ -14,9 +14,19 @@ module ComposableOperations
14
14
  self
15
15
  end
16
16
 
17
+ def failure_message
18
+ raise NotImplementedError, "Expected #{self.class} to implement ##{__callee__}"
19
+ end
20
+
21
+ def failure_message_when_negated
22
+ raise NotImplementedError, "Expected #{self.class} to implement ##{__callee__}"
23
+ end
24
+ alias negative_failure_message failure_message_when_negated
25
+
17
26
  protected
18
27
 
19
28
  attr_reader :operation
29
+ attr_reader :message
20
30
  attr_reader :result
21
31
  attr_reader :input
22
32
 
@@ -34,11 +44,20 @@ module ComposableOperations
34
44
  operation.succeeded?
35
45
  end
36
46
 
47
+ def halted?
48
+ operation.halted?
49
+ end
50
+
37
51
  def result_as_expected?
38
52
  return true unless result
39
53
  operation.result == result
40
54
  end
41
55
 
56
+ def message_as_expected?
57
+ return true unless message
58
+ operation.message == message
59
+ end
60
+
42
61
  def input_as_text
43
62
  humanize(*input)
44
63
  end
@@ -78,7 +97,6 @@ module ComposableOperations
78
97
  def failure_message_when_negated
79
98
  "the operation succeeded unexpectedly"
80
99
  end
81
- alias negative_failure_message failure_message_when_negated
82
100
 
83
101
  private
84
102
 
@@ -124,20 +142,58 @@ module ComposableOperations
124
142
  def failure_message_when_negated
125
143
  "the operation failed unexpectedly"
126
144
  end
127
- alias negative_failure_message failure_message_when_negated
128
145
 
129
146
  protected
130
147
 
131
- attr_reader :message
132
-
133
- def message_as_expected?
134
- return true unless message
135
- operation.message == message
148
+ def failure_reasons
149
+ reasons = []
150
+ reasons << "it did not fail at all" unless failed?
151
+ reasons << "its message was not as expected" unless message_as_expected?
152
+ unless result_as_expected?
153
+ reasons << [
154
+ "it did not return the expected result",
155
+ "Expected: #{result.inspect}",
156
+ "Got: #{operation.result.inspect}"
157
+ ].join("\n\t ")
158
+ end
159
+ reasons.map { |r| "\t- #{r}" }.join("\n")
136
160
  end
137
161
 
162
+ end
163
+
164
+ class HaltWhilePerforming < Base
165
+
166
+ def matches?(operation)
167
+ self.operation = operation
168
+ halted? && result_as_expected? && message_as_expected?
169
+ end
170
+
171
+ def because(message)
172
+ @message = message
173
+ self
174
+ end
175
+
176
+ def description
177
+ description = "halt while performing"
178
+ description += " because #{message}" if message
179
+ description += " when initialized with custom input (#{input_as_text})" if input
180
+ description += " and return the expected result (#{result_as_text})" if result
181
+ description
182
+ end
183
+
184
+ def failure_message
185
+ "the operation did not halt while performing for the following reason(s):\n#{failure_reasons}"
186
+ end
187
+
188
+ def failure_message_when_negated
189
+ "the operation was halted unexpectedly"
190
+ end
191
+
192
+ protected
193
+
138
194
  def failure_reasons
139
195
  reasons = []
140
- reasons << "it did not fail at all" unless failed?
196
+ reasons << "it did not halt at all" unless halted?
141
197
  reasons << "its message was not as expected" unless message_as_expected?
142
198
  unless result_as_expected?
143
199
  reasons << [
@@ -159,6 +215,10 @@ module ComposableOperations
159
215
  FailToPerform.new
160
216
  end
161
217
 
218
+ def halt_while_performing
219
+ HaltWhilePerforming.new
220
+ end
221
+
162
222
  end
163
223
  end
164
224
  end
@@ -1,3 +1,3 @@
1
1
  module ComposableOperations
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composable_operations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Tennhard