r_spec 1.0.0.beta3 → 1.0.0.beta8
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 +127 -166
- data/lib/r_spec.rb +57 -5
- data/lib/r_spec/console.rb +38 -0
- data/lib/r_spec/dsl.rb +297 -76
- data/lib/r_spec/error.rb +14 -0
- data/lib/r_spec/error/pending_expectation.rb +28 -0
- data/lib/r_spec/error/reserved_method.rb +11 -0
- data/lib/r_spec/error/undefined_described_class.rb +11 -0
- data/lib/r_spec/error/undefined_subject.rb +11 -0
- data/lib/r_spec/expectation_helper.rb +10 -0
- data/lib/r_spec/expectation_helper/it.rb +41 -0
- data/lib/r_spec/expectation_helper/its.rb +25 -0
- data/lib/r_spec/expectation_helper/shared.rb +82 -0
- data/lib/r_spec/expectation_target.rb +7 -5
- data/lib/r_spec/expectation_target/base.rb +21 -5
- data/lib/r_spec/expectation_target/block.rb +7 -18
- data/lib/r_spec/expectation_target/value.rb +6 -17
- metadata +19 -11
- data/lib/r_spec/log.rb +0 -24
- data/lib/r_spec/pending.rb +0 -24
- data/lib/r_spec/test.rb +0 -7
data/lib/r_spec/error.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative File.join("error", "pending_expectation")
|
4
|
+
require_relative File.join("error", "reserved_method")
|
5
|
+
require_relative File.join("error", "undefined_described_class")
|
6
|
+
require_relative File.join("error", "undefined_subject")
|
7
|
+
|
8
|
+
module RSpec
|
9
|
+
# Namespace for exceptions.
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
module Error
|
13
|
+
end
|
14
|
+
end
|
@@ -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
|
+
::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
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative File.join("expectation_helper", "it")
|
4
|
+
require_relative File.join("expectation_helper", "its")
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
# Namespace for {Dsl.it} and {Dsl.its}'s helper modules.
|
8
|
+
module ExpectationHelper
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "shared"
|
4
|
+
require_relative File.join("..", "expectation_target")
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
module ExpectationHelper
|
8
|
+
# {RSpec::Dsl.it}'s expectation helper module.
|
9
|
+
module It
|
10
|
+
include Shared
|
11
|
+
|
12
|
+
# Create an expectation for a spec.
|
13
|
+
#
|
14
|
+
# @param value [#object_id, nil] An actual value.
|
15
|
+
# @param block [#call, nil] A code to evaluate.
|
16
|
+
#
|
17
|
+
# @return [Block, Value] The wrapped target of an expectation.
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# expect("foo") # => #<RSpec::ExpectationTarget::Value:0x00007fb6b82311a0 @actual="foo">
|
21
|
+
# expect { Boom } # => #<RSpec::ExpectationTarget::Block:0x00007fb6b8263df8 @callable=#<Proc:0x00007fb6b8263e20>>
|
22
|
+
#
|
23
|
+
# @api public
|
24
|
+
def expect(value = self.class.superclass, &block)
|
25
|
+
ExpectationTarget.call(self.class.superclass, value, block)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Wraps the target of an expectation with the subject as actual value.
|
29
|
+
#
|
30
|
+
# @return [Block] The wrapped target of an expectation.
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
# is_expected # => #<RSpec::ExpectationTarget::Block:0x00007fb6b8263df8 @callable=#<Proc:0x00007fb6b8263e20>>
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
def is_expected
|
37
|
+
expect { subject }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "shared"
|
4
|
+
require_relative File.join("..", "expectation_target", "block")
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
module ExpectationHelper
|
8
|
+
# {RSpec::Dsl.its}'s expectation helper module.
|
9
|
+
module Its
|
10
|
+
include Shared
|
11
|
+
|
12
|
+
# Wraps the target of an expectation with the actual value.
|
13
|
+
#
|
14
|
+
# @return [Block] The wrapped target of an expectation.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# is_expected # => #<RSpec::ExpectationTarget::Block:0x00007fb6b8263df8 @callable=#<Proc:0x00007fb6b8263e20>>
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
def is_expected
|
21
|
+
ExpectationTarget::Block.new(method(:actual))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "matchi/rspec"
|
4
|
+
|
5
|
+
require_relative File.join("..", "error", "pending_expectation")
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module ExpectationHelper
|
9
|
+
# Abstract expectation helper base module.
|
10
|
+
#
|
11
|
+
# This module defines a number of methods to create expectations, which are
|
12
|
+
# automatically included into examples.
|
13
|
+
#
|
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
|
75
|
+
#
|
76
|
+
# @see https://github.com/fixrb/matchi
|
77
|
+
# @see https://github.com/fixrb/matchi-rspec
|
78
|
+
module Shared
|
79
|
+
include ::Matchi::Helper
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -1,15 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative File.join("expectation_target", "block")
|
4
|
+
require_relative File.join("expectation_target", "value")
|
5
|
+
|
3
6
|
module RSpec
|
4
7
|
# Wraps the target of an expectation.
|
8
|
+
#
|
9
|
+
# @api private
|
5
10
|
module ExpectationTarget
|
6
11
|
# @param undefined_value A sentinel value to be able to tell when the user
|
7
12
|
# did not pass an argument. We can't use `nil` for that because `nil` is a
|
8
13
|
# valid value to pass.
|
9
|
-
# @param value [#object_id, nil] An actual value
|
14
|
+
# @param value [#object_id, nil] An actual value.
|
10
15
|
# @param block [#call, nil] A code to evaluate.
|
11
16
|
#
|
12
|
-
# @
|
17
|
+
# @return [Block, Value] The wrapped target of an expectation.
|
13
18
|
def self.call(undefined_value, value, block)
|
14
19
|
if undefined_value.equal?(value)
|
15
20
|
raise ::ArgumentError, "Pass either an argument or a block" unless block
|
@@ -23,6 +28,3 @@ module RSpec
|
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
26
|
-
|
27
|
-
require_relative File.join("expectation_target", "block")
|
28
|
-
require_relative File.join("expectation_target", "value")
|
@@ -2,12 +2,22 @@
|
|
2
2
|
|
3
3
|
require "expresenter"
|
4
4
|
|
5
|
+
require_relative File.join("..", "console")
|
6
|
+
|
5
7
|
module RSpec
|
6
8
|
module ExpectationTarget
|
7
|
-
# Abstract class.
|
9
|
+
# Abstract expectation target base class.
|
8
10
|
#
|
9
|
-
# @
|
11
|
+
# @note `RSpec::ExpectationTarget::Base` is not intended to be instantiated
|
12
|
+
# directly by users. Use `expect` instead.
|
10
13
|
class Base
|
14
|
+
# Instantiate a new expectation target.
|
15
|
+
#
|
16
|
+
# @param actual [#object_id] The actual value of the code to evaluate.
|
17
|
+
def initialize(actual)
|
18
|
+
@actual = actual
|
19
|
+
end
|
20
|
+
|
11
21
|
# Runs the given expectation, passing if `matcher` returns true.
|
12
22
|
#
|
13
23
|
# @example _Absolute requirement_ definition
|
@@ -17,6 +27,8 @@ module RSpec
|
|
17
27
|
#
|
18
28
|
# @raise (see #result)
|
19
29
|
# @return (see #result)
|
30
|
+
#
|
31
|
+
# @api public
|
20
32
|
def to(matcher)
|
21
33
|
absolute_requirement(matcher: matcher, negate: false)
|
22
34
|
end
|
@@ -30,6 +42,8 @@ module RSpec
|
|
30
42
|
#
|
31
43
|
# @raise (see #result)
|
32
44
|
# @return (see #result)
|
45
|
+
#
|
46
|
+
# @api public
|
33
47
|
def not_to(matcher)
|
34
48
|
absolute_requirement(matcher: matcher, negate: true)
|
35
49
|
end
|
@@ -47,8 +61,10 @@ module RSpec
|
|
47
61
|
#
|
48
62
|
# @raise [SystemExit] Terminate execution immediately by calling
|
49
63
|
# `Kernel.exit(false)` with a failure message written to STDERR.
|
64
|
+
#
|
65
|
+
# @api private
|
50
66
|
def result(actual:, error:, got:, matcher:, negate:, valid:)
|
51
|
-
|
67
|
+
Console.passed_spec ::Expresenter.call(valid).with(
|
52
68
|
actual: actual,
|
53
69
|
error: error,
|
54
70
|
expected: matcher.expected,
|
@@ -57,9 +73,9 @@ module RSpec
|
|
57
73
|
valid: valid,
|
58
74
|
matcher: matcher.class.to_sym,
|
59
75
|
level: :MUST
|
60
|
-
)
|
76
|
+
)
|
61
77
|
rescue ::Expresenter::Fail => e
|
62
|
-
|
78
|
+
Console.failed_spec(e)
|
63
79
|
end
|
64
80
|
end
|
65
81
|
end
|
@@ -6,7 +6,7 @@ require_relative "base"
|
|
6
6
|
|
7
7
|
module RSpec
|
8
8
|
module ExpectationTarget
|
9
|
-
# Wraps the target of an expectation.
|
9
|
+
# Wraps the target of an expectation with a block.
|
10
10
|
#
|
11
11
|
# @example
|
12
12
|
# expect { something } # => ExpectationTarget::Block wrapping something
|
@@ -19,30 +19,19 @@ module RSpec
|
|
19
19
|
#
|
20
20
|
# @note `RSpec::ExpectationTarget::Block` is not intended to be instantiated
|
21
21
|
# directly by users. Use `expect` instead.
|
22
|
-
#
|
23
|
-
# @private
|
24
22
|
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
23
|
protected
|
37
24
|
|
38
25
|
# @param matcher [#matches?] The matcher.
|
39
|
-
# @param negate [Boolean]
|
26
|
+
# @param negate [Boolean] The assertion is positive or negative.
|
27
|
+
#
|
28
|
+
# @return [nil] Write a message to STDOUT.
|
40
29
|
#
|
41
|
-
# @raise
|
42
|
-
#
|
30
|
+
# @raise [SystemExit] Terminate execution immediately by calling
|
31
|
+
# `Kernel.exit(false)` with a failure message written to STDERR.
|
43
32
|
def absolute_requirement(matcher:, negate:)
|
44
33
|
exam = ::Spectus::Exam.new(
|
45
|
-
callable: @
|
34
|
+
callable: @actual,
|
46
35
|
isolation: false,
|
47
36
|
negate: negate,
|
48
37
|
matcher: matcher
|
@@ -4,7 +4,7 @@ require_relative "base"
|
|
4
4
|
|
5
5
|
module RSpec
|
6
6
|
module ExpectationTarget
|
7
|
-
# Wraps the target of an expectation.
|
7
|
+
# Wraps the target of an expectation with a value.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
# expect(something) # => ExpectationTarget::Value wrapping something
|
@@ -17,27 +17,16 @@ module RSpec
|
|
17
17
|
#
|
18
18
|
# @note `RSpec::ExpectationTarget::Value` is not intended to be instantiated
|
19
19
|
# directly by users. Use `expect` instead.
|
20
|
-
#
|
21
|
-
# @private
|
22
20
|
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
21
|
protected
|
35
22
|
|
36
23
|
# @param matcher [#matches?] The matcher.
|
37
|
-
# @param negate [Boolean]
|
24
|
+
# @param negate [Boolean] The assertion is positive or negative.
|
25
|
+
#
|
26
|
+
# @return [nil] Write a message to STDOUT.
|
38
27
|
#
|
39
|
-
# @raise
|
40
|
-
#
|
28
|
+
# @raise [SystemExit] Terminate execution immediately by calling
|
29
|
+
# `Kernel.exit(false)` with a failure message written to STDERR.
|
41
30
|
def absolute_requirement(matcher:, negate:)
|
42
31
|
valid = negate ^ matcher.matches? { @actual }
|
43
32
|
|
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.
|
4
|
+
version: 1.0.0.beta8
|
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-
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: expresenter
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.
|
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.
|
26
|
+
version: 1.2.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: matchi-rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.
|
33
|
+
version: 1.1.2
|
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.1.
|
40
|
+
version: 1.1.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: spectus
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.3.
|
47
|
+
version: 3.3.4
|
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.
|
54
|
+
version: 3.3.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,14 +187,21 @@ files:
|
|
187
187
|
- LICENSE.md
|
188
188
|
- README.md
|
189
189
|
- lib/r_spec.rb
|
190
|
+
- lib/r_spec/console.rb
|
190
191
|
- lib/r_spec/dsl.rb
|
192
|
+
- lib/r_spec/error.rb
|
193
|
+
- lib/r_spec/error/pending_expectation.rb
|
194
|
+
- lib/r_spec/error/reserved_method.rb
|
195
|
+
- lib/r_spec/error/undefined_described_class.rb
|
196
|
+
- lib/r_spec/error/undefined_subject.rb
|
197
|
+
- lib/r_spec/expectation_helper.rb
|
198
|
+
- lib/r_spec/expectation_helper/it.rb
|
199
|
+
- lib/r_spec/expectation_helper/its.rb
|
200
|
+
- lib/r_spec/expectation_helper/shared.rb
|
191
201
|
- lib/r_spec/expectation_target.rb
|
192
202
|
- lib/r_spec/expectation_target/base.rb
|
193
203
|
- lib/r_spec/expectation_target/block.rb
|
194
204
|
- 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
205
|
homepage: https://r-spec.dev/
|
199
206
|
licenses:
|
200
207
|
- MIT
|
@@ -202,6 +209,7 @@ metadata:
|
|
202
209
|
bug_tracker_uri: https://github.com/cyril/r_spec.rb/issues
|
203
210
|
documentation_uri: https://rubydoc.info/gems/r_spec
|
204
211
|
source_code_uri: https://github.com/cyril/r_spec.rb
|
212
|
+
wiki_uri: https://github.com/cyril/r_spec.rb/wiki
|
205
213
|
post_install_message:
|
206
214
|
rdoc_options: []
|
207
215
|
require_paths:
|