lopata 0.1.20 → 0.1.21

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: 7e55390905dd755e2f414e1164e0164ede72e4a11acd368ed6ff6971a7b69e34
4
- data.tar.gz: d4aa229e3bba5a2ac1875546b7ffe75b684a89ed4e1e08e1769f501a81989ce1
3
+ metadata.gz: c89f9dfc95a2a0586323e2fd682d971f619f8f47cba620c2846035af7a8d3736
4
+ data.tar.gz: ba2c2067b9cbce8691899cc5ba0a76c34295f54d1bb5bacea6234ac7b4756a46
5
5
  SHA512:
6
- metadata.gz: 7ea02b4920bc2534dc361aff03a6d277526f5aa53a51d15ba219e3ca6ee8877771b9fb185146172c67c9744afa18414baa6565e55ac5b213db00eb1fdf8884db
7
- data.tar.gz: 6c546d9eed8857a1e852e00b64d6a99c65b744862d914bc51fe8bdd14b81b2f7abe80f2c23217d38b83748068731f7eabaacc5ae2eb4b29354845904772e1177
6
+ metadata.gz: 0eada79585b1ca222a2ba29dacdecfb094cc32e50b21406e2e59e9326a8ad6f0463eff8f9772074d3f27bd2442a67efe233c3c08661ab3284b7b4cd71b069864
7
+ data.tar.gz: 1003113a61e1ec7093c7f6eab47e49ee87ab0ec7b267a593afe9c3b0625f095ce7ee024188837d7ec21e987e4437e7b26f42b8cdfc2370b6b813aacb9b2651b1
@@ -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.20'
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.20
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-04-14 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.20
141
+ summary: lopata-0.1.21
142
142
  test_files: []