lopata 0.1.22 → 0.1.23

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: 594efeb814131537b5efdcd66d912bf4557038f47a85e3fad0fb9b17408586fb
4
- data.tar.gz: a63860ec22996bd77f569ad3e85060b208eefc392ec79f6e5d3be7dc56ac7418
3
+ metadata.gz: 9404c01f3020e012451ba5cd5c6d91fbec443df94fe961ad9159e296f5783775
4
+ data.tar.gz: 16523f8e209f6864370912267f5e26955e1cc07708cfc7f31b2d4f324c0a2aec
5
5
  SHA512:
6
- metadata.gz: 110b59071e44955f890c8df68c6cc1d5180b968d8c93556ddae4a3da29fe253951f9650a36dc7f5dc38ad04e9bbd9e770100332597512c267ae387cfca7b82f0
7
- data.tar.gz: f2300be4be7155921fdf1972fd5bc98832daccc3707d80c8f93d51fe806a130914349f978931c09317f629acc57561b564955a07521a66139234229e6b9a7bdc
6
+ metadata.gz: 2c81b2e83e0df4838d7743dccdc6c79ef689ccb0d8a1caed6bf3ba3ecfd228041841b531881390a5efe369cc05d681feab919b0d0acebea8d48a065c36e0c6be
7
+ data.tar.gz: 363b3ea67a91e50ead1d51eb23c50856e9a5a8f2a0f524f56fbabd9f72d3c1b5cb4b7254b9bcf6bcc4fbaef57024ffe6a207bb52d277f8eb96e1a3723d1346fc
@@ -1,14 +1,19 @@
1
1
  module Lopata
2
2
  # @private
3
3
  class Condition
4
- attr_reader :condition, :positive
4
+ attr_reader :condition, :positive, :dynamic
5
5
  def initialize(condition, positive: true)
6
6
  @condition, @positive = condition, positive
7
+ @dynamic = @condition.is_a?(Proc)
7
8
  end
8
9
 
9
10
  alias positive? positive
11
+ alias dynamic? dynamic
10
12
 
13
+ # Match scenario on build-time.
11
14
  def match?(scenario)
15
+ # dynamic steps match scenario in build-time: will be verified later
16
+ return true if dynamic?
12
17
  matched = match_metadata?(scenario)
13
18
  positive? ? matched : !matched
14
19
  end
@@ -33,5 +38,10 @@ module Lopata
33
38
  end
34
39
  end
35
40
 
41
+ def match_dynamic?(scenario_runtime)
42
+ return false unless dynamic?
43
+ matched = scenario_runtime.instance_exec(&condition)
44
+ positive? ? matched : !matched
45
+ end
36
46
  end
37
47
  end
@@ -90,7 +90,17 @@ class Lopata::Scenario
90
90
  end
91
91
 
92
92
  def run_step(step)
93
- return if step.skipped?
93
+ return if step.skipped? || step.ignored?
94
+ groups = step.groups
95
+ if groups.length > 0 && groups != @current_groups
96
+ @current_groups = groups
97
+ condition = groups.last.condition
98
+ if condition&.dynamic? && !condition.match_dynamic?(scenario)
99
+ step.ignored!
100
+ ignore_groups(groups)
101
+ return
102
+ end
103
+ end
94
104
  @current_step = step
95
105
  step.run(scenario)
96
106
  skip_rest if step.failed? && step.skip_rest_on_failure?
@@ -113,6 +123,10 @@ class Lopata::Scenario
113
123
  steps.select { |s| s.status == :not_runned && !s.teardown? }.each(&:skip!)
114
124
  end
115
125
 
126
+ def ignore_groups(groups)
127
+ steps.select { _1.status == :not_runned && _1.groups.take(groups.length) == groups }.each(&:ignored!)
128
+ end
129
+
116
130
  def metadata
117
131
  if current_step
118
132
  @metadata.merge(current_step.metadata)
data/lib/lopata/step.rb CHANGED
@@ -25,7 +25,7 @@ module Lopata
25
25
  def execution_steps(scenario, groups: [])
26
26
  return [] if condition && !condition.match?(scenario)
27
27
  return [] unless block
28
- [StepExecution.new(self, groups, &block)]
28
+ [StepExecution.new(self, groups, condition: condition, &block)]
29
29
  end
30
30
  end
31
31
 
@@ -39,13 +39,14 @@ module Lopata
39
39
  if step.is_a?(String)
40
40
  Lopata::SharedStep.find(step).steps.each do |shared_step|
41
41
  next if shared_step.condition && !shared_step.condition.match?(scenario)
42
- steps += shared_step.execution_steps(scenario, groups: groups)
42
+ shared_group = SharedGroupStep.new(:shared_step)
43
+ steps += shared_step.execution_steps(scenario, groups: groups + [shared_group])
43
44
  end
44
45
  elsif step.is_a?(Proc)
45
- steps << StepExecution.new(self, groups, &step)
46
+ steps << StepExecution.new(self, groups, condition: condition, &step)
46
47
  end
47
48
  end
48
- steps << StepExecution.new(self, groups, &block) if block
49
+ steps << StepExecution.new(self, groups, condition: condition, &block) if block
49
50
  steps.reject { |s| !s.block }
50
51
  end
51
52
 
@@ -103,20 +104,31 @@ module Lopata
103
104
  end
104
105
  end
105
106
 
107
+ # @private
108
+ # Fake group for shared step instance
109
+ # Used to build group hierarhy including chared steps
110
+ class SharedGroupStep < Step
111
+ # stub title - should not be used in scenario/step name generation.
112
+ def title
113
+ ''
114
+ end
115
+ end
116
+
106
117
  #@private
107
118
  class StepExecution
108
- attr_reader :step, :status, :exception, :block, :pending_message, :groups
119
+ attr_reader :step, :status, :exception, :block, :pending_message, :groups, :condition
109
120
  extend Forwardable
110
121
  def_delegators :step, :method_name
111
122
 
112
123
  class PendingStepFixedError < StandardError; end
113
124
 
114
- def initialize(step, groups, &block)
125
+ def initialize(step, groups, condition: nil, &block)
115
126
  @step = step
116
127
  @status = :not_runned
117
128
  @exception = nil
118
129
  @block = block
119
130
  @groups = groups
131
+ @condition = condition
120
132
  end
121
133
 
122
134
  def title
@@ -130,6 +142,10 @@ module Lopata
130
142
  def run(scenario)
131
143
  @status = :running
132
144
  begin
145
+ unless check_dynamic_condition?(scenario)
146
+ @status = :ignored
147
+ return
148
+ end
133
149
  run_step(scenario)
134
150
  if pending?
135
151
  @status = :failed
@@ -148,6 +164,22 @@ module Lopata
148
164
  scenario.instance_exec(&block)
149
165
  end
150
166
 
167
+ def check_dynamic_condition?(scenario)
168
+ dynamic_conditions.each do
169
+ return false unless _1.match_dynamic?(scenario)
170
+ end
171
+ true
172
+ end
173
+
174
+ def dynamic_conditions
175
+ conds = []
176
+ conds << condition if condition&.dynamic?
177
+ groups.each do
178
+ conds << _1.condition if _1.condition&.dynamic?
179
+ end
180
+ conds
181
+ end
182
+
151
183
  def failed?
152
184
  status == :failed
153
185
  end
@@ -160,6 +192,14 @@ module Lopata
160
192
  status == :skipped
161
193
  end
162
194
 
195
+ def ignored?
196
+ status == :ignored
197
+ end
198
+
199
+ def ignored!
200
+ status == :ignored
201
+ end
202
+
163
203
  def skip!
164
204
  @status = :skipped
165
205
  end
@@ -175,6 +215,7 @@ module Lopata
175
215
 
176
216
  # Need log this step.
177
217
  def loggable?
218
+ return false if ignored?
178
219
  not %i{ let let! }.include?(method_name)
179
220
  end
180
221
 
@@ -186,6 +227,10 @@ module Lopata
186
227
  teardown? && self.groups.last == group
187
228
  end
188
229
 
230
+ def in_group?(group)
231
+ groups.include?(group)
232
+ end
233
+
189
234
  def skip_rest_on_failure?
190
235
  %i{ setup action }.include?(method_name)
191
236
  end
@@ -1,6 +1,6 @@
1
1
  module Lopata
2
2
  # @private
3
3
  module Version
4
- STRING = '0.1.22'
4
+ STRING = '0.1.23'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lopata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Volochnev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-18 00:00:00.000000000 Z
11
+ date: 2023-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -139,5 +139,5 @@ requirements: []
139
139
  rubygems_version: 3.2.15
140
140
  signing_key:
141
141
  specification_version: 4
142
- summary: lopata-0.1.22
142
+ summary: lopata-0.1.23
143
143
  test_files: []