r_spec 1.0.0.beta10 → 1.0.0.beta11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -11
  3. data/lib/r_spec.rb +40 -1
  4. data/lib/r_spec/dsl.rb +5 -2
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba07a04820e5602fb73f32e7b265ef6cc755a54c396a7c9419fc97c8125d2fb1
4
- data.tar.gz: 2330fe89b377b2f0cf13aaf6d325bf0b4f1c1fff5a409b8feba2f24f39e040a2
3
+ metadata.gz: 8c7957c4316cd89f58118ce544d50f3b5f401962648415b535c97da57ae4b7db
4
+ data.tar.gz: a1e8ec62ac5d695203917c85674a1d9b5dccbf1993c4fb55569fdd9d9401220b
5
5
  SHA512:
6
- metadata.gz: 76a062afb51273f181f86db0fd85eb342fe6404f832e6facba450607f32f6b8555057ffa9918379ae30a8a63548c0911378348318ddba64be5bf94a14ecad8c1
7
- data.tar.gz: 0d90f7fd0f0b94f40d28d4cb4c6dfcf82047830067881b0a8fef8108eb8cf4704b1542589023d91aed0f3814bbc10a5b7652269ac67ab7477a8a1c2231dc3383
6
+ metadata.gz: 51375c2f10d7cc11e71041c538940956e94721ae8f6e72af2bbb770d0b73041f6845b0100e9ebec2f7ec5d178fef388d5a5ece60e41076d7ff659d1d035afabd
7
+ data.tar.gz: 512ec78cc25d9ec8e0b5661c9a14b1fae3ae73714d8dc21e291721277ee6741035f5ccf130e190d661e8b19caf5d356d603a9951b40ad74b7fbdd20f7f9e6fec
data/README.md CHANGED
@@ -7,8 +7,9 @@ A minimalist __[RSpec](https://github.com/rspec/rspec) clone__ with all the esse
7
7
  ## Status
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/r_spec.svg)](https://badge.fury.io/rb/r_spec)
10
- [![CI](https://github.com/cyril/r_spec.rb/workflows/ci/badge.svg?branch=main)](https://github.com/cyril/r_spec.rb/actions?query=workflow%3Aci+branch%3Amain)
11
10
  [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)](https://rubydoc.info/gems/r_spec/frames)
11
+ [![CI](https://github.com/cyril/r_spec.rb/workflows/CI/badge.svg?branch=main)](https://github.com/cyril/r_spec.rb/actions?query=workflow%3Aci+branch%3Amain)
12
+ [![RuboCop](https://github.com/cyril/r_spec.rb/workflows/RuboCop/badge.svg?branch=main)](https://github.com/cyril/r_spec.rb/actions?query=workflow%3Arubocop+branch%3Amain)
12
13
 
13
14
  ## Project goals
14
15
 
@@ -29,6 +30,7 @@ A minimalist __[RSpec](https://github.com/rspec/rspec) clone__ with all the esse
29
30
  * The `let` method defines a helper method rather than a memoized helper method.
30
31
  * The one-liner `is_expected` syntax also works with block expectations.
31
32
  * `subject`, `before`, `after` and `let` definitions must come before examples.
33
+ * Each `context` runs its tests in _isolation_ to prevent side effects.
32
34
 
33
35
  ## Important ⚠️
34
36
 
@@ -47,7 +49,7 @@ Following [RubyGems naming conventions](https://guides.rubygems.org/name-your-ge
47
49
  Add this line to your application's Gemfile:
48
50
 
49
51
  ```ruby
50
- gem "r_spec", ">= 1.0.0.beta10"
52
+ gem "r_spec", ">= 1.0.0.beta11"
51
53
  ```
52
54
 
53
55
  And then execute:
@@ -101,7 +103,8 @@ For unit tests, it is recommended to follow the conventions for method names:
101
103
  * instance methods are prefixed with `#`, class methods with `.`.
102
104
 
103
105
  To establish certain contexts — think _empty array_ versus _array with elements_ — the `context` method may be used to communicate this to the reader.
104
- It has a different name, but behaves exactly like `describe`.
106
+ Its behavior is slightly different from `describe` because each `context` runs its tests in isolation,
107
+ so side effects caused by testing do not propagate out of contexts.
105
108
 
106
109
  `describe` and `context` take an optional description as argument and a block containing the individual specs or nested groupings.
107
110
 
@@ -220,12 +223,7 @@ task default: :test
220
223
 
221
224
  Benchmark against [100 executions of a file containing one expectation](https://github.com/cyril/r_spec.rb/blob/main/benchmark/) (lower is better).
222
225
 
223
- | Framework | Seconds to complete |
224
- |-------------|---------------------|
225
- | `r_spec` | 13.0 |
226
- | `rspec` | 32.2 |
227
- | `minitest` | 17.5 |
228
- | `test-unit` | 20.5 |
226
+ ![Runtime](https://r-spec.dev/benchmark-runtime.png)
229
227
 
230
228
  ## Test suite
231
229
 
@@ -233,8 +231,10 @@ __RSpec clone__'s specifications are self-described here: [spec/](https://github
233
231
 
234
232
  ## Contact
235
233
 
236
- * Home page: https://r-spec.dev
237
- * Source code: https://github.com/cyril/r_spec.rb
234
+ * Home page: [https://r-spec.dev/](https://r-spec.dev/)
235
+ * Cheatsheet: [https://r-spec.dev/cheatsheet.html](https://r-spec.dev/cheatsheet.html)
236
+ * Source code: [https://github.com/cyril/r_spec.rb](https://github.com/cyril/r_spec.rb)
237
+ * API Doc: [https://rubydoc.info/gems/r_spec](https://rubydoc.info/gems/r_spec)
238
238
  * Twitter: [https://twitter.com/cyri\_](https://twitter.com/cyri\_)
239
239
 
240
240
  ## Special thanks ❤️
data/lib/r_spec.rb CHANGED
@@ -65,7 +65,46 @@ require_relative File.join("r_spec", "dsl")
65
65
  #
66
66
  # @api public
67
67
  module RSpec
68
- # Specs are built with this method.
68
+ # Defines an example group that establishes a specific context, like _empty
69
+ # array_ versus _array with elements_.
70
+ #
71
+ # Unlike {.describe}, the block is evaluated in isolation in order to scope
72
+ # possible side effects inside its context.
73
+ #
74
+ # @example
75
+ # require "r_spec"
76
+ #
77
+ # RSpec.context "when divided by zero" do
78
+ # subject { 42 / 0 }
79
+ #
80
+ # it { is_expected.to raise_exception ZeroDivisionError }
81
+ # end
82
+ #
83
+ # # Output to the console
84
+ # # Success: divided by 0.
85
+ #
86
+ # @param description [String] A description that usually begins with "when",
87
+ # "with" or "without".
88
+ # @param block [Proc] The block to define the specs.
89
+ #
90
+ # @api public
91
+ def self.context(description, &block)
92
+ Dsl.context(description, &block)
93
+ end
94
+
95
+ # Defines an example group that describes a unit to be tested.
96
+ #
97
+ # @example
98
+ # require "r_spec"
99
+ #
100
+ # RSpec.describe String do
101
+ # describe "+" do
102
+ # it("concats") { expect("foo" + "bar").to eq "foobar" }
103
+ # end
104
+ # end
105
+ #
106
+ # # Output to the console
107
+ # # Success: expected to eq "foobar".
69
108
  #
70
109
  # @param const [Module, String] A module to include in block context.
71
110
  # @param block [Proc] The block to define the specs.
data/lib/r_spec/dsl.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "aw"
4
+
3
5
  require_relative "console"
4
6
  require_relative "error"
5
7
  require_relative "expectation_helper"
@@ -155,7 +157,8 @@ module RSpec
155
157
  # Defines an example group that establishes a specific context, like _empty
156
158
  # array_ versus _array with elements_.
157
159
  #
158
- # It is functionally equivalent to {.describe}.
160
+ # Unlike {.describe}, the block is evaluated in isolation in order to scope
161
+ # possible side effects inside its context.
159
162
  #
160
163
  # @example
161
164
  # require "r_spec"
@@ -179,7 +182,7 @@ module RSpec
179
182
  # @param block [Proc] The block to define the specs.
180
183
  def self.context(_description = nil, &block)
181
184
  desc = ::Class.new(self)
182
- desc.instance_eval(&block)
185
+ ::Aw.fork! { desc.instance_eval(&block) }
183
186
  end
184
187
 
185
188
  # Defines a concrete test case.
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta10
4
+ version: 1.0.0.beta11
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-21 00:00:00.000000000 Z
11
+ date: 2021-06-23 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
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: expresenter
15
29
  requirement: !ruby/object:Gem::Requirement