r_spec-clone 1.2.4 → 1.3.0
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 +4 -4
- data/README.md +23 -2
- data/lib/r_spec.rb +2 -2
- data/lib/r_spec/clone/error/pending_expectation.rb +7 -7
- data/lib/r_spec/clone/expectation_helper/shared.rb +184 -65
- data/lib/r_spec/clone/expectation_target/base.rb +7 -7
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8475d853643279af5a0a255bf7b3fd5b4547f4dd596bc044fa37a5ac2d69ff0
|
4
|
+
data.tar.gz: 3d22158ee01cb6f0e4924bd57345225e35d40920b2bffaf0cf862575db4b62ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f6826b996db0d6b3f727a7bc16b7757f7fc1ae350ca2285cf81aaf4ce8bfb15f0c37a8910bb2413800821524109cd6c655275aa2b800f52ba25aba1c31c9ac7
|
7
|
+
data.tar.gz: 53b85ef4eb8b249cdf2f717de35a6c29916c65d28a125e28656e300a5bfb7263d62865fba6d53a2517ae035cf64daa0c2b7b04a82ecaca93903502b0f5c2a59d
|
data/README.md
CHANGED
@@ -149,13 +149,13 @@ expect(actual).to match(expected) # passes if expected.match?(actual)
|
|
149
149
|
expect { actual }.to raise_exception(expected) # passes if expected exception is raised
|
150
150
|
```
|
151
151
|
|
152
|
-
####
|
152
|
+
#### True
|
153
153
|
|
154
154
|
```ruby
|
155
155
|
expect(actual).to be_true # passes if true.equal?(actual)
|
156
156
|
```
|
157
157
|
|
158
|
-
####
|
158
|
+
#### False
|
159
159
|
|
160
160
|
```ruby
|
161
161
|
expect(actual).to be_false # passes if false.equal?(actual)
|
@@ -174,6 +174,21 @@ expect(actual).to be_instance_of(expected) # passes if expected.equal?(actual
|
|
174
174
|
expect(actual).to be_an_instance_of(expected) # passes if expected.equal?(actual.class)
|
175
175
|
```
|
176
176
|
|
177
|
+
#### Change
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
expect { object.action }.to change(object, :value).from(old).to(new)
|
181
|
+
expect { object.action }.to change(object, :value).by(delta)
|
182
|
+
expect { object.action }.to change(object, :value).by_at_least(minimum_delta)
|
183
|
+
expect { object.action }.to change(object, :value).by_at_most(maximum_delta)
|
184
|
+
```
|
185
|
+
|
186
|
+
#### Satisfy
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
expect(actual).to(satisfy { |value| value == expected })
|
190
|
+
```
|
191
|
+
|
177
192
|
### Running specs
|
178
193
|
|
179
194
|
By convention, specs live in the `spec/` directory of a project. Spec files should end with `_spec.rb` to be recognizable as such.
|
@@ -234,6 +249,12 @@ bundle exec rake
|
|
234
249
|
|
235
250
|
## Performance
|
236
251
|
|
252
|
+
The benchmarks compare the performance of [`r_spec-clone`](https://rubygems.org/gems/r_spec-clone) with the following frameworks (in alphabetical order):
|
253
|
+
|
254
|
+
* [`fix`](https://rubygems.org/gems/fix)
|
255
|
+
* [`minitest`](https://rubygems.org/gems/minitest)
|
256
|
+
* [`rspec`](https://rubygems.org/gems/rspec)
|
257
|
+
|
237
258
|
### Boot time
|
238
259
|
|
239
260
|
Benchmark against [100 executions of a file containing 1 expectation](https://github.com/cyril/r_spec-clone.rb/blob/main/benchmark/boot_time/) (lower is better).
|
data/lib/r_spec.rb
CHANGED
@@ -37,8 +37,8 @@ require_relative File.join("r_spec", "clone", "dsl")
|
|
37
37
|
#
|
38
38
|
# # Output to the console
|
39
39
|
# # Success: expected to eq 3.
|
40
|
-
# # Success: expected
|
41
|
-
# # Success: expected
|
40
|
+
# # Success: expected to be true.
|
41
|
+
# # Success: expected to be false.
|
42
42
|
#
|
43
43
|
# @example An inherited definition of let
|
44
44
|
# require "r_spec"
|
@@ -12,13 +12,13 @@ module RSpec
|
|
12
12
|
# @return [nil] Write a pending expectation to STDOUT.
|
13
13
|
def self.result(message)
|
14
14
|
::Expresenter.call(true).with(
|
15
|
-
actual:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
negate:
|
21
|
-
level:
|
15
|
+
actual: new(message),
|
16
|
+
definition: "raise exception #{self}",
|
17
|
+
error: nil,
|
18
|
+
expected: self,
|
19
|
+
got: false,
|
20
|
+
negate: true,
|
21
|
+
level: :SHOULD
|
22
22
|
)
|
23
23
|
end
|
24
24
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "matchi
|
4
|
-
require "matchi/helper"
|
3
|
+
require "matchi"
|
5
4
|
|
6
5
|
module RSpec
|
7
6
|
module Clone
|
@@ -11,72 +10,192 @@ module RSpec
|
|
11
10
|
# This module defines a number of methods to create expectations, which
|
12
11
|
# are automatically included into examples.
|
13
12
|
#
|
14
|
-
# It also includes a collection of expectation matchers
|
15
|
-
#
|
16
|
-
# @example Equivalence matcher
|
17
|
-
# matcher = eql("foo") # => Matchi::Matcher::Eql.new("foo")
|
18
|
-
# matcher.matches? { "foo" } # => true
|
19
|
-
# matcher.matches? { "bar" } # => false
|
20
|
-
#
|
21
|
-
# matcher = eq("foo") # => Matchi::Matcher::Eq.new("foo")
|
22
|
-
# matcher.matches? { "foo" } # => true
|
23
|
-
# matcher.matches? { "bar" } # => false
|
24
|
-
#
|
25
|
-
# @example Identity matcher
|
26
|
-
# object = "foo"
|
27
|
-
#
|
28
|
-
# matcher = equal(object) # => Matchi::Matcher::Equal.new(object)
|
29
|
-
# matcher.matches? { object } # => true
|
30
|
-
# matcher.matches? { "foo" } # => false
|
31
|
-
#
|
32
|
-
# matcher = be(object) # => Matchi::Matcher::Be.new(object)
|
33
|
-
# matcher.matches? { object } # => true
|
34
|
-
# matcher.matches? { "foo" } # => false
|
35
|
-
#
|
36
|
-
# @example Regular expressions matcher
|
37
|
-
# matcher = match(/^foo$/) # => Matchi::Matcher::Match.new(/^foo$/)
|
38
|
-
# matcher.matches? { "foo" } # => true
|
39
|
-
# matcher.matches? { "bar" } # => false
|
40
|
-
#
|
41
|
-
# @example Expecting errors matcher
|
42
|
-
# matcher = raise_exception(NameError) # => Matchi::Matcher::RaiseException.new(NameError)
|
43
|
-
# matcher.matches? { Boom } # => true
|
44
|
-
# matcher.matches? { true } # => false
|
45
|
-
#
|
46
|
-
# @example Truth matcher
|
47
|
-
# matcher = be_true # => Matchi::Matcher::BeTrue.new
|
48
|
-
# matcher.matches? { true } # => true
|
49
|
-
# matcher.matches? { false } # => false
|
50
|
-
# matcher.matches? { nil } # => false
|
51
|
-
# matcher.matches? { 4 } # => false
|
52
|
-
#
|
53
|
-
# @example Untruth matcher
|
54
|
-
# matcher = be_false # => Matchi::Matcher::BeFalse.new
|
55
|
-
# matcher.matches? { false } # => true
|
56
|
-
# matcher.matches? { true } # => false
|
57
|
-
# matcher.matches? { nil } # => false
|
58
|
-
# matcher.matches? { 4 } # => false
|
59
|
-
#
|
60
|
-
# @example Nil matcher
|
61
|
-
# matcher = be_nil # => Matchi::Matcher::BeNil.new
|
62
|
-
# matcher.matches? { nil } # => true
|
63
|
-
# matcher.matches? { false } # => false
|
64
|
-
# matcher.matches? { true } # => false
|
65
|
-
# matcher.matches? { 4 } # => false
|
66
|
-
#
|
67
|
-
# @example Type/class matcher
|
68
|
-
# matcher = be_instance_of(String) # => Matchi::Matcher::BeInstanceOf.new(String)
|
69
|
-
# matcher.matches? { "foo" } # => true
|
70
|
-
# matcher.matches? { 4 } # => false
|
71
|
-
#
|
72
|
-
# matcher = be_an_instance_of(String) # => Matchi::Matcher::BeAnInstanceOf.new(String)
|
73
|
-
# matcher.matches? { "foo" } # => true
|
74
|
-
# matcher.matches? { 4 } # => false
|
13
|
+
# It also includes a collection of expectation matchers.
|
75
14
|
#
|
76
15
|
# @see https://github.com/fixrb/matchi
|
77
|
-
# @see https://github.com/fixrb/matchi-rspec
|
78
16
|
module Shared
|
79
|
-
|
17
|
+
# Equivalence matcher
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# matcher = eq("foo")
|
21
|
+
# matcher.matches? { "foo" } # => true
|
22
|
+
# matcher.matches? { "bar" } # => false
|
23
|
+
#
|
24
|
+
# @param expected [#eql?] An expected equivalent object.
|
25
|
+
#
|
26
|
+
# @return [#matches?] An equivalence matcher.
|
27
|
+
#
|
28
|
+
# @api public
|
29
|
+
def eq(expected)
|
30
|
+
::Matchi::Eq.new(expected)
|
31
|
+
end
|
32
|
+
|
33
|
+
alias eql eq
|
34
|
+
|
35
|
+
# Identity matcher
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# object = "foo"
|
39
|
+
# matcher = be(object)
|
40
|
+
# matcher.matches? { object } # => true
|
41
|
+
# matcher.matches? { "foo" } # => false
|
42
|
+
#
|
43
|
+
# @param expected [#equal?] The expected identical object.
|
44
|
+
#
|
45
|
+
# @return [#matches?] An identity matcher.
|
46
|
+
#
|
47
|
+
# @api public
|
48
|
+
def be(expected)
|
49
|
+
::Matchi::Be.new(expected)
|
50
|
+
end
|
51
|
+
|
52
|
+
alias equal be
|
53
|
+
|
54
|
+
# Regular expressions matcher
|
55
|
+
#
|
56
|
+
# @example
|
57
|
+
# matcher = match(/^foo$/)
|
58
|
+
# matcher.matches? { "foo" } # => true
|
59
|
+
# matcher.matches? { "bar" } # => false
|
60
|
+
#
|
61
|
+
# @param expected [#match] A regular expression.
|
62
|
+
#
|
63
|
+
# @return [#matches?] A regular expression matcher.
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
def match(expected)
|
67
|
+
::Matchi::Match.new(expected)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Expecting errors matcher
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# matcher = raise_exception(NameError)
|
74
|
+
# matcher.matches? { Boom } # => true
|
75
|
+
# matcher.matches? { true } # => false
|
76
|
+
#
|
77
|
+
# @param expected [Exception, #to_s] The expected exception name.
|
78
|
+
#
|
79
|
+
# @return [#matches?] An error matcher.
|
80
|
+
#
|
81
|
+
# @api public
|
82
|
+
def raise_exception(expected)
|
83
|
+
::Matchi::RaiseException.new(expected)
|
84
|
+
end
|
85
|
+
|
86
|
+
# True matcher
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
# matcher = be_true
|
90
|
+
# matcher.matches? { true } # => true
|
91
|
+
# matcher.matches? { false } # => false
|
92
|
+
# matcher.matches? { nil } # => false
|
93
|
+
# matcher.matches? { 4 } # => false
|
94
|
+
#
|
95
|
+
# @return [#matches?] A `true` matcher.
|
96
|
+
#
|
97
|
+
# @api public
|
98
|
+
def be_true
|
99
|
+
be(true)
|
100
|
+
end
|
101
|
+
|
102
|
+
# False matcher
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# matcher = be_false
|
106
|
+
# matcher.matches? { false } # => true
|
107
|
+
# matcher.matches? { true } # => false
|
108
|
+
# matcher.matches? { nil } # => false
|
109
|
+
# matcher.matches? { 4 } # => false
|
110
|
+
#
|
111
|
+
# @return [#matches?] A `false` matcher.
|
112
|
+
#
|
113
|
+
# @api public
|
114
|
+
def be_false
|
115
|
+
be(false)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Nil matcher
|
119
|
+
#
|
120
|
+
# @example
|
121
|
+
# matcher = be_nil
|
122
|
+
# matcher.matches? { nil } # => true
|
123
|
+
# matcher.matches? { false } # => false
|
124
|
+
# matcher.matches? { true } # => false
|
125
|
+
# matcher.matches? { 4 } # => false
|
126
|
+
#
|
127
|
+
# @return [#matches?] A `nil` matcher.
|
128
|
+
#
|
129
|
+
# @api public
|
130
|
+
def be_nil
|
131
|
+
be(nil)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Type/class matcher
|
135
|
+
#
|
136
|
+
# @example
|
137
|
+
# matcher = be_an_instance_of(String)
|
138
|
+
# matcher.matches? { "foo" } # => true
|
139
|
+
# matcher.matches? { 4 } # => false
|
140
|
+
#
|
141
|
+
# @param expected [Class, #to_s] The expected class name.
|
142
|
+
#
|
143
|
+
# @return [#matches?] A type/class matcher.
|
144
|
+
#
|
145
|
+
# @api public
|
146
|
+
def be_an_instance_of(expected)
|
147
|
+
::Matchi::BeAnInstanceOf.new(expected)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Change matcher
|
151
|
+
#
|
152
|
+
# @example
|
153
|
+
# object = []
|
154
|
+
# matcher = change(object, :length).by(1)
|
155
|
+
# matcher.matches? { object << 1 } # => true
|
156
|
+
#
|
157
|
+
# object = []
|
158
|
+
# matcher = change(object, :length).by_at_least(1)
|
159
|
+
# matcher.matches? { object << 1 } # => true
|
160
|
+
#
|
161
|
+
# object = []
|
162
|
+
# matcher = change(object, :length).by_at_most(1)
|
163
|
+
# matcher.matches? { object << 1 } # => true
|
164
|
+
#
|
165
|
+
# object = "foo"
|
166
|
+
# matcher = change(object, :to_s).from("foo").to("FOO")
|
167
|
+
# matcher.matches? { object.upcase! } # => true
|
168
|
+
#
|
169
|
+
# object = "foo"
|
170
|
+
# matcher = change(object, :to_s).to("FOO")
|
171
|
+
# matcher.matches? { object.upcase! } # => true
|
172
|
+
#
|
173
|
+
# @param object [#object_id] An object.
|
174
|
+
# @param method [Symbol] The name of a method.
|
175
|
+
# @param args [Array] A list of arguments.
|
176
|
+
# @param kwargs [Hash] A list of keyword arguments.
|
177
|
+
#
|
178
|
+
# @return [#matches?] A change matcher.
|
179
|
+
#
|
180
|
+
# @api public
|
181
|
+
def change(object, method, *args, **kwargs, &block)
|
182
|
+
::Matchi::Change.new(object, method, *args, **kwargs, &block)
|
183
|
+
end
|
184
|
+
|
185
|
+
# Satisfy matcher
|
186
|
+
#
|
187
|
+
# @example
|
188
|
+
# matcher = satisfy { |value| value == 42 }
|
189
|
+
# matcher.matches? { 42 } # => true
|
190
|
+
#
|
191
|
+
# @param expected [Proc] A block of code.
|
192
|
+
#
|
193
|
+
# @return [#matches?] A satisfy matcher.
|
194
|
+
#
|
195
|
+
# @api public
|
196
|
+
def satisfy(&expected)
|
197
|
+
::Matchi::Satisfy.new(&expected)
|
198
|
+
end
|
80
199
|
end
|
81
200
|
end
|
82
201
|
end
|
@@ -95,13 +95,13 @@ module RSpec
|
|
95
95
|
# `Kernel.exit(false)` with a failure message written to STDERR.
|
96
96
|
def result(passed, actual:, error:, got:, matcher:, negate:)
|
97
97
|
Console.passed_spec ::Expresenter.call(passed).with(
|
98
|
-
actual:
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
level:
|
98
|
+
actual: actual,
|
99
|
+
definition: matcher.to_s,
|
100
|
+
error: error,
|
101
|
+
expected: matcher.expected,
|
102
|
+
got: got,
|
103
|
+
negate: negate,
|
104
|
+
level: :MUST
|
105
105
|
)
|
106
106
|
rescue ::Expresenter::Fail => e
|
107
107
|
Console.failed_spec(e)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r_spec-clone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.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-07-
|
11
|
+
date: 2021-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: expresenter
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: matchi
|
28
|
+
name: matchi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 3.1.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 3.1.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test_tube
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|