rspec-forward 0.2.1 → 0.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/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +23 -23
- data/lib/rspec/forward/core_extensions.rb +21 -0
- data/lib/rspec/forward/forward_scope_methods.rb +67 -0
- data/lib/rspec/forward/forward_scope_parent_methods.rb +32 -0
- data/lib/rspec/forward/forward_to_scope.rb +27 -0
- data/lib/rspec/forward/version.rb +1 -1
- data/lib/rspec/forward.rb +8 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 408b6bb845882bb291901c4cdd81bdc6c0f22b90f9a28f76992e22a83c4b1c63
|
4
|
+
data.tar.gz: 82a3952da4f7b3debb6759afbc0fd37340405fde5d59a3059b081d83224e9493
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98481a93f0e7770547c370b49d5635b0e4be146ea9b292139ca4eb692e202c1b0778410c213af863da8770d6e194aabd5212107c2c6b30061255a6e0f060ac67
|
7
|
+
data.tar.gz: 403eef097334f5796c461e8bca0ad792b00e22d65d8a7484a88bab5209b59ca228fa150f8c22d4459685d1a5be93d4d16fdcf057455d7b242e56c04ccfbac4bb
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-forward (0.
|
4
|
+
rspec-forward (0.3.0)
|
5
5
|
rspec-mocks (~> 3.9)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
coderay (1.1.3)
|
11
|
-
diff-lcs (1.
|
12
|
-
ffi (1.15.
|
13
|
-
formatador (
|
14
|
-
guard (2.
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
ffi (1.15.5)
|
13
|
+
formatador (1.1.0)
|
14
|
+
guard (2.18.0)
|
15
15
|
formatador (>= 0.2.4)
|
16
16
|
listen (>= 2.7, < 4.0)
|
17
17
|
lumberjack (>= 1.0.12, < 2.0)
|
18
18
|
nenv (~> 0.1)
|
19
19
|
notiffany (~> 0.0)
|
20
|
-
pry (>= 0.
|
20
|
+
pry (>= 0.13.0)
|
21
21
|
shellany (~> 0.0)
|
22
22
|
thor (>= 0.18.1)
|
23
23
|
guard-compat (1.2.1)
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
guard (~> 2.1)
|
26
26
|
guard-compat (~> 1.1)
|
27
27
|
rspec (>= 2.99.0, < 4.0)
|
28
|
-
listen (3.
|
28
|
+
listen (3.7.1)
|
29
29
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
30
30
|
rb-inotify (~> 0.9, >= 0.9.10)
|
31
31
|
lumberjack (1.2.8)
|
@@ -37,25 +37,25 @@ GEM
|
|
37
37
|
pry (0.14.1)
|
38
38
|
coderay (~> 1.1)
|
39
39
|
method_source (~> 1.0)
|
40
|
-
rake (
|
41
|
-
rb-fsevent (0.11.
|
40
|
+
rake (13.0.6)
|
41
|
+
rb-fsevent (0.11.1)
|
42
42
|
rb-inotify (0.10.1)
|
43
43
|
ffi (~> 1.0)
|
44
|
-
rspec (3.
|
45
|
-
rspec-core (~> 3.
|
46
|
-
rspec-expectations (~> 3.
|
47
|
-
rspec-mocks (~> 3.
|
48
|
-
rspec-core (3.
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-expectations (3.
|
44
|
+
rspec (3.11.0)
|
45
|
+
rspec-core (~> 3.11.0)
|
46
|
+
rspec-expectations (~> 3.11.0)
|
47
|
+
rspec-mocks (~> 3.11.0)
|
48
|
+
rspec-core (3.11.0)
|
49
|
+
rspec-support (~> 3.11.0)
|
50
|
+
rspec-expectations (3.11.0)
|
51
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
-
rspec-support (~> 3.
|
53
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.11.0)
|
53
|
+
rspec-mocks (3.11.1)
|
54
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
-
rspec-support (~> 3.
|
56
|
-
rspec-support (3.
|
55
|
+
rspec-support (~> 3.11.0)
|
56
|
+
rspec-support (3.11.0)
|
57
57
|
shellany (0.0.1)
|
58
|
-
thor (1.1
|
58
|
+
thor (1.2.1)
|
59
59
|
|
60
60
|
PLATFORMS
|
61
61
|
ruby
|
@@ -63,9 +63,9 @@ PLATFORMS
|
|
63
63
|
DEPENDENCIES
|
64
64
|
guard (~> 2.16)
|
65
65
|
guard-rspec (~> 4.7)
|
66
|
-
rake
|
66
|
+
rake
|
67
67
|
rspec (~> 3.0)
|
68
68
|
rspec-forward!
|
69
69
|
|
70
70
|
BUNDLED WITH
|
71
|
-
2.
|
71
|
+
2.3.20
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ::RSpec
|
2
|
+
module Forward
|
3
|
+
module CoreExtensions
|
4
|
+
refine String do
|
5
|
+
def camelize(uppercase_first_letter = true)
|
6
|
+
string = self
|
7
|
+
|
8
|
+
if uppercase_first_letter
|
9
|
+
string = string.sub(/^[a-z\d]*/, &:capitalize)
|
10
|
+
else
|
11
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/, &:downcase)
|
12
|
+
end
|
13
|
+
|
14
|
+
string
|
15
|
+
.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
|
16
|
+
.gsub("/", "::")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ::RSpec
|
2
|
+
module Forward
|
3
|
+
module ForwardScopeMethods
|
4
|
+
using CoreExtensions
|
5
|
+
|
6
|
+
def exp_args(actual)
|
7
|
+
return [actual, *@args] if @with_parent_arg
|
8
|
+
return [no_args] if @args.size.zero? && @kwargs.size.zero?
|
9
|
+
|
10
|
+
@args
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches_for?(actual)
|
14
|
+
method_name = @expected
|
15
|
+
base_klass = format("%<method>s_scope", method: method_name.to_s).camelize
|
16
|
+
@scope_klass_name ||= format("%s::%s", actual.to_s, base_klass)
|
17
|
+
|
18
|
+
|
19
|
+
begin
|
20
|
+
@scope_klass = Object.const_get(@scope_klass_name)
|
21
|
+
rescue NameError => e
|
22
|
+
failure_scope_klass_name_not_defined(@scope_klass_name)
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
|
26
|
+
allow(@scope_klass)
|
27
|
+
.to receive(@target_method_name)
|
28
|
+
.and_return(:result)
|
29
|
+
|
30
|
+
if @kwargs.any?
|
31
|
+
result = actual.public_send(method_name, *@args, **@kwargs) == :result
|
32
|
+
|
33
|
+
expect(@scope_klass)
|
34
|
+
.to have_received(@target_method_name)
|
35
|
+
.with(*exp_args(actual), **@kwargs)
|
36
|
+
else
|
37
|
+
result = actual.public_send(method_name, *@args) == :result
|
38
|
+
|
39
|
+
expect(@scope_klass)
|
40
|
+
.to have_received(@target_method_name)
|
41
|
+
.with(*exp_args(actual))
|
42
|
+
end
|
43
|
+
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
def failure_scope_klass_name_not_defined(name)
|
48
|
+
@failure_message = "#{name} should be defined"
|
49
|
+
@failure_message_when_negated = "#{name} should be defined"
|
50
|
+
end
|
51
|
+
|
52
|
+
def failure_message
|
53
|
+
@failure_message ||
|
54
|
+
%Q(expected "#{@target}.call" to be invoked)
|
55
|
+
end
|
56
|
+
|
57
|
+
def failure_message_when_negated
|
58
|
+
@failure_message_when_negated ||
|
59
|
+
%Q(expected "#{@target}.call" not to be invoked)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.included(base)
|
63
|
+
private :matches_for?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ::RSpec
|
2
|
+
module Forward
|
3
|
+
module ForwardScopeParentMethods
|
4
|
+
using CoreExtensions
|
5
|
+
|
6
|
+
def using_method(target_method_name)
|
7
|
+
@target_method_name = target_method_name
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def using_class_name(target_class_name)
|
12
|
+
@scope_klass_name = target_class_name
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def using_method_args(*args, **kwargs)
|
17
|
+
@args = args
|
18
|
+
@kwargs = kwargs
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def with_parent_arg
|
23
|
+
# Name of the parent class is not available here if the default
|
24
|
+
# class is used, because defaualt class needs the "actual"
|
25
|
+
# parameter from matchers_for?(actual)
|
26
|
+
|
27
|
+
@with_parent_arg = true
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ::RSpec
|
2
|
+
module Forward
|
3
|
+
class ForwardToScope
|
4
|
+
include ForwardScopeMethods
|
5
|
+
include ForwardScopeParentMethods
|
6
|
+
include Mocks::ExampleMethods
|
7
|
+
|
8
|
+
def initialize(expected)
|
9
|
+
@expected = expected
|
10
|
+
@kwargs ||= {}
|
11
|
+
@args ||= []
|
12
|
+
@target_method_name ||= :call
|
13
|
+
end
|
14
|
+
|
15
|
+
def matches?(actual)
|
16
|
+
matches_for?(actual)
|
17
|
+
end
|
18
|
+
|
19
|
+
def description
|
20
|
+
<<~TXT.gsub(/\n+/, " ")
|
21
|
+
to pass the arguments to the constructor of instance and return
|
22
|
+
the value returned by the instance method
|
23
|
+
TXT
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/rspec/forward.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require "rspec"
|
2
2
|
require "rspec/mocks"
|
3
3
|
require "rspec/forward/version"
|
4
|
+
require "rspec/forward/core_extensions"
|
4
5
|
require "rspec/forward/forward_methods"
|
6
|
+
require "rspec/forward/forward_scope_methods"
|
7
|
+
require "rspec/forward/forward_scope_parent_methods"
|
5
8
|
require "rspec/forward/forward_to_instance"
|
6
9
|
require "rspec/forward/forward_to_instance_build"
|
10
|
+
require "rspec/forward/forward_to_scope"
|
7
11
|
|
8
12
|
module RSpec
|
9
13
|
module Forward
|
@@ -16,6 +20,10 @@ module RSpec
|
|
16
20
|
def forward_to_instance_build(expected)
|
17
21
|
ForwardToInstanceBuild.new(expected)
|
18
22
|
end
|
23
|
+
|
24
|
+
def forward_to_scope(expected)
|
25
|
+
ForwardToScope.new(expected)
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-forward
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marz Drel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-mocks
|
@@ -73,9 +73,13 @@ files:
|
|
73
73
|
- bin/console
|
74
74
|
- bin/setup
|
75
75
|
- lib/rspec/forward.rb
|
76
|
+
- lib/rspec/forward/core_extensions.rb
|
76
77
|
- lib/rspec/forward/forward_methods.rb
|
78
|
+
- lib/rspec/forward/forward_scope_methods.rb
|
79
|
+
- lib/rspec/forward/forward_scope_parent_methods.rb
|
77
80
|
- lib/rspec/forward/forward_to_instance.rb
|
78
81
|
- lib/rspec/forward/forward_to_instance_build.rb
|
82
|
+
- lib/rspec/forward/forward_to_scope.rb
|
79
83
|
- lib/rspec/forward/version.rb
|
80
84
|
- rspec-forward.gemspec
|
81
85
|
homepage:
|