sinclair 1.6.6 → 1.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/check_specs.yml +3 -0
- data/config/yardstick.yml +7 -1
- data/lib/sinclair/matchers.rb +37 -10
- data/lib/sinclair/matchers/add_class_method.rb +16 -13
- data/lib/sinclair/matchers/add_class_method_to.rb +9 -23
- data/lib/sinclair/matchers/add_instance_method.rb +16 -18
- data/lib/sinclair/matchers/add_instance_method_to.rb +12 -16
- data/lib/sinclair/matchers/add_method.rb +13 -30
- data/lib/sinclair/matchers/add_method_to.rb +4 -56
- data/lib/sinclair/matchers/base.rb +45 -0
- data/lib/sinclair/matchers/change_class_method.rb +42 -0
- data/lib/sinclair/matchers/change_class_method_on.rb +64 -0
- data/lib/sinclair/matchers/change_instance_method.rb +42 -0
- data/lib/sinclair/matchers/change_instance_method_on.rb +98 -0
- data/lib/sinclair/matchers/change_method_on.rb +25 -0
- data/lib/sinclair/matchers/method_to.rb +82 -0
- data/lib/sinclair/version.rb +1 -1
- data/spec/lib/sinclair/matchers/add_class_method_to_spec.rb +40 -16
- data/spec/lib/sinclair/matchers/add_instance_method_to_spec.rb +36 -12
- data/spec/lib/sinclair/matchers/change_class_method_on_spec.rb +138 -0
- data/spec/lib/sinclair/matchers/change_class_method_spec.rb +38 -0
- data/spec/lib/sinclair/matchers/change_instance_method_on_spec.rb +149 -0
- data/spec/lib/sinclair/matchers/change_instance_method_spec.rb +38 -0
- data/spec/lib/sinclair/matchers_spec.rb +30 -0
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecab9b7d077c8641fa413a2e8e8b673e2412a900f5a9322b81dff53e47a7c51d
|
4
|
+
data.tar.gz: 816d60a81f193492df1fa44cc5ae405e8521c4dca914ff862171e3381e9e4c7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75b74e8881fe963bccff4b154727e354eeb9189d73774f86cbc53bbcea345d89cb34cc09fcd38db5136e9aad819f90179707ff7e6016e749c4fd336ef680169d
|
7
|
+
data.tar.gz: 195d742d548b6d9cfe218dc23ba8ae8194882abf0203b5cda7c90f4f06f122e1768da71d7f51e05ca3f32563ef5335046ab0f5d5e9513fcaf1dd36eec50059cf
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ methods
|
|
15
15
|
|
16
16
|
Yard Documentation
|
17
17
|
-------------------
|
18
|
-
[https://www.rubydoc.info/gems/sinclair/1.6.
|
18
|
+
[https://www.rubydoc.info/gems/sinclair/1.6.7](https://www.rubydoc.info/gems/sinclair/1.6.7)
|
19
19
|
|
20
20
|
Installation
|
21
21
|
---------------
|
data/config/check_specs.yml
CHANGED
data/config/yardstick.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
threshold:
|
1
|
+
threshold: 99.8
|
2
2
|
require_exact_threshold: false
|
3
3
|
rules:
|
4
4
|
ApiTag::Presence:
|
@@ -28,6 +28,8 @@ rules:
|
|
28
28
|
- Sinclair::Matchers::AddClassMethodTo#raise_block_syntax_error
|
29
29
|
- Sinclair::Matchers::AddInstanceMethodTo#raise_block_syntax_error
|
30
30
|
- Sinclair::MethodBuilder#build_from_definition
|
31
|
+
- Sinclair::Matchers::ChangeClassMethodOn#raise_block_syntax_error
|
32
|
+
- Sinclair::Matchers::ChangeInstanceMethodOn#raise_block_syntax_error
|
31
33
|
Summary::Presence:
|
32
34
|
enabled: true
|
33
35
|
exclude:
|
@@ -36,10 +38,14 @@ rules:
|
|
36
38
|
- Sinclair::EnvSettable::Builder#initialize
|
37
39
|
- Sinclair::Exception::InvalidOptions#initialize
|
38
40
|
- Sinclair::InputHash#initialize
|
41
|
+
- Sinclair::Matchers::AddInstanceMethodTo#initialize
|
39
42
|
- Sinclair::Matchers::AddClassMethodTo#initialize
|
40
43
|
- Sinclair::Matchers::AddInstanceMethodTo#instance
|
41
44
|
- Sinclair::Matchers::AddMethod#initialize
|
42
45
|
- Sinclair::Matchers::AddMethodTo#initialize
|
46
|
+
- Sinclair::Matchers::Base#initialize
|
47
|
+
- Sinclair::Matchers::ChangeClassMethodOn#initialize
|
48
|
+
- Sinclair::Matchers::ChangeInstanceMethodOn#initialize
|
43
49
|
- Sinclair::MethodBuilder
|
44
50
|
- Sinclair::MethodBuilder::Base#initialize
|
45
51
|
- Sinclair::MethodDefinition#initialize
|
data/lib/sinclair/matchers.rb
CHANGED
@@ -28,12 +28,19 @@ class Sinclair
|
|
28
28
|
# end
|
29
29
|
# end
|
30
30
|
module Matchers
|
31
|
-
autoload :
|
32
|
-
autoload :AddInstanceMethod,
|
33
|
-
autoload :AddClassMethod,
|
34
|
-
autoload :
|
35
|
-
autoload :
|
36
|
-
autoload :
|
31
|
+
autoload :Base, 'sinclair/matchers/base'
|
32
|
+
autoload :AddInstanceMethod, 'sinclair/matchers/add_instance_method'
|
33
|
+
autoload :AddClassMethod, 'sinclair/matchers/add_class_method'
|
34
|
+
autoload :AddMethod, 'sinclair/matchers/add_method'
|
35
|
+
autoload :AddMethodTo, 'sinclair/matchers/add_method_to'
|
36
|
+
autoload :AddInstanceMethodTo, 'sinclair/matchers/add_instance_method_to'
|
37
|
+
autoload :AddClassMethodTo, 'sinclair/matchers/add_class_method_to'
|
38
|
+
autoload :ChangeClassMethod, 'sinclair/matchers/change_class_method'
|
39
|
+
autoload :ChangeInstanceMethod, 'sinclair/matchers/change_instance_method'
|
40
|
+
autoload :ChangeMethodOn, 'sinclair/matchers/change_method_on'
|
41
|
+
autoload :ChangeClassMethodOn, 'sinclair/matchers/change_class_method_on'
|
42
|
+
autoload :ChangeInstanceMethodOn, 'sinclair/matchers/change_instance_method_on'
|
43
|
+
autoload :MethodTo, 'sinclair/matchers/method_to'
|
37
44
|
|
38
45
|
# DSL to AddInstanceMethod
|
39
46
|
#
|
@@ -41,8 +48,8 @@ class Sinclair
|
|
41
48
|
# @example (see Sinclair::Matchers::AddInstanceMethod#to)
|
42
49
|
#
|
43
50
|
# @return [AddInstanceMethod] RSpec Matcher
|
44
|
-
def add_method(
|
45
|
-
Sinclair::Matchers::AddInstanceMethod.new(
|
51
|
+
def add_method(method_name)
|
52
|
+
Sinclair::Matchers::AddInstanceMethod.new(method_name)
|
46
53
|
end
|
47
54
|
|
48
55
|
# DSL to AddClassMethod
|
@@ -51,8 +58,28 @@ class Sinclair
|
|
51
58
|
# @example (see Sinclair::Matchers::AddClassMethod#to)
|
52
59
|
#
|
53
60
|
# @return [AddClassMethod] RSpec Matcher
|
54
|
-
def add_class_method(
|
55
|
-
Sinclair::Matchers::AddClassMethod.new(
|
61
|
+
def add_class_method(method_name)
|
62
|
+
Sinclair::Matchers::AddClassMethod.new(method_name)
|
63
|
+
end
|
64
|
+
|
65
|
+
# DSL to ChangeInstanceMethod
|
66
|
+
#
|
67
|
+
# @example (see Sinclair::Matchers)
|
68
|
+
# @example (see Sinclair::Matchers::ChangeInstanceMethod#to)
|
69
|
+
#
|
70
|
+
# @return [ChangeInstanceMethod] RSpec Matcher
|
71
|
+
def change_method(method_name)
|
72
|
+
Sinclair::Matchers::ChangeInstanceMethod.new(method_name)
|
73
|
+
end
|
74
|
+
|
75
|
+
# DSL to ChangeClassMethod
|
76
|
+
#
|
77
|
+
# @example (see Sinclair::Matchers)
|
78
|
+
# @example (see Sinclair::Matchers::ChangeClassMethod#to)
|
79
|
+
#
|
80
|
+
# @return [ChangeClassMethod] RSpec Matcher
|
81
|
+
def change_class_method(method_name)
|
82
|
+
Sinclair::Matchers::ChangeClassMethod.new(method_name)
|
56
83
|
end
|
57
84
|
end
|
58
85
|
end
|
@@ -31,25 +31,28 @@ class Sinclair
|
|
31
31
|
#
|
32
32
|
# # outputs
|
33
33
|
# # should add method class_method 'new_method' to #<Class:0x000055b4d0a25c80>
|
34
|
-
class AddClassMethod <
|
35
|
-
|
34
|
+
class AddClassMethod < Base
|
35
|
+
include AddMethod
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# @private
|
36
40
|
#
|
37
|
-
#
|
41
|
+
# Error description on wrong usage
|
38
42
|
#
|
39
|
-
# @
|
40
|
-
def
|
41
|
-
|
42
|
-
"add_class_method(:#{
|
43
|
+
# @return String
|
44
|
+
def matcher_error
|
45
|
+
'You should specify which class the method is being added to' \
|
46
|
+
"add_class_method(:#{method_name}).to(klass)"
|
43
47
|
end
|
44
48
|
|
45
|
-
#
|
49
|
+
# @private
|
46
50
|
#
|
47
|
-
#
|
48
|
-
# class where the method should be added to
|
51
|
+
# Class of the real matcher
|
49
52
|
#
|
50
|
-
# @return [
|
51
|
-
def
|
52
|
-
AddClassMethodTo
|
53
|
+
# @return [Class<Sinclair::Matchers::Base>]
|
54
|
+
def add_method_to_class
|
55
|
+
AddClassMethodTo
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
@@ -36,55 +36,41 @@ class Sinclair
|
|
36
36
|
# @param [Class] klass
|
37
37
|
# Class where the class method should be added to
|
38
38
|
#
|
39
|
-
# @param
|
40
|
-
def initialize(klass,
|
39
|
+
# @param method_name [SYmbol,String] method name
|
40
|
+
def initialize(klass, method_name)
|
41
41
|
@klass = klass
|
42
|
-
super(
|
42
|
+
super(method_name)
|
43
43
|
end
|
44
44
|
|
45
45
|
# Return expectaton description
|
46
46
|
#
|
47
47
|
# @return [String]
|
48
48
|
def description
|
49
|
-
"add method
|
49
|
+
"add class method '#{method_name}' to #{klass}"
|
50
50
|
end
|
51
51
|
|
52
52
|
# Returns message on expectation failure
|
53
53
|
#
|
54
54
|
# @return [String]
|
55
55
|
def failure_message_for_should
|
56
|
-
"expected
|
57
|
-
"#{
|
56
|
+
"expected class method '#{method_name}' to be added to #{klass} but " \
|
57
|
+
"#{initial_state ? 'it already existed' : "it didn't"}"
|
58
58
|
end
|
59
59
|
|
60
60
|
# Returns message on expectation failure for negative expectation
|
61
61
|
#
|
62
62
|
# @return [String]
|
63
63
|
def failure_message_for_should_not
|
64
|
-
"expected
|
64
|
+
"expected class method '#{method_name}' not to be added to #{klass} but it was"
|
65
65
|
end
|
66
66
|
|
67
|
-
alias failure_message failure_message_for_should
|
68
|
-
alias failure_message_when_negated failure_message_for_should_not
|
69
|
-
|
70
|
-
protected
|
71
|
-
|
72
|
-
# @method klass
|
73
|
-
# @private
|
74
|
-
# @api private
|
75
|
-
#
|
76
|
-
# Class where class method should be added to
|
77
|
-
#
|
78
|
-
# @return [Class]
|
79
|
-
attr_reader :klass
|
80
|
-
|
81
67
|
private
|
82
68
|
|
83
69
|
# Checks if class has instance method defined
|
84
70
|
#
|
85
71
|
# @return [Boolean]
|
86
|
-
def
|
87
|
-
klass.methods(false).include?(
|
72
|
+
def state
|
73
|
+
klass.methods(false).include?(method_name.to_sym)
|
88
74
|
end
|
89
75
|
|
90
76
|
# Raises when block was not given
|
@@ -55,30 +55,28 @@ class Sinclair
|
|
55
55
|
#
|
56
56
|
# # Outputs
|
57
57
|
# # 'should add method 'the_method' to #<Class:0x000056441bf46608> instances'
|
58
|
-
class AddInstanceMethod <
|
59
|
-
|
58
|
+
class AddInstanceMethod < Base
|
59
|
+
include AddMethod
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# @private
|
60
64
|
#
|
61
|
-
#
|
65
|
+
# Error description on wrong usage
|
62
66
|
#
|
63
|
-
# @
|
64
|
-
def
|
65
|
-
|
66
|
-
"add_method(:#{
|
67
|
+
# @return String
|
68
|
+
def matcher_error
|
69
|
+
'You should specify which instance the method is being added to' \
|
70
|
+
"add_method(:#{method_name}).to(instance)"
|
67
71
|
end
|
68
72
|
|
69
|
-
#
|
70
|
-
#
|
71
|
-
# @overload to(klass)
|
72
|
-
# @param [Class] klass
|
73
|
-
# class where the method should be added to
|
73
|
+
# @private
|
74
74
|
#
|
75
|
-
#
|
76
|
-
# @param [Object] instance
|
77
|
-
# instance of the class where the method should be added to
|
75
|
+
# Class of the real matcher
|
78
76
|
#
|
79
|
-
# @return [
|
80
|
-
def
|
81
|
-
AddInstanceMethodTo
|
77
|
+
# @return [Class<Sinclair::Matchers::Base>]
|
78
|
+
def add_method_to_class
|
79
|
+
AddInstanceMethodTo
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
@@ -30,54 +30,50 @@ class Sinclair
|
|
30
30
|
# end
|
31
31
|
# end
|
32
32
|
class AddInstanceMethodTo < AddMethodTo
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# @overload initialize(klass, method)
|
33
|
+
# @overload initialize(klass, method_name)
|
36
34
|
# @param [Class] klass
|
37
35
|
# class where the method should be added to
|
38
36
|
#
|
39
|
-
# @overload initialize(instance,
|
37
|
+
# @overload initialize(instance, method_name)
|
40
38
|
# @param [Object] instance
|
41
39
|
# instance of the class where the method should be added to
|
42
40
|
#
|
43
|
-
# @param
|
44
|
-
def initialize(target,
|
41
|
+
# @param method_name [Symbol,String] method name
|
42
|
+
def initialize(target, method_name)
|
45
43
|
if target.is_a?(Class)
|
46
44
|
@klass = target
|
47
45
|
else
|
48
46
|
@instance = target
|
49
47
|
end
|
50
|
-
super(
|
48
|
+
super(method_name)
|
51
49
|
end
|
52
50
|
|
53
51
|
# Returnst expectaton description
|
54
52
|
#
|
55
53
|
# @return [String]
|
56
54
|
def description
|
57
|
-
"add method '#{
|
55
|
+
"add method '#{method_name}' to #{klass} instances"
|
58
56
|
end
|
59
57
|
|
60
58
|
# Returns message on expectation failure
|
61
59
|
#
|
62
60
|
# @return [String]
|
63
61
|
def failure_message_for_should
|
64
|
-
"expected '#{
|
65
|
-
"#{
|
62
|
+
"expected '#{method_name}' to be added to #{klass} but " \
|
63
|
+
"#{initial_state ? 'it already existed' : "it didn't"}"
|
66
64
|
end
|
67
65
|
|
68
66
|
# Returns message on expectation failure for negative expectation
|
69
67
|
#
|
70
68
|
# @return [String]
|
71
69
|
def failure_message_for_should_not
|
72
|
-
"expected '#{
|
70
|
+
"expected '#{method_name}' not to be added to #{klass} but it was"
|
73
71
|
end
|
74
72
|
|
75
|
-
alias failure_message failure_message_for_should
|
76
|
-
alias failure_message_when_negated failure_message_for_should_not
|
77
|
-
|
78
73
|
protected
|
79
74
|
|
80
75
|
# @method instance
|
76
|
+
# @api private
|
81
77
|
# @private
|
82
78
|
#
|
83
79
|
# Instance of the class where the method should be added
|
@@ -101,8 +97,8 @@ class Sinclair
|
|
101
97
|
# Checks if class has instance method defined
|
102
98
|
#
|
103
99
|
# @return [Boolean]
|
104
|
-
def
|
105
|
-
klass.method_defined?(
|
100
|
+
def state
|
101
|
+
klass.method_defined?(method_name)
|
106
102
|
end
|
107
103
|
|
108
104
|
# @private
|
@@ -3,43 +3,26 @@
|
|
3
3
|
class Sinclair
|
4
4
|
module Matchers
|
5
5
|
# @api private
|
6
|
-
# @author darthjee
|
7
|
-
# @abstract
|
8
6
|
#
|
9
|
-
#
|
10
|
-
|
11
|
-
# @
|
12
|
-
def initialize(method)
|
13
|
-
@method = method.to_sym
|
14
|
-
end
|
15
|
-
|
16
|
-
# definition needed for block matchers
|
7
|
+
# Commone methods for matchers
|
8
|
+
module AddMethod
|
9
|
+
# @api public
|
17
10
|
#
|
18
|
-
#
|
19
|
-
def supports_block_expectations?
|
20
|
-
true
|
21
|
-
end
|
22
|
-
|
23
|
-
# Checkes if another instnce is equal self
|
11
|
+
# Builds final matcher
|
24
12
|
#
|
25
|
-
# @return [
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
other.method == method
|
13
|
+
# @return [Sinclair::Matchers::Base]
|
14
|
+
def to(target = nil)
|
15
|
+
add_method_to_class.new(target, method_name)
|
30
16
|
end
|
31
17
|
|
32
|
-
|
33
|
-
|
34
|
-
protected
|
35
|
-
|
36
|
-
# @method method
|
37
|
-
# @private
|
18
|
+
# @abstract
|
38
19
|
#
|
39
|
-
#
|
20
|
+
# Raise a warning on the usage as this is only a builder
|
40
21
|
#
|
41
|
-
# @
|
42
|
-
|
22
|
+
# @raise SyntaxError
|
23
|
+
def matches?(_actual)
|
24
|
+
raise SyntaxError, matcher_error
|
25
|
+
end
|
43
26
|
end
|
44
27
|
end
|
45
28
|
end
|
@@ -7,49 +7,8 @@ class Sinclair
|
|
7
7
|
# @abstract
|
8
8
|
#
|
9
9
|
# Base class for add_method_to matcher
|
10
|
-
class AddMethodTo <
|
11
|
-
|
12
|
-
def initialize(method)
|
13
|
-
@method = method
|
14
|
-
end
|
15
|
-
|
16
|
-
# Checks if expectation is true or not
|
17
|
-
#
|
18
|
-
# @return [Boolean] expectation check
|
19
|
-
def matches?(event_proc)
|
20
|
-
return false unless event_proc.is_a?(Proc)
|
21
|
-
|
22
|
-
raise_block_syntax_error if block_given?
|
23
|
-
perform_change(event_proc)
|
24
|
-
added?
|
25
|
-
end
|
26
|
-
|
27
|
-
# definition needed for block matchers
|
28
|
-
def supports_block_expectations?
|
29
|
-
true
|
30
|
-
end
|
31
|
-
|
32
|
-
# Checkes if another instnce is equal self
|
33
|
-
#
|
34
|
-
# @return [Boolean]
|
35
|
-
def equal?(other)
|
36
|
-
return unless other.class == self.class
|
37
|
-
|
38
|
-
other.method == method &&
|
39
|
-
other.klass == klass
|
40
|
-
end
|
41
|
-
|
42
|
-
alias == equal?
|
43
|
-
|
44
|
-
protected
|
45
|
-
|
46
|
-
# @method method
|
47
|
-
# @private
|
48
|
-
#
|
49
|
-
# The method, to be checked, name
|
50
|
-
#
|
51
|
-
# @return [Symbol]
|
52
|
-
attr_reader :method
|
10
|
+
class AddMethodTo < Base
|
11
|
+
include MethodTo
|
53
12
|
|
54
13
|
private
|
55
14
|
|
@@ -58,19 +17,8 @@ class Sinclair
|
|
58
17
|
# Checks if a method was added (didn't exist before)
|
59
18
|
#
|
60
19
|
# @return Boolean
|
61
|
-
def
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
# @private
|
66
|
-
#
|
67
|
-
# Call block to check if it aded a method or not
|
68
|
-
#
|
69
|
-
# @return [Boolan]
|
70
|
-
def perform_change(event_proc)
|
71
|
-
@initial_state = method_defined?
|
72
|
-
event_proc.call
|
73
|
-
@final_state = method_defined?
|
20
|
+
def check
|
21
|
+
!initial_state && final_state
|
74
22
|
end
|
75
23
|
end
|
76
24
|
end
|