isomorfeus-operation 1.0.0.zeta10 → 1.0.0.zeta11

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
  SHA256:
3
- metadata.gz: 22c168cd9a23de81eee4ae1b895a5f7af7a6060404b353999e0be3e8baf83ede
4
- data.tar.gz: 3fe7dc3877b1bda0a2cc49225f24dec950a94bc1c9df9ce2545a954667e3f0dd
3
+ metadata.gz: b930d60e18bbeee4a7e6d7a7a485b30fab763a125effc4dc8d247a2d623f4620
4
+ data.tar.gz: fa908d46658112782209ea3d4356e58c0cf25650ef290efd571fe2dc44862710
5
5
  SHA512:
6
- metadata.gz: 3008ae8becff8ae908f56a5366879c4d420ed9efa68036364db30ebd35493d509ec92f3d4183d74e4632091bc0e2f6a8b1faa694f05f32dba623763fa2a22407
7
- data.tar.gz: 2f519ac92c744beade913436932d6c381fc0bd2f081a001df33e96a7693c296d77b31f5f2473bed57e044b5ff45f24573b579ed77a3dbb6c376be5e4f13dae59
6
+ metadata.gz: 1204dd77815390824442797f78bd4286f5d01413165b2e5eaed3adde6e0c7a096c87694984eb7702e9b78280c2cd70ce3539a10e60b05d597bd14ab56aab3cf3
7
+ data.tar.gz: 1d54a02687d8e1327481e49fb21ed1a0e5f086a5cbd6ee239aba014d1a247c75b2830ca31baa2526ed97b6badba3d7da5bebc8af989489ecf4059004e9b173af
data/README.md CHANGED
@@ -22,11 +22,15 @@ class MyQuickOp < LucidQuickOp::Base
22
22
  end
23
23
 
24
24
  MyQuickOp.promise_run(a_prop: 'a_value')
25
+
26
+ # or
27
+
28
+ MyQuickOp.promise_run(props: { a_prop: 'a_value' })
25
29
  ```
26
30
 
27
31
  Quick remote procedure call, always executed on the server.
28
32
  LucidOperation too is always executed on the Server. It allows to define Operations in gherkin human language style:
29
- ```
33
+ ```ruby
30
34
  class MyOperation < LucidOperation::Base
31
35
  prop :a_prop
32
36
 
@@ -44,6 +48,10 @@ class MyOperation < LucidOperation::Base
44
48
  end
45
49
 
46
50
  MyOperation.promise_run(a_prop: 'a_value')
51
+
52
+ # or
53
+
54
+ MyOperation.promise_run(props: { a_prop: 'a_value' })
47
55
  ```
48
56
 
49
57
  LucidLocalOperation is the same as LucidOperation, except its always executed locally, wherever that may be.
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Operation
3
- VERSION = '1.0.0.zeta10'
3
+ VERSION = '1.0.0.zeta11'
4
4
  end
5
5
  end
@@ -1,21 +1,22 @@
1
1
  require 'isomorfeus-transport'
2
2
  require 'isomorfeus/operation/config'
3
- require 'isomorfeus/operation/gherkin'
4
- require 'isomorfeus/operation/mixin'
5
- require 'isomorfeus/operation/promise_run'
6
- require 'lucid_local_operation/mixin'
7
- require 'lucid_local_operation/base'
8
- require 'lucid_quick_op/mixin'
9
- require 'lucid_quick_op/base'
10
- require 'lucid_operation/mixin'
11
- require 'lucid_operation/base'
12
3
 
13
4
  if RUBY_ENGINE == 'opal'
5
+ Isomorfeus.zeitwerk.push_dir('isomorfeus_operation')
6
+ require_tree 'isomorfeus_operation', :autoload
14
7
  Isomorfeus.zeitwerk.push_dir('operations')
15
8
  else
16
9
  require 'oj'
17
10
  require 'isomorfeus/operation/handler/operation_handler'
18
-
11
+ require 'isomorfeus_operation/lucid_operation/gherkin'
12
+ require 'isomorfeus_operation/lucid_operation/steps'
13
+ require 'isomorfeus_operation/lucid_operation/promise_run'
14
+ require 'isomorfeus_operation/lucid_local_operation/mixin'
15
+ require 'isomorfeus_operation/lucid_local_operation/base'
16
+ require 'isomorfeus_operation/lucid_quick_op/mixin'
17
+ require 'isomorfeus_operation/lucid_quick_op/base'
18
+ require 'isomorfeus_operation/lucid_operation/mixin'
19
+ require 'isomorfeus_operation/lucid_operation/base'
19
20
  Opal.append_path(__dir__.untaint) unless Opal.paths.include?(__dir__.untaint)
20
21
 
21
22
  # require 'active_support/dependencies'
@@ -6,11 +6,12 @@ module LucidLocalOperation
6
6
  end
7
7
 
8
8
  base.extend(LucidPropDeclaration::Mixin)
9
- base.extend(Isomorfeus::Operation::Mixin)
10
- base.include(Isomorfeus::Operation::PromiseRun)
9
+ base.extend(LucidOperation::Steps)
10
+ base.include(LucidOperation::PromiseRun)
11
11
 
12
12
  base.instance_exec do
13
- def promise_run(props_hash)
13
+ def promise_run(props_hash = nil, props: nil)
14
+ props_hash = props_hash || props
14
15
  validate_props(props_hash)
15
16
  self.new(props_hash).promise_run
16
17
  end
@@ -0,0 +1,63 @@
1
+ module LucidOperation
2
+ module Gherkin
3
+ FIRST_EXCEPTION = "First must be the first one that is used and can only used once!"
4
+ FINALLY_EXCEPTION = "Finally, except for Ensure and Failed, must be the last one to be used and can only be used once!"
5
+
6
+ NEWLINE = /\r?\n/
7
+ OPERATION = /^\s*Operation: (.*)$/
8
+ PROCEDURE = /^\s*Procedure: (.*)$/
9
+ STAR = /^\s*\* (.*)$/
10
+ GIVEN = /^\s*Given (.*)$/
11
+ WHEN = /^\s*When (.*)$/
12
+ THEN = /^\s*Then (.*)$/
13
+ AND = /^\s*And (.*)$/
14
+ FIRST = /^\s*First (.*)$/
15
+ ENSURE = /^\s*Ensure (.*)$/
16
+ FINALLY = /^\s*Finally (.*)$/
17
+ IW_FAILING = /^\s*(?:When|If) failing (.*)$/
18
+ IF_ITT_FAILED = /^\s*If (?:that|this|it) failed (.*)$/
19
+ FAILED = /^\s*Failed (.*)$/
20
+ COMMENT = /^\s*# (.*)$/
21
+ WHITE_SPACE = /^\s*$/
22
+
23
+ def self.parse(gherkin_text)
24
+ operation = { operation: '', procedure: '', steps: [], failure: [], ensure: [] }
25
+ has_finally = false
26
+ lines = gherkin_text.split(NEWLINE)
27
+
28
+ lines.each do |line|
29
+ case line
30
+ when STAR, GIVEN, WHEN, THEN, AND
31
+ raise FINALLY_EXCEPTION if has_finally
32
+ operation[:steps] << $1.strip
33
+ when ENSURE
34
+ operation[:ensure] << $1.strip
35
+ when IW_FAILING, IF_ITT_FAILED, FAILED
36
+ operation[:failure] << $1.strip
37
+ when FIRST
38
+ raise FIRST_EXCEPTION if operation[:steps].size > 0
39
+ operation[:steps] << $1.strip
40
+ when FINALLY
41
+ raise FINALLY_EXCEPTION if has_finally
42
+ operation[:steps] << $1.strip
43
+ has_finally = true
44
+ when PROCEDURE
45
+ raise 'No Operation defined!' if operation[:operation].empty?
46
+ raise 'Procedure already defined!' unless operation[:procedure].empty?
47
+ operation[:procedure] = $1.strip
48
+ when OPERATION
49
+ raise 'Operation already defined!' unless operation[:operation].empty?
50
+ operation[:operation] = $1.strip
51
+ when WHITE_SPACE, COMMENT
52
+ # nothing, just skip
53
+ else
54
+ raise "Unknown key word(s) at the beginning of the line: #{line}" unless operation[:procedure].empty?
55
+ operation[:description] = [] unless operation.key?(:description)
56
+ operation[:description] << line.strip
57
+ end
58
+ end
59
+
60
+ operation
61
+ end
62
+ end
63
+ end
@@ -36,9 +36,10 @@ module LucidOperation
36
36
  @finally_defined = true
37
37
  end
38
38
 
39
- def promise_run(props_hash)
39
+ def promise_run(props_hash = nil)
40
+ props_hash = props_hash || props
40
41
  validate_props(props_hash)
41
- props_json = Isomorfeus::Data::Props.new(props_hash).to_json
42
+ props_json = Isomorfeus::Transport::PropsProxy.new(props_hash).to_json
42
43
  Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, props_json).then do |agent|
43
44
  if agent.processed
44
45
  agent.result
@@ -55,8 +56,8 @@ module LucidOperation
55
56
  end
56
57
  else
57
58
  Isomorfeus.add_valid_operation_class(base) unless base == LucidOperation::Base
58
- base.extend(Isomorfeus::Operation::Mixin)
59
- base.include(Isomorfeus::Operation::PromiseRun)
59
+ base.extend(LucidOperation::Steps)
60
+ base.include(LucidOperation::PromiseRun)
60
61
 
61
62
  unless base == LucidOperation::Base
62
63
  base.prop :pub_sub_client, default: nil
@@ -64,7 +65,8 @@ module LucidOperation
64
65
  end
65
66
 
66
67
  base.instance_exec do
67
- def promise_run(props_hash)
68
+ def promise_run(props_hash = nil)
69
+ props_hash = props_hash || props
68
70
  validate_props(props_hash)
69
71
  self.new(props_hash).promise_run
70
72
  end
@@ -0,0 +1,74 @@
1
+ module LucidOperation
2
+ module PromiseRun
3
+ def initialize(validated_props_hash)
4
+ @props = Isomorfeus::Transport::PropsProxy.new(validated_props_hash)
5
+ end
6
+
7
+ def promise_run
8
+ promise = Promise.new
9
+ original_promise = promise
10
+ operation = self
11
+
12
+ # steps
13
+ self.class.gherkin[:steps].each do |gherkin_step|
14
+ matched = false
15
+ self.class.steps.each do |step|
16
+ # step[0] -> regular_expression
17
+ # step[1] -> block
18
+ match_data = gherkin_step.match(step[0])
19
+ if match_data
20
+ matched = true
21
+ promise = promise.then do |result|
22
+ operation.step_result = result
23
+ operation.instance_exec(*match_data, &step[1])
24
+ end
25
+ end
26
+ end
27
+ raise "No match found for step #{gherkin_step}!" unless matched
28
+ end
29
+
30
+ # fail track
31
+ self.class.gherkin[:failure].each do |gherkin_step|
32
+ matched = false
33
+ self.class.failure_steps.each do |step|
34
+ # step[0] -> regular_expression
35
+ # step[1] -> block
36
+ match_data = gherkin_step.match(step[0])
37
+ if match_data
38
+ matched = true
39
+ promise = promise.fail do |result|
40
+ operation.step_result = result
41
+ operation.instance_exec(*match_data, &step[1])
42
+ end
43
+ end
44
+ end
45
+ raise "No match found for failure step #{gherkin_step}!" unless matched
46
+ end
47
+
48
+ # ensure
49
+ self.class.gherkin[:ensure].each do |gherkin_step|
50
+ matched = false
51
+ self.class.ensure_steps.each do |step|
52
+ # step[0] -> regular_expression
53
+ # step[1] -> block
54
+ match_data = gherkin_step.match(step[0])
55
+ if match_data
56
+ matched = true
57
+
58
+ promise = promise.then do |result|
59
+ operation.step_result = result
60
+ operation.instance_exec(*match_data, &step[1])
61
+ end.fail do |result|
62
+ operation.step_result = result
63
+ operation.instance_exec(*match_data, &step[1])
64
+ end
65
+ end
66
+ end
67
+ raise "No match found for ensure step #{gherkin_step}!" unless matched
68
+ end
69
+
70
+ original_promise.resolve
71
+ promise
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LucidOperation
4
+ module Steps
5
+ def procedure(gherkin_text)
6
+ feature_line = gherkin_text.include?('Operation: ') ? '' : "Operation: #{self.name}\n"
7
+ scenario_line = feature_line == '' || gherkin_text.include?('Procedure: ') ? '' : " Procedure: #{self.name} executing\n"
8
+ @procedure = feature_line + scenario_line + gherkin_text
9
+ end
10
+
11
+ def gherkin
12
+ @gherkin ||= LucidOperation::Gherkin.parse(@procedure)
13
+ end
14
+
15
+ def ensure_steps
16
+ @ensure_steps ||= []
17
+ end
18
+
19
+ def failure_steps
20
+ @failure_steps ||= []
21
+ end
22
+
23
+ def steps
24
+ @steps ||= []
25
+ end
26
+
27
+ def First(regular_expression, &block)
28
+ raise "#{self}: First already defined, can only be defined once!" if @first_defined
29
+ @first_defined = true
30
+ steps << [regular_expression, block]
31
+ end
32
+
33
+ def Given(regular_expression, &block)
34
+ steps << [regular_expression, block]
35
+ end
36
+ alias :And :Given
37
+ alias :Then :Given
38
+ alias :When :Given
39
+
40
+ def Finally(regular_expression, &block)
41
+ raise "#{self}: Finally already defined, can only be defined once!" if @finally_defined
42
+ @finally_defined = true
43
+ steps << [regular_expression, block]
44
+ end
45
+
46
+ def Ensure(regular_expression, &block)
47
+ ensure_steps << [regular_expression, block]
48
+ end
49
+
50
+ def Failed(regular_expression, &block)
51
+ failure_steps << [regular_expression, block]
52
+ end
53
+ alias :If_failing :Failed
54
+ alias :When_failing :Failed
55
+ alias :If_this_failed :Failed
56
+ alias :If_that_failed :Failed
57
+ end
58
+ end
@@ -8,9 +8,10 @@ module LucidQuickOp
8
8
  def op
9
9
  end
10
10
 
11
- def promise_run(props_hash)
11
+ def promise_run(props_hash = nil)
12
+ props_hash = props_hash || props
12
13
  validate_props(props_hash)
13
- props_json = Isomorfeus::Data::Props.new(props_hash).to_json
14
+ props_json = Isomorfeus::Transport::PropsProxy.new(props_hash).to_json
14
15
  Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, props_json).then do |agent|
15
16
  if agent.processed
16
17
  agent.result
@@ -38,7 +39,8 @@ module LucidQuickOp
38
39
  @op = block
39
40
  end
40
41
 
41
- def promise_run(props_hash)
42
+ def promise_run(props_hash = nil)
43
+ props_hash = props_hash || props
42
44
  validate_props(props_hash)
43
45
  self.new(props_hash).promise_run
44
46
  end
@@ -49,12 +51,12 @@ module LucidQuickOp
49
51
  attr_accessor :props
50
52
 
51
53
  def initialize(validated_props_hash)
52
- @props = Isomorfeus::Data::Props.new(validated_props_hash)
54
+ @props = Isomorfeus::Transport::PropsProxy.new(validated_props_hash)
53
55
  @on_fail_track = false
54
56
  end
55
57
 
56
58
  def promise_run
57
- original_promise = Promise.new.then
59
+ original_promise = Promise.new
58
60
 
59
61
  operation = self
60
62
  promise = original_promise.then do |result|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.zeta10
4
+ version: 1.0.0.zeta11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-19 00:00:00.000000000 Z
11
+ date: 2019-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 16.12.4
75
+ version: 16.12.6
76
76
  type: :runtime
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: 16.12.4
82
+ version: 16.12.6
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: isomorfeus-redux
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,42 +100,42 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 1.0.0.zeta10
103
+ version: 1.0.0.zeta11
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 1.0.0.zeta10
110
+ version: 1.0.0.zeta11
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: isomorfeus
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.0.0.zeta10
117
+ version: 1.0.0.zeta11
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 1.0.0.zeta10
124
+ version: 1.0.0.zeta11
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: opal-webpack-loader
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 0.9.9
131
+ version: 0.9.10
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 0.9.9
138
+ version: 0.9.10
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rake
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -174,17 +174,17 @@ files:
174
174
  - README.md
175
175
  - lib/isomorfeus-operation.rb
176
176
  - lib/isomorfeus/operation/config.rb
177
- - lib/isomorfeus/operation/gherkin.rb
178
177
  - lib/isomorfeus/operation/handler/operation_handler.rb
179
- - lib/isomorfeus/operation/mixin.rb
180
- - lib/isomorfeus/operation/promise_run.rb
181
178
  - lib/isomorfeus/operation/version.rb
182
- - lib/lucid_local_operation/base.rb
183
- - lib/lucid_local_operation/mixin.rb
184
- - lib/lucid_operation/base.rb
185
- - lib/lucid_operation/mixin.rb
186
- - lib/lucid_quick_op/base.rb
187
- - lib/lucid_quick_op/mixin.rb
179
+ - lib/isomorfeus_operation/lucid_local_operation/base.rb
180
+ - lib/isomorfeus_operation/lucid_local_operation/mixin.rb
181
+ - lib/isomorfeus_operation/lucid_operation/base.rb
182
+ - lib/isomorfeus_operation/lucid_operation/gherkin.rb
183
+ - lib/isomorfeus_operation/lucid_operation/mixin.rb
184
+ - lib/isomorfeus_operation/lucid_operation/promise_run.rb
185
+ - lib/isomorfeus_operation/lucid_operation/steps.rb
186
+ - lib/isomorfeus_operation/lucid_quick_op/base.rb
187
+ - lib/isomorfeus_operation/lucid_quick_op/mixin.rb
188
188
  homepage: http://isomorfeus.com
189
189
  licenses:
190
190
  - MIT
@@ -1,65 +0,0 @@
1
- module Isomorfeus
2
- module Operation
3
- module Gherkin
4
- FIRST_EXCEPTION = "First must be the first one that is used and can only used once!"
5
- FINALLY_EXCEPTION = "Finally, except for Ensure and Failed, must be the last one to be used and can only be used once!"
6
-
7
- NEWLINE = /\r?\n/
8
- OPERATION = /^\s*Operation: (.*)$/
9
- PROCEDURE = /^\s*Procedure: (.*)$/
10
- STAR = /^\s*\* (.*)$/
11
- GIVEN = /^\s*Given (.*)$/
12
- WHEN = /^\s*When (.*)$/
13
- THEN = /^\s*Then (.*)$/
14
- AND = /^\s*And (.*)$/
15
- FIRST = /^\s*First (.*)$/
16
- ENSURE = /^\s*Ensure (.*)$/
17
- FINALLY = /^\s*Finally (.*)$/
18
- IW_FAILING = /^\s*(?:When|If) failing (.*)$/
19
- IF_ITT_FAILED = /^\s*If (?:that|this|it) failed (.*)$/
20
- FAILED = /^\s*Failed (.*)$/
21
- COMMENT = /^\s*# (.*)$/
22
- WHITE_SPACE = /^\s*$/
23
-
24
- def self.parse(gherkin_text)
25
- operation = { operation: '', procedure: '', steps: [], failure: [], ensure: [] }
26
- has_finally = false
27
- lines = gherkin_text.split(NEWLINE)
28
-
29
- lines.each do |line|
30
- case line
31
- when STAR, GIVEN, WHEN, THEN, AND
32
- raise FINALLY_EXCEPTION if has_finally
33
- operation[:steps] << $1.strip
34
- when ENSURE
35
- operation[:ensure] << $1.strip
36
- when IW_FAILING, IF_ITT_FAILED, FAILED
37
- operation[:failure] << $1.strip
38
- when FIRST
39
- raise FIRST_EXCEPTION if operation[:steps].size > 0
40
- operation[:steps] << $1.strip
41
- when FINALLY
42
- raise FINALLY_EXCEPTION if has_finally
43
- operation[:steps] << $1.strip
44
- has_finally = true
45
- when PROCEDURE
46
- raise 'No Operation defined!' if operation[:operation].empty?
47
- raise 'Procedure already defined!' unless operation[:procedure].empty?
48
- operation[:procedure] = $1.strip
49
- when OPERATION
50
- raise 'Operation already defined!' unless operation[:operation].empty?
51
- operation[:operation] = $1.strip
52
- when WHITE_SPACE, COMMENT
53
- # nothing, just skip
54
- else
55
- raise "Unknown key word(s) at the beginning of the line: #{line}" unless operation[:procedure].empty?
56
- operation[:description] = [] unless operation.key?(:description)
57
- operation[:description] << line.strip
58
- end
59
- end
60
-
61
- operation
62
- end
63
- end
64
- end
65
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Isomorfeus
4
- module Operation
5
- module Mixin
6
- def procedure(gherkin_text)
7
- feature_line = gherkin_text.include?('Operation: ') ? '' : "Operation: #{self.name}\n"
8
- scenario_line = feature_line == '' || gherkin_text.include?('Procedure: ') ? '' : " Procedure: #{self.name} executing\n"
9
- @procedure = feature_line + scenario_line + gherkin_text
10
- end
11
-
12
- def gherkin
13
- @gherkin ||= Isomorfeus::Operation::Gherkin.parse(@procedure)
14
- end
15
-
16
- def ensure_steps
17
- @ensure_steps ||= []
18
- end
19
-
20
- def failure_steps
21
- @failure_steps ||= []
22
- end
23
-
24
- def steps
25
- @steps ||= []
26
- end
27
-
28
- def First(regular_expression, &block)
29
- raise "#{self}: First already defined, can only be defined once!" if @first_defined
30
- @first_defined = true
31
- steps << [regular_expression, block]
32
- end
33
-
34
- def Given(regular_expression, &block)
35
- steps << [regular_expression, block]
36
- end
37
- alias :And :Given
38
- alias :Then :Given
39
- alias :When :Given
40
-
41
- def Finally(regular_expression, &block)
42
- raise "#{self}: Finally already defined, can only be defined once!" if @finally_defined
43
- @finally_defined = true
44
- steps << [regular_expression, block]
45
- end
46
-
47
- def Ensure(regular_expression, &block)
48
- ensure_steps << [regular_expression, block]
49
- end
50
-
51
- def Failed(regular_expression, &block)
52
- failure_steps << [regular_expression, block]
53
- end
54
- alias :If_failing :Failed
55
- alias :When_failing :Failed
56
- alias :If_this_failed :Failed
57
- alias :If_that_failed :Failed
58
- end
59
- end
60
- end
@@ -1,76 +0,0 @@
1
- module Isomorfeus
2
- module Operation
3
- module PromiseRun
4
- def initialize(validated_props_hash)
5
- @props = Isomorfeus::Data::Props.new(validated_props_hash)
6
- end
7
-
8
- def promise_run
9
- promise = Promise.new
10
- original_promise = promise
11
- operation = self
12
-
13
- # steps
14
- self.class.gherkin[:steps].each do |gherkin_step|
15
- matched = false
16
- self.class.steps.each do |step|
17
- # step[0] -> regular_expression
18
- # step[1] -> block
19
- match_data = gherkin_step.match(step[0])
20
- if match_data
21
- matched = true
22
- promise = promise.then do |result|
23
- operation.step_result = result
24
- operation.instance_exec(*match_data, &step[1])
25
- end
26
- end
27
- end
28
- raise "No match found for step #{gherkin_step}!" unless matched
29
- end
30
-
31
- # fail track
32
- self.class.gherkin[:failure].each do |gherkin_step|
33
- matched = false
34
- self.class.failure_steps.each do |step|
35
- # step[0] -> regular_expression
36
- # step[1] -> block
37
- match_data = gherkin_step.match(step[0])
38
- if match_data
39
- matched = true
40
- promise = promise.fail do |result|
41
- operation.step_result = result
42
- operation.instance_exec(*match_data, &step[1])
43
- end
44
- end
45
- end
46
- raise "No match found for failure step #{gherkin_step}!" unless matched
47
- end
48
-
49
- # ensure
50
- self.class.gherkin[:ensure].each do |gherkin_step|
51
- matched = false
52
- self.class.ensure_steps.each do |step|
53
- # step[0] -> regular_expression
54
- # step[1] -> block
55
- match_data = gherkin_step.match(step[0])
56
- if match_data
57
- matched = true
58
-
59
- promise = promise.then do |result|
60
- operation.step_result = result
61
- operation.instance_exec(*match_data, &step[1])
62
- end.fail do |result|
63
- operation.step_result = result
64
- operation.instance_exec(*match_data, &step[1])
65
- end
66
- end
67
- end
68
- raise "No match found for ensure step #{gherkin_step}!" unless matched
69
- end
70
-
71
- original_promise.resolve
72
- promise
73
- end
74
- end
75
- end
76
- end