r_spec-clone 1.0.2 → 1.1.0

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: 3cbbbb0e875f54ccff6794dfc52606e5d712f82a8e270e2d325cbaf59a62910e
4
- data.tar.gz: 33a3f94a742cad452bf55ce4a9968f9f46b5af98e9db0bc63c9fe25860e730a5
3
+ metadata.gz: 6d314d17896138ce2ff2b6d7eb389a1ba2316690f40923684c68632227692a5f
4
+ data.tar.gz: af8efe2d9ab1b773db062263503221dd56b6b7a604e73d5f1a84baf0ccbf2b35
5
5
  SHA512:
6
- metadata.gz: 89fea25a7d8bc02a3abbc31000d2b5690168d8e711513913b41b0df7692e1bebd3eececfb630f7ee710d940cb9a40588b48e5ac852457fc7ef5c93786795c1ec
7
- data.tar.gz: b37a7a661bde709da6cb1c218329c1eef418e4ef1ea6777d649687da348a014aeae65706d202accb8d850a9fb73a55dcd8241854ded13d82288db837553e9006
6
+ metadata.gz: a57d31c77a3da5d120651efbbc1f6d28f808fa47d9c7184e04f79723273df0ce6d84ba08628bc2f60c98c7756a0f2cf1d46774f42d1c505ca9f4e522f418e404
7
+ data.tar.gz: 2b2cb13a1620fd98107b3f82e8d7427ae11eb054e9e4bd8c36fe21402efc9dc38af0f6aa41850dc65c05eeba9cfc918a23dfcdea743658963459ef9e5b35c689
data/README.md CHANGED
@@ -7,7 +7,7 @@ A minimalist __RSpec clone__ with all the essentials.
7
7
  ## Status
8
8
 
9
9
  [![Version](https://img.shields.io/github/v/tag/cyril/r_spec-clone.rb?label=Version&logo=github)](https://github.com/cyril/r_spec-clone.rb/releases)
10
- [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?)](https://rubydoc.info/github/cyril/r_spec-clone.rb/main)
10
+ [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/cyril/r_spec-clone.rb/main)
11
11
  [![CI](https://github.com/cyril/r_spec-clone.rb/workflows/CI/badge.svg?branch=main)](https://github.com/cyril/r_spec-clone.rb/actions?query=workflow%3Aci+branch%3Amain)
12
12
  [![RuboCop](https://github.com/cyril/r_spec-clone.rb/workflows/RuboCop/badge.svg?branch=main)](https://github.com/cyril/r_spec-clone.rb/actions?query=workflow%3Arubocop+branch%3Amain)
13
13
  [![License](https://img.shields.io/github/license/cyril/r_spec-clone.rb?label=License&logo=github)](https://github.com/cyril/r_spec-clone.rb/raw/main/LICENSE.md)
@@ -32,14 +32,14 @@ A minimalist __RSpec clone__ with all the essentials.
32
32
  * The `let` method defines a helper method rather than a memoized helper method.
33
33
  * The one-liner `is_expected` syntax also works with block expectations.
34
34
  * `subject`, `before`, `after` and `let` definitions must come before examples.
35
- * Each [`context` runs its tests in _isolation_](https://asciinema.org/a/29070?autoplay=1&speed=2) to prevent side effects.
35
+ * Groups and examples are _executed in subprocesses_ the order they are defined.
36
36
 
37
37
  ## Installation
38
38
 
39
39
  Add this line to your application's Gemfile:
40
40
 
41
41
  ```ruby
42
- gem "r_spec-clone", ">= 1.0.2"
42
+ gem "r_spec-clone"
43
43
  ```
44
44
 
45
45
  And then execute:
@@ -93,8 +93,6 @@ For unit tests, it is recommended to follow the conventions for method names:
93
93
  * instance methods are prefixed with `#`, class methods with `.`.
94
94
 
95
95
  To establish certain contexts — think _empty array_ versus _array with elements_ — the `context` method may be used to communicate this to the reader.
96
- Its behavior is slightly different from `describe` because each `context` runs its tests in isolation,
97
- so side effects caused by testing do not propagate out of contexts.
98
96
 
99
97
  ### Expectations
100
98
 
@@ -211,11 +209,11 @@ bundle exec rake
211
209
 
212
210
  ## Performance
213
211
 
214
- ### Runtime
212
+ ### Boot time
215
213
 
216
214
  Benchmark against [100 executions of a file containing one expectation](https://github.com/cyril/r_spec-clone.rb/blob/main/benchmark/) (lower is better).
217
215
 
218
- ![Runtime](https://clone.r-spec.dev/benchmark-runtime.png)
216
+ ![Runtime](https://r-spec.dev/benchmark-boot-time.svg)
219
217
 
220
218
  ## Test suite
221
219
 
@@ -224,7 +222,7 @@ __RSpec clone__'s specifications are self-described here: [spec/](https://github
224
222
  ## Contact
225
223
 
226
224
  * Home page: [https://r-spec.dev/](https://r-spec.dev/)
227
- * Cheatsheet: [https://clone.r-spec.dev/cheatsheet.html](https://clone.r-spec.dev/cheatsheet.html)
225
+ * Cheatsheet: [https://r-spec.dev/cheatsheet.html](https://r-spec.dev/cheatsheet.html)
228
226
  * Source code: [https://github.com/cyril/r_spec-clone.rb](https://github.com/cyril/r_spec-clone.rb)
229
227
  * API Doc: [https://rubydoc.info/gems/r_spec-clone](https://rubydoc.info/gems/r_spec-clone)
230
228
  * Twitter: [https://twitter.com/cyri\_](https://twitter.com/cyri\_)
data/lib/r_spec.rb CHANGED
@@ -68,9 +68,6 @@ module RSpec
68
68
  # Defines an example group that establishes a specific context, like _empty
69
69
  # array_ versus _array with elements_.
70
70
  #
71
- # Unlike {.describe}, the block is evaluated in isolation in order to scope
72
- # possible side effects inside its context.
73
- #
74
71
  # @example
75
72
  # require "r_spec/clone"
76
73
  #
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "aw"
4
-
5
3
  require_relative "console"
6
4
  require_relative "error"
7
5
  require_relative "expectation_helper"
@@ -152,14 +150,11 @@ module RSpec
152
150
  def self.describe(const, &block)
153
151
  desc = ::Class.new(self)
154
152
  desc.let(:described_class) { const } if const.is_a?(::Module)
155
- desc.instance_eval(&block)
153
+ fork! { desc.instance_eval(&block) }
156
154
  end
157
155
 
158
- # Defines an example group that establishes a specific context, like _empty
159
- # array_ versus _array with elements_.
160
- #
161
- # Unlike {.describe}, the block is evaluated in isolation in order to scope
162
- # possible side effects inside its context.
156
+ # Defines an example group that establishes a specific context, like
157
+ # _empty array_ versus _array with elements_.
163
158
  #
164
159
  # @example
165
160
  # require "r_spec/clone"
@@ -183,7 +178,7 @@ module RSpec
183
178
  # @param block [Proc] The block to define the specs.
184
179
  def self.context(_description, &block)
185
180
  desc = ::Class.new(self)
186
- ::Aw.fork! { desc.instance_eval(&block) }
181
+ fork! { desc.instance_eval(&block) }
187
182
  end
188
183
 
189
184
  # Defines a concrete test case.
@@ -225,16 +220,8 @@ module RSpec
225
220
  # @raise (see ExpectationTarget::Base#result)
226
221
  # @return (see ExpectationTarget::Base#result)
227
222
  def self.it(_name = nil, &block)
228
- raise ::ArgumentError, "Missing example block" unless block
229
-
230
223
  example = ::Class.new(self) { include ExpectationHelper::It }.new
231
- example.instance_eval(&block)
232
- rescue ::SystemExit
233
- Console.source(*block.source_location)
234
-
235
- exit false
236
- ensure
237
- example&.send(AFTER_METHOD)
224
+ fork! { run(example, &block) }
238
225
  end
239
226
 
240
227
  # Use the {.its} method to define a single spec that specifies the actual
@@ -283,8 +270,6 @@ module RSpec
283
270
  # @raise (see ExpectationTarget::Base#result)
284
271
  # @return (see ExpectationTarget::Base#result)
285
272
  def self.its(attribute, *args, **kwargs, &block)
286
- raise ::ArgumentError, "Missing example block" unless block
287
-
288
273
  example = ::Class.new(self) do
289
274
  include ExpectationHelper::Its
290
275
 
@@ -293,19 +278,13 @@ module RSpec
293
278
  end
294
279
  end.new
295
280
 
296
- example.instance_eval(&block)
297
- rescue ::SystemExit
298
- Console.source(*block.source_location)
299
-
300
- exit false
301
- ensure
302
- example&.send(AFTER_METHOD)
281
+ fork! { run(example, &block) }
303
282
  end
304
283
 
305
284
  # Defines a pending test case.
306
285
  #
307
- # `&block` is never evaluated. It can be used to describe behaviour that is
308
- # not yet implemented.
286
+ # `&block` is never evaluated. It can be used to describe behaviour that
287
+ # is not yet implemented.
309
288
  #
310
289
  # @example
311
290
  # require "r_spec/clone"
@@ -331,6 +310,27 @@ module RSpec
331
310
  Console.passed_spec Error::PendingExpectation.result(message)
332
311
  end
333
312
 
313
+ # Creates a subprocess and runs the block inside.
314
+ def self.fork!(&block)
315
+ pid = fork(&block)
316
+ thread = ::Process.detach(pid)
317
+ exitstatus = thread.join.value.exitstatus
318
+ exit false unless exitstatus.zero?
319
+ end
320
+
321
+ # Execution of specifications.
322
+ def self.run(example, &block)
323
+ example.instance_eval(&block)
324
+ rescue ::SystemExit
325
+ Console.source(*block.source_location)
326
+
327
+ exit false
328
+ ensure
329
+ example&.send(AFTER_METHOD)
330
+ end
331
+
332
+ private_class_method :fork!, :run
333
+
334
334
  private
335
335
 
336
336
  def described_class
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_spec-clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-27 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: aw
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.1.12
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.1.12
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: expresenter
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -217,7 +203,7 @@ files:
217
203
  - lib/r_spec/clone/expectation_target/base.rb
218
204
  - lib/r_spec/clone/expectation_target/block.rb
219
205
  - lib/r_spec/clone/expectation_target/value.rb
220
- homepage: https://clone.r-spec.dev/
206
+ homepage: https://r-spec.dev/
221
207
  licenses:
222
208
  - MIT
223
209
  metadata: