r_spec 1.0.0.beta4 → 1.0.0.beta5

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: 0d94ad6d7ba01dc04c4bcbe727543524f6a3d83cf69549a34453c1eefc5282e9
4
- data.tar.gz: 61b3ebe1299e69d7ef1f2c180325e85e1bda05e2347176ae507fc7430cf311ca
3
+ metadata.gz: 5df8b9cdb685bc7388fdbdbc0a7de755a3c5c2426e5c6f8346c464562ed16e30
4
+ data.tar.gz: 9b22d8599741dd00b0a812931cbf4c575acf948b0e4914dd662decc23fd8eea6
5
5
  SHA512:
6
- metadata.gz: 5d44ce99f58c17711be4b3f76cdfaf3c9923d031aa9a7d214db50b990825673b9bb485ce095195594fbeb45977763dc5a0be31770f089cd17dcb1e3ef1d6885b
7
- data.tar.gz: ca64a27f7cf4032b6b073b9fc2eb05aa37654c02a58289c41094e9afa000deccc3886d03d2043642a02e38cf10b6cc0fbd775e7ef9bc1c29cb592b813dcf5d04
6
+ metadata.gz: 27938ad6a4ab512ef8c564402064188c67bfb40430897f14be5cbd07eefae04bce7bf5709b5a4fbb11f82b4e51b9aaaaa36278ad3ff34cc829fd54a76d643660
7
+ data.tar.gz: b2ee9bccf5f59bb9d1a0a03d800a8824f643b5875854e57465c640d5eacce8a1ae86a45ccfe42c968921c6587a07d973b1e622bf19ac9e19eee22d906d396f16
data/README.md CHANGED
@@ -22,7 +22,8 @@ This clone attempts to provide most of RSpec's DSL to express expected outcomes
22
22
  * There is no option to activate monkey-patching.
23
23
  * It does not rely on hacks such as `at_exit` hook to trigger the tests.
24
24
  * Built-in matchers do not trust _actual_ and do not send it messages.
25
- * The `subject` must be explicitly defined, otherwise it is not implemented.
25
+ * If no `subject` has been explicitly determined, none is defined.
26
+ * If no described class is set, `described_class` is undefined instead of `nil`.
26
27
  * Expectations cannot be added inside a `before` block.
27
28
  * [Arbitrary helper methods](https://relishapp.com/rspec/rspec-core/v/3-10/docs/helper-methods/arbitrary-helper-methods) are not exposed to examples.
28
29
  * The `let` method defines a helper method rather than a memoized helper method.
@@ -45,7 +46,7 @@ Following [RubyGems naming conventions](https://guides.rubygems.org/name-your-ge
45
46
  Add this line to your application's Gemfile:
46
47
 
47
48
  ```ruby
48
- gem "r_spec", ">= 1.0.0.beta4"
49
+ gem "r_spec", ">= 1.0.0.beta5"
49
50
  ```
50
51
 
51
52
  And then execute:
@@ -227,12 +228,18 @@ __RSpec clone__'s specifications are self-described here: [spec/](https://github
227
228
 
228
229
  __RSpec clone__ follows [Semantic Versioning 2.0](https://semver.org/).
229
230
 
230
- ## Special thanks
231
+ ## Special thanks ❤️
231
232
 
232
233
  I would like to thank the whole [RSpec team](https://rspec.info/about/) for all their work.
233
234
  It's a great framework and it's a pleasure to work with every day.
234
235
 
235
- Without RSpec, this clone would not have been possible. ❤️
236
+ Without RSpec, this clone would not have been possible.
237
+
238
+ ## Buy me a coffee ☕
239
+
240
+ If you like this project please consider making a small donation.
241
+
242
+ [![Donate with Ethereum](https://github.com/cyril/r_spec.rb/raw/main/img/donate-eth.svg)](https://etherscan.io/address/0x834b5c1feaff5aebf9cd0f25dc38e741d65ab773)
236
243
 
237
244
  ## License
238
245
 
data/lib/r_spec.rb CHANGED
@@ -9,6 +9,9 @@
9
9
  # it { expect(false).not_to be true }
10
10
  # end
11
11
  #
12
+ # # Output to the console
13
+ # # Success: expected false not to be true.
14
+ #
12
15
  # @example The basic behavior of arrays
13
16
  # require "r_spec"
14
17
  #
@@ -30,6 +33,11 @@
30
33
  # end
31
34
  # end
32
35
  #
36
+ # # Output to the console
37
+ # # Success: expected to eq 3.
38
+ # # Success: expected true to be true.
39
+ # # Success: expected false to be false.
40
+ #
33
41
  # @example An inherited definition of let
34
42
  # require "r_spec"
35
43
  #
@@ -49,6 +57,10 @@
49
57
  # end
50
58
  # end
51
59
  #
60
+ # # Output to the console
61
+ # # Success: expected to be 42.
62
+ # # Success: expected to be 43.
63
+ #
52
64
  # @api public
53
65
  module RSpec
54
66
  # Specs are built with this method.
data/lib/r_spec/dsl.rb CHANGED
@@ -53,9 +53,37 @@ module RSpec
53
53
  # Add `context` to the DSL.
54
54
  singleton_class.send(:alias_method, :context, :describe)
55
55
 
56
- # Define a single spec. A spec should contain one or more expectations that
57
- # test the state of the code.
56
+ # Use the `it` method to define a single spec. A spec should contain one or
57
+ # more expectations that test the state of the code.
58
58
  #
59
+ # @example The integer after 41
60
+ # require "r_spec"
61
+ #
62
+ # RSpec.describe Integer do
63
+ # it { expect(41.next).to be 42 }
64
+ # end
65
+ #
66
+ # # Output to the console
67
+ # # Success: expected to be 42.
68
+ #
69
+ # @example A division by zero
70
+ # require "r_spec"
71
+ #
72
+ # RSpec.describe Integer do
73
+ # subject { 41 }
74
+ #
75
+ # it { is_expected.to be_an_instance_of described_class }
76
+ #
77
+ # it "raises an error" do
78
+ # expect { subject / 0 }.to raise_exception ZeroDivisionError
79
+ # end
80
+ # end
81
+ #
82
+ # # Output to the console
83
+ # # Success: expected 41 to be an instance of Integer.
84
+ # # Success: divided by 0.
85
+ #
86
+ # @param _name [String, nil] The name of the spec.
59
87
  # @param block [Proc] An expectation to evaluate.
60
88
  #
61
89
  # @raise (see ExpectationTarget::Base#result)
@@ -69,10 +97,10 @@ module RSpec
69
97
  i.instance_eval(&block)
70
98
  end
71
99
 
72
- # Define a single spec. A spec should contain one or more expectations that
73
- # test the state of the code.
100
+ # Use the `its` method to define a single spec that specifies the actual
101
+ # value of an attribute of the subject using `is_expected`.
74
102
  #
75
- # @example The value after 41
103
+ # @example The integer after 41
76
104
  # require "r_spec"
77
105
  #
78
106
  # RSpec.describe Integer do
@@ -81,14 +109,35 @@ module RSpec
81
109
  # its(:next) { is_expected.to be 42 }
82
110
  # end
83
111
  #
84
- # @example Without defining a subject
112
+ # # Output to the console
113
+ # # Success: expected to be 42.
114
+ #
115
+ # @example A division by zero
85
116
  # require "r_spec"
86
117
  #
87
118
  # RSpec.describe Integer do
88
- # its(:next) { is_expected.to raise_exception NameError }
119
+ # subject { 41 }
120
+ #
121
+ # its(:/, 0) { is_expected.to raise_exception ZeroDivisionError }
122
+ # end
123
+ #
124
+ # # Output to the console
125
+ # # Success: divided by 0.
126
+ #
127
+ # @example A spec without subject
128
+ # require "r_spec"
129
+ #
130
+ # RSpec.describe Integer do
131
+ # its(:boom) { is_expected.to raise_exception RSpec::Error::UndefinedSubject }
89
132
  # end
90
133
  #
134
+ # # Output to the console
135
+ # # Success: subject not explicitly defined.
136
+ #
91
137
  # @param attribute [String, Symbol] The property to call to subject.
138
+ # @param args [Array] An optional list of arguments.
139
+ # @param kwargs [Hash] An optional list of keyword arguments.
140
+ # @param block [Proc] An expectation to evaluate.
92
141
  #
93
142
  # @raise (see ExpectationTarget::Base#result)
94
143
  # @return (see ExpectationTarget::Base#result)
@@ -128,8 +177,20 @@ module RSpec
128
177
  end
129
178
 
130
179
  private_class_method :it_example, :its_example, :random_test_const_name
180
+
181
+ protected
182
+
183
+ def described_class
184
+ raise Error::UndefinedDescribedClass,
185
+ "the first argument to at least one example group must be a module"
186
+ end
187
+
188
+ def subject
189
+ raise Error::UndefinedSubject, "subject not explicitly defined"
190
+ end
131
191
  end
132
192
  end
133
193
 
194
+ require_relative "error"
134
195
  require_relative "expectation_helper"
135
196
  require_relative "sandbox"
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ # Namespace for exceptions.
5
+ #
6
+ # @api private
7
+ module Error
8
+ end
9
+ end
10
+
11
+ require_relative File.join("error", "pending_expectation")
12
+ require_relative File.join("error", "undefined_described_class")
13
+ require_relative File.join("error", "undefined_subject")
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "expresenter"
4
+
5
+ module RSpec
6
+ module Error
7
+ # Exception for pending expectations.
8
+ #
9
+ # @api private
10
+ class PendingExpectation < ::RuntimeError
11
+ # @param message [String] The not implemented expectation description.
12
+ #
13
+ # @return [nil] Write a pending expectation to STDOUT.
14
+ def self.result(message)
15
+ warn " " + ::Expresenter.call(true).with(
16
+ actual: new(message),
17
+ error: nil,
18
+ expected: self,
19
+ got: false,
20
+ matcher: :raise_exception,
21
+ negate: true,
22
+ level: :SHOULD,
23
+ valid: false
24
+ ).colored_string
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Error
5
+ # Exception for undefined described classes.
6
+ #
7
+ # @api private
8
+ class UndefinedDescribedClass < ::RuntimeError
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Error
5
+ # Exception for undefined subjects.
6
+ #
7
+ # @api private
8
+ class UndefinedSubject < ::RuntimeError
9
+ end
10
+ end
11
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "matchi/rspec"
4
4
 
5
- require_relative File.join("..", "pending")
5
+ require_relative File.join("..", "error", "pending_expectation")
6
6
 
7
7
  module RSpec
8
8
  module ExpectationHelper
@@ -87,9 +87,12 @@ module RSpec
87
87
  # @example Output a message to the console and return nil
88
88
  # pending("something else getting finished") # => nil
89
89
  #
90
+ # # Output to the console
91
+ # # Warning: something else getting finished.
92
+ #
90
93
  # @api public
91
94
  def pending(description)
92
- Pending.result(description)
95
+ Error::PendingExpectation.result(description)
93
96
  end
94
97
  end
95
98
  end
@@ -27,7 +27,7 @@ module RSpec
27
27
 
28
28
  # Wraps the target of an expectation with the subject as actual value.
29
29
  #
30
- # @return (see #expect)
30
+ # @return [Block] The wrapped target of an expectation.
31
31
  #
32
32
  # @example
33
33
  # is_expected # => #<RSpec::ExpectationTarget::Block:0x00007fb6b8263df8 @callable=#<Proc:0x00007fb6b8263e20>>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta4
4
+ version: 1.0.0.beta5
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-08 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expresenter
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.0
19
+ version: 1.2.1
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.2.0
26
+ version: 1.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: matchi-rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.3.2
47
+ version: 3.3.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.3.2
54
+ version: 3.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +188,10 @@ files:
188
188
  - README.md
189
189
  - lib/r_spec.rb
190
190
  - lib/r_spec/dsl.rb
191
+ - lib/r_spec/error.rb
192
+ - lib/r_spec/error/pending_expectation.rb
193
+ - lib/r_spec/error/undefined_described_class.rb
194
+ - lib/r_spec/error/undefined_subject.rb
191
195
  - lib/r_spec/expectation_helper.rb
192
196
  - lib/r_spec/expectation_helper/base.rb
193
197
  - lib/r_spec/expectation_helper/it.rb
@@ -196,7 +200,6 @@ files:
196
200
  - lib/r_spec/expectation_target/base.rb
197
201
  - lib/r_spec/expectation_target/block.rb
198
202
  - lib/r_spec/expectation_target/value.rb
199
- - lib/r_spec/pending.rb
200
203
  - lib/r_spec/sandbox.rb
201
204
  homepage: https://r-spec.dev/
202
205
  licenses:
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "expresenter"
4
-
5
- module RSpec
6
- # Exception for pending expectations.
7
- #
8
- # @api private
9
- class Pending < ::NotImplementedError
10
- # @param message [String] The not implemented expectation description.
11
- #
12
- # @return [nil] Write a pending expectation to STDOUT.
13
- def self.result(message)
14
- warn " " + ::Expresenter.call(true).with(
15
- actual: new(message),
16
- error: nil,
17
- expected: self,
18
- got: false,
19
- matcher: :raise_exception,
20
- negate: true,
21
- level: :SHOULD,
22
- valid: false
23
- ).colored_string
24
- end
25
- end
26
- end