r_spec 0.3.1 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ # Wraps the target of an expectation.
5
+ module ExpectationTarget
6
+ # @param undefined_value A sentinel value to be able to tell when the user
7
+ # did not pass an argument. We can't use `nil` for that because `nil` is a
8
+ # valid value to pass.
9
+ # @param value [#object_id, nil] An actual value
10
+ # @param block [#call, nil] A code to evaluate.
11
+ #
12
+ # @private
13
+ def self.call(undefined_value, value, block)
14
+ if undefined_value.equal?(value)
15
+ raise ::ArgumentError, "Pass either an argument or a block" unless block
16
+
17
+ Block.new(block)
18
+ else
19
+ raise ::ArgumentError, "Can't pass both an argument and a block" if block
20
+
21
+ Value.new(value)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ require_relative File.join("expectation_target", "block")
28
+ require_relative File.join("expectation_target", "value")
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "expresenter"
4
+
5
+ module RSpec
6
+ module ExpectationTarget
7
+ # Abstract class.
8
+ #
9
+ # @private
10
+ class Base
11
+ # Runs the given expectation, passing if `matcher` returns true.
12
+ #
13
+ # @example _Absolute requirement_ definition
14
+ # expect { "foo".upcase }.to eq("foo")
15
+ #
16
+ # @param matcher [#matches?] The matcher.
17
+ #
18
+ # @raise (see #result)
19
+ # @return (see #result)
20
+ def to(matcher)
21
+ absolute_requirement(matcher: matcher, negate: false)
22
+ end
23
+
24
+ # Runs the given expectation, passing if `matcher` returns false.
25
+ #
26
+ # @example _Absolute prohibition_ definition
27
+ # expect { "foo".size }.not_to be(4)
28
+ #
29
+ # @param (see #to)
30
+ #
31
+ # @raise (see #result)
32
+ # @return (see #result)
33
+ def not_to(matcher)
34
+ absolute_requirement(matcher: matcher, negate: true)
35
+ end
36
+
37
+ protected
38
+
39
+ # @param actual [#object_id] The actual value.
40
+ # @param error [Exception, nil] Any raised exception.
41
+ # @param got [Boolean, nil] Any returned value.
42
+ # @param matcher [#matches?] The matcher.
43
+ # @param negate [Boolean] The assertion is positive or negative.
44
+ # @param valid [Boolean] The result of an expectation.
45
+ #
46
+ # @return [nil] Write a message to STDOUT.
47
+ #
48
+ # @raise [SystemExit] Terminate execution immediately by calling
49
+ # `Kernel.exit(false)` with a failure message written to STDERR.
50
+ def result(actual:, error:, got:, matcher:, negate:, valid:)
51
+ puts " " + ::Expresenter.call(valid).with(
52
+ actual: actual,
53
+ error: error,
54
+ expected: matcher.expected,
55
+ got: got,
56
+ negate: negate,
57
+ valid: valid,
58
+ matcher: matcher.class.to_sym,
59
+ level: :MUST
60
+ ).colored_string
61
+ rescue ::Expresenter::Fail => e
62
+ abort " #{e.colored_string}"
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spectus/exam"
4
+
5
+ require_relative "base"
6
+
7
+ module RSpec
8
+ module ExpectationTarget
9
+ # Wraps the target of an expectation.
10
+ #
11
+ # @example
12
+ # expect { something } # => ExpectationTarget::Block wrapping something
13
+ #
14
+ # # used with `to`
15
+ # expect { actual }.to be(42)
16
+ #
17
+ # # with `not_to`
18
+ # expect { actual }.not_to be(4)
19
+ #
20
+ # @note `RSpec::ExpectationTarget::Block` is not intended to be instantiated
21
+ # directly by users. Use `expect` instead.
22
+ #
23
+ # @private
24
+ class Block < Base
25
+ # Instantiate a new expectation target.
26
+ #
27
+ # @param block [#call] The code to evaluate.
28
+ #
29
+ # @api private
30
+ def initialize(block)
31
+ super()
32
+
33
+ @callable = block
34
+ end
35
+
36
+ protected
37
+
38
+ # @param matcher [#matches?] The matcher.
39
+ # @param negate [Boolean] Positive or negative assertion?
40
+ #
41
+ # @raise (see Base#result)
42
+ # @return (see Base#result)
43
+ def absolute_requirement(matcher:, negate:)
44
+ exam = ::Spectus::Exam.new(
45
+ callable: @callable,
46
+ isolation: false,
47
+ negate: negate,
48
+ matcher: matcher
49
+ )
50
+
51
+ result(
52
+ actual: exam.actual,
53
+ error: exam.exception,
54
+ got: exam.got,
55
+ matcher: matcher,
56
+ negate: negate,
57
+ valid: exam.valid?
58
+ )
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module RSpec
6
+ module ExpectationTarget
7
+ # Wraps the target of an expectation.
8
+ #
9
+ # @example
10
+ # expect(something) # => ExpectationTarget::Value wrapping something
11
+ #
12
+ # # used with `to`
13
+ # expect(actual).to be(42)
14
+ #
15
+ # # with `not_to`
16
+ # expect(actual).not_to be(4)
17
+ #
18
+ # @note `RSpec::ExpectationTarget::Value` is not intended to be instantiated
19
+ # directly by users. Use `expect` instead.
20
+ #
21
+ # @private
22
+ class Value < Base
23
+ # Instantiate a new expectation target.
24
+ #
25
+ # @param actual [#object_id] The actual value.
26
+ #
27
+ # @api private
28
+ def initialize(actual)
29
+ super()
30
+
31
+ @actual = actual
32
+ end
33
+
34
+ protected
35
+
36
+ # @param matcher [#matches?] The matcher.
37
+ # @param negate [Boolean] Positive or negative assertion?
38
+ #
39
+ # @raise (see Base#result)
40
+ # @return (see Base#result)
41
+ def absolute_requirement(matcher:, negate:)
42
+ valid = negate ^ matcher.matches? { @actual }
43
+
44
+ result(
45
+ actual: @actual,
46
+ error: nil,
47
+ got: valid,
48
+ matcher: matcher,
49
+ negate: negate,
50
+ valid: valid
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/r_spec/log.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "expresenter"
4
+
5
+ module RSpec
6
+ # Exception for debugging purpose.
7
+ class Log < ::NoMethodError
8
+ # @param message [String] A message to log to the console.
9
+ #
10
+ # @return [nil] Write a log message to STDOUT.
11
+ def self.result(message)
12
+ puts " " + ::Expresenter.call(true).with(
13
+ actual: nil,
14
+ error: new(message),
15
+ expected: 42,
16
+ got: nil,
17
+ matcher: :be,
18
+ negate: false,
19
+ level: :MAY,
20
+ valid: false
21
+ ).colored_string
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "expresenter"
4
+
5
+ module RSpec
6
+ # Exception for pending expectations.
7
+ class Pending < ::NotImplementedError
8
+ # @param message [String] The not implemented expectation description.
9
+ #
10
+ # @return [nil] Write a pending expectation to STDOUT.
11
+ def self.result(message)
12
+ warn " " + ::Expresenter.call(true).with(
13
+ actual: new(message),
14
+ error: nil,
15
+ expected: self,
16
+ got: false,
17
+ matcher: :raise_exception,
18
+ negate: true,
19
+ level: :SHOULD,
20
+ valid: false
21
+ ).colored_string
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ # Namespace to collect test classes.
5
+ module Test
6
+ end
7
+ end
metadata CHANGED
@@ -1,188 +1,207 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - certs/gem-cyril-public_cert.pem
12
- date: 2017-04-30 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2021-06-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: fix-expect
14
+ name: expresenter
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: 0.3.2
19
+ version: 1.2.0
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: 0.3.2
26
+ version: 1.2.0
28
27
  - !ruby/object:Gem::Dependency
29
- name: fix-its
28
+ name: matchi-rspec
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - "~>"
33
32
  - !ruby/object:Gem::Version
34
- version: 0.5.1
33
+ version: 1.1.0
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - "~>"
40
39
  - !ruby/object:Gem::Version
41
- version: 0.5.1
40
+ version: 1.1.0
42
41
  - !ruby/object:Gem::Dependency
43
- name: fix-let
42
+ name: spectus
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
45
  - - "~>"
47
46
  - !ruby/object:Gem::Version
48
- version: 0.1.1
47
+ version: 3.3.2
49
48
  type: :runtime
50
49
  prerelease: false
51
50
  version_requirements: !ruby/object:Gem::Requirement
52
51
  requirements:
53
52
  - - "~>"
54
53
  - !ruby/object:Gem::Version
55
- version: 0.1.1
54
+ version: 3.3.2
56
55
  - !ruby/object:Gem::Dependency
57
- name: matchi-rspec
56
+ name: bundler
58
57
  requirement: !ruby/object:Gem::Requirement
59
58
  requirements:
60
- - - "~>"
59
+ - - ">="
61
60
  - !ruby/object:Gem::Version
62
- version: 0.1.1
63
- type: :runtime
61
+ version: '0'
62
+ type: :development
64
63
  prerelease: false
65
64
  version_requirements: !ruby/object:Gem::Requirement
66
65
  requirements:
67
- - - "~>"
66
+ - - ">="
68
67
  - !ruby/object:Gem::Version
69
- version: 0.1.1
68
+ version: '0'
70
69
  - !ruby/object:Gem::Dependency
71
- name: bundler
70
+ name: rake
72
71
  requirement: !ruby/object:Gem::Requirement
73
72
  requirements:
74
- - - "~>"
73
+ - - ">="
75
74
  - !ruby/object:Gem::Version
76
- version: '1.14'
75
+ version: '0'
77
76
  type: :development
78
77
  prerelease: false
79
78
  version_requirements: !ruby/object:Gem::Requirement
80
79
  requirements:
81
- - - "~>"
80
+ - - ">="
82
81
  - !ruby/object:Gem::Version
83
- version: '1.14'
82
+ version: '0'
84
83
  - !ruby/object:Gem::Dependency
85
- name: rake
84
+ name: rubocop-md
86
85
  requirement: !ruby/object:Gem::Requirement
87
86
  requirements:
88
- - - "~>"
87
+ - - ">="
89
88
  - !ruby/object:Gem::Version
90
- version: '12.0'
89
+ version: '0'
91
90
  type: :development
92
91
  prerelease: false
93
92
  version_requirements: !ruby/object:Gem::Requirement
94
93
  requirements:
95
- - - "~>"
94
+ - - ">="
96
95
  - !ruby/object:Gem::Version
97
- version: '12.0'
96
+ version: '0'
98
97
  - !ruby/object:Gem::Dependency
99
- name: yard
98
+ name: rubocop-performance
100
99
  requirement: !ruby/object:Gem::Requirement
101
100
  requirements:
102
- - - "~>"
101
+ - - ">="
103
102
  - !ruby/object:Gem::Version
104
- version: '0.9'
103
+ version: '0'
105
104
  type: :development
106
105
  prerelease: false
107
106
  version_requirements: !ruby/object:Gem::Requirement
108
107
  requirements:
109
- - - "~>"
108
+ - - ">="
110
109
  - !ruby/object:Gem::Version
111
- version: '0.9'
110
+ version: '0'
112
111
  - !ruby/object:Gem::Dependency
113
- name: simplecov
112
+ name: rubocop-rake
114
113
  requirement: !ruby/object:Gem::Requirement
115
114
  requirements:
116
- - - "~>"
115
+ - - ">="
117
116
  - !ruby/object:Gem::Version
118
- version: '0.14'
117
+ version: '0'
119
118
  type: :development
120
119
  prerelease: false
121
120
  version_requirements: !ruby/object:Gem::Requirement
122
121
  requirements:
123
- - - "~>"
122
+ - - ">="
124
123
  - !ruby/object:Gem::Version
125
- version: '0.14'
124
+ version: '0'
126
125
  - !ruby/object:Gem::Dependency
127
- name: rubocop
126
+ name: rubocop-rspec
128
127
  requirement: !ruby/object:Gem::Requirement
129
128
  requirements:
130
- - - "~>"
129
+ - - ">="
131
130
  - !ruby/object:Gem::Version
132
- version: '0.48'
131
+ version: '0'
133
132
  type: :development
134
133
  prerelease: false
135
134
  version_requirements: !ruby/object:Gem::Requirement
136
135
  requirements:
137
- - - "~>"
136
+ - - ">="
138
137
  - !ruby/object:Gem::Version
139
- version: '0.48'
138
+ version: '0'
140
139
  - !ruby/object:Gem::Dependency
141
- name: spectus
140
+ name: rubocop-thread_safety
142
141
  requirement: !ruby/object:Gem::Requirement
143
142
  requirements:
144
- - - "~>"
143
+ - - ">="
145
144
  - !ruby/object:Gem::Version
146
- version: '3.0'
145
+ version: '0'
147
146
  type: :development
148
147
  prerelease: false
149
148
  version_requirements: !ruby/object:Gem::Requirement
150
149
  requirements:
151
- - - "~>"
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
152
165
  - !ruby/object:Gem::Version
153
- version: '3.0'
154
- description: A small Rspec clone based on Fix specing framework.
155
- email:
156
- - contact@cyril.email
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: A minimalist RSpec clone with all the essentials.
182
+ email: contact@cyril.email
157
183
  executables: []
158
184
  extensions: []
159
185
  extra_rdoc_files: []
160
186
  files:
161
- - ".gitignore"
162
- - ".travis.yml"
163
- - ".yardopts"
164
- - CODE_OF_CONDUCT.md
165
- - Gemfile
166
187
  - LICENSE.md
167
188
  - README.md
168
- - Rakefile
169
- - VERSION.semver
170
- - bin/console
171
- - bin/setup
172
- - certs/gem-cyril-public_cert.pem
173
- - checksum/r_spec-0.1.0.gem.sha512
174
- - checksum/r_spec-0.1.1.gem.sha512
175
- - checksum/r_spec-0.2.0.gem.sha512
176
- - checksum/r_spec-0.3.0.gem.sha512
177
- - lib/fix/it.rb
178
- - lib/fix/on.rb
179
189
  - lib/r_spec.rb
180
- - pkg_checksum
181
- - r_spec.gemspec
182
- homepage: https://github.com/cyril/r_spec
190
+ - lib/r_spec/dsl.rb
191
+ - lib/r_spec/expectation_target.rb
192
+ - lib/r_spec/expectation_target/base.rb
193
+ - lib/r_spec/expectation_target/block.rb
194
+ - lib/r_spec/expectation_target/value.rb
195
+ - lib/r_spec/log.rb
196
+ - lib/r_spec/pending.rb
197
+ - lib/r_spec/test.rb
198
+ homepage: https://r-spec.dev/
183
199
  licenses:
184
200
  - MIT
185
- metadata: {}
201
+ metadata:
202
+ bug_tracker_uri: https://github.com/cyril/r_spec.rb/issues
203
+ documentation_uri: https://rubydoc.info/gems/r_spec
204
+ source_code_uri: https://github.com/cyril/r_spec.rb
186
205
  post_install_message:
187
206
  rdoc_options: []
188
207
  require_paths:
@@ -191,16 +210,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
210
  requirements:
192
211
  - - ">="
193
212
  - !ruby/object:Gem::Version
194
- version: '0'
213
+ version: 2.7.0
195
214
  required_rubygems_version: !ruby/object:Gem::Requirement
196
215
  requirements:
197
- - - ">="
216
+ - - ">"
198
217
  - !ruby/object:Gem::Version
199
- version: '0'
218
+ version: 1.3.1
200
219
  requirements: []
201
- rubyforge_project:
202
- rubygems_version: 2.6.11
220
+ rubygems_version: 3.1.6
203
221
  signing_key:
204
222
  specification_version: 4
205
- summary: Rspec clone with Fix.
223
+ summary: A minimalist RSpec clone
206
224
  test_files: []