lopata 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a8a4ad14daa538fff802214154447f18870218fc11ab868329b49ceb83dc92f
4
- data.tar.gz: 45699cd6159403c5e8179d5bdd55ebfef468e9f35484c2aebd19a9de6c38fe11
3
+ metadata.gz: c89f9dfc95a2a0586323e2fd682d971f619f8f47cba620c2846035af7a8d3736
4
+ data.tar.gz: ba2c2067b9cbce8691899cc5ba0a76c34295f54d1bb5bacea6234ac7b4756a46
5
5
  SHA512:
6
- metadata.gz: 3dd9b7b141261b79dfc3d1218f97344fbbc9dddd3149872d08a1b759fd58ffaf2671e69604ad7ce278fb8df1134544dbdec803ef6f718f8bb6238b2e058ba3bb
7
- data.tar.gz: '095b74c08cecece6997171bb1dba20d004d790adc5f32ca3d433853623146e8d94f60467d47a691a173241b6601c81b33b5245f621db706c7c3aef404c4c8884'
6
+ metadata.gz: 0eada79585b1ca222a2ba29dacdecfb094cc32e50b21406e2e59e9326a8ad6f0463eff8f9772074d3f27bd2442a67efe233c3c08661ab3284b7b4cd71b069864
7
+ data.tar.gz: 1003113a61e1ec7093c7f6eab47e49ee87ab0ec7b267a593afe9c3b0625f095ce7ee024188837d7ec21e987e4437e7b26f42b8cdfc2370b6b813aacb9b2651b1
@@ -52,6 +52,10 @@ module Lopata
52
52
  request = { status: status, steps: steps, launch: { id: @launch_id, finished: finished } }
53
53
  test = test_id(scenario)
54
54
  post("/tests/#{test}/attempts.json", body: request)
55
+ rescue SocketError => e
56
+ # Ignore network problems. Continue with next scenario when cannot log results.
57
+ puts e.message
58
+ puts e.backtrace
55
59
  end
56
60
 
57
61
  def step_hash(step)
@@ -46,7 +46,7 @@ class Lopata::Scenario
46
46
  # @private
47
47
  def method_missing(method, *args, &block)
48
48
  if execution.let_methods.include?(method)
49
- instance_exec(*args, &execution.let_methods[method])
49
+ execution.let_methods[method].call_in_scenario(self, *args)
50
50
  elsif metadata.keys.include?(method)
51
51
  metadata[method]
52
52
  else
@@ -129,17 +129,23 @@ class Lopata::Scenario
129
129
  end
130
130
  end
131
131
 
132
+ def let_base
133
+ if current_step && !current_step.groups.empty?
134
+ current_step.groups.last.let_methods
135
+ else
136
+ @let_methods
137
+ end
138
+ end
139
+
132
140
  def let(method_name, &block)
133
- # define_singleton_method method_name, &block
134
- base =
135
- if current_step && !current_step.groups.empty?
136
- current_step.groups.last.let_methods
137
- else
138
- @let_methods
139
- end
140
- base[method_name] = block
141
+ let_base[method_name] = LetMethod.new(&block)
142
+ end
143
+
144
+ def let!(method_name, &block)
145
+ let_base[method_name] = LetBangMethod.new(&block)
141
146
  end
142
147
 
148
+
143
149
  def cleanup
144
150
  @title = nil
145
151
  @metadata = nil
@@ -147,4 +153,42 @@ class Lopata::Scenario
147
153
  @scenario = nil
148
154
  end
149
155
  end
156
+
157
+ # @private
158
+ # let! methods incapsulate cached value and calculation block
159
+ class LetBangMethod
160
+ attr_reader :block, :calculated, :value
161
+
162
+ alias calculated? calculated
163
+
164
+ def initialize(&block)
165
+ @block = block
166
+ @calculated = false
167
+ @value = nil
168
+ end
169
+
170
+ def call_in_scenario(scenario, *args)
171
+ if calculated?
172
+ value
173
+ else
174
+ @value = scenario.instance_exec(&block)
175
+ @calculated = true
176
+ @value
177
+ end
178
+ end
179
+ end
180
+
181
+ # @private
182
+ # let methods calculates
183
+ class LetMethod
184
+ attr_reader :block
185
+
186
+ def initialize(&block)
187
+ @block = block
188
+ end
189
+
190
+ def call_in_scenario(scenario, *args)
191
+ scenario.instance_exec(*args, &block)
192
+ end
193
+ end
150
194
  end
@@ -277,6 +277,24 @@ class Lopata::ScenarioBuilder
277
277
  end
278
278
  end
279
279
 
280
+ # Define memorized runtime method for the scenario.
281
+ #
282
+ # @note
283
+ # The method to be called via #method_missing, so it wont override already defined methods.
284
+ #
285
+ # @example
286
+ # let!(:started) { Time.now }
287
+ # it 'started early' do
288
+ # first_started = started
289
+ # expect(started).to eq first_started
290
+ # end
291
+ def let!(method_name, &block)
292
+ steps << Lopata::Step.new(:let) do
293
+ execution.let!(method_name, &block)
294
+ end
295
+ end
296
+
297
+
280
298
  # @!endgroup
281
299
 
282
300
  # @private
data/lib/lopata/step.rb CHANGED
@@ -88,6 +88,10 @@ module Lopata
88
88
  @let_methods ||= {}
89
89
  end
90
90
 
91
+ def let_bang_methods
92
+ @let_bang_methods ||= {}
93
+ end
94
+
91
95
  private
92
96
 
93
97
  # Group step's block is a block in context of builder, not scenario. So hide the @block to not be used in scenario.
@@ -187,5 +191,10 @@ module Lopata
187
191
  def let_methods
188
192
  (groups).compact.inject({}) { |merged, part| merged.merge(part.let_methods) }
189
193
  end
194
+
195
+ # Step bang methods is a combination of let_bang_methods for all contexts (group) the step included
196
+ def let_bang_methods
197
+ (groups).compact.inject({}) { |merged, part| merged.merge(part.let_bang_methods) }
198
+ end
190
199
  end
191
200
  end
@@ -1,6 +1,6 @@
1
1
  module Lopata
2
2
  # @private
3
3
  module Version
4
- STRING = '0.1.19'
4
+ STRING = '0.1.21'
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.19
4
+ version: 0.1.21
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-01-24 00:00:00.000000000 Z
11
+ date: 2023-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -138,5 +138,5 @@ requirements: []
138
138
  rubygems_version: 3.2.15
139
139
  signing_key:
140
140
  specification_version: 4
141
- summary: lopata-0.1.19
141
+ summary: lopata-0.1.21
142
142
  test_files: []