sinclair 1.8.0 → 1.10.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/.circleci/config.yml +20 -6
- data/.rubocop.yml +5 -2
- data/Dockerfile +1 -1
- data/README.md +25 -1
- data/config/check_specs.yml +1 -0
- data/config/yardstick.yml +9 -1
- data/lib/sinclair/comparable/class_methods.rb +33 -0
- data/lib/sinclair/comparable.rb +47 -0
- data/lib/sinclair/config_builder.rb +4 -2
- data/lib/sinclair/configurable.rb +2 -0
- data/lib/sinclair/equals_checker.rb +110 -0
- data/lib/sinclair/matchers/add_class_method.rb +27 -36
- data/lib/sinclair/matchers/add_instance_method.rb +59 -59
- data/lib/sinclair/matchers/add_method.rb +33 -35
- data/lib/sinclair/matchers/change_class_method.rb +22 -16
- data/lib/sinclair/matchers/change_instance_method.rb +46 -16
- data/lib/sinclair/matchers.rb +2 -8
- data/lib/sinclair/method_builder/call_method_builder.rb +49 -0
- data/lib/sinclair/method_builder.rb +4 -1
- data/lib/sinclair/method_definition/call_definition.rb +52 -0
- data/lib/sinclair/method_definition/string_definition.rb +0 -2
- data/lib/sinclair/method_definition.rb +40 -24
- data/lib/sinclair/method_definitions.rb +21 -1
- data/lib/sinclair/options/builder.rb +8 -0
- data/lib/sinclair/options.rb +1 -13
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +2 -0
- data/sinclair.gemspec +1 -1
- data/spec/integration/readme/sinclair/comparable_spec.rb +24 -0
- data/spec/integration/yard/sinclair/comparable_spec.rb +24 -0
- data/spec/integration/yard/sinclair/equals_checker_spec.rb +51 -0
- data/spec/integration/yard/sinclair/matchers/change_class_method_spec.rb +24 -0
- data/spec/integration/yard/sinclair/matchers/change_instance_method_spec.rb +40 -0
- data/spec/lib/sinclair/comparable_spec.rb +202 -0
- data/spec/lib/sinclair/equals_checker_spec.rb +148 -0
- data/spec/lib/sinclair/method_builder/call_method_builder_spec.rb +76 -0
- data/spec/lib/sinclair/method_builder_spec.rb +63 -20
- data/spec/lib/sinclair/method_definition/call_definition_spec.rb +36 -0
- data/spec/lib/sinclair/method_definition_spec.rb +64 -0
- data/spec/lib/sinclair/method_definitions_spec.rb +79 -0
- data/spec/lib/sinclair/options/builder_spec.rb +13 -0
- data/spec/lib/sinclair/options/class_methods_spec.rb +23 -8
- data/spec/support/sample_model.rb +19 -0
- data/spec/support/shared_examples/attribute_accessor.rb +103 -0
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a3575c54efcf82ce477b70a6a34b6f6d37d6242b2c272454b141942ee90e381
|
4
|
+
data.tar.gz: fdae2230f95d50d239537f01dace6b278b7930cef96115667b424910d7106c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 424c2bd3b847482b32b45da5f3778c724c967fff11a14fdb5664e1d9b61fd0c484dc00e5f938739ffa46d3f04fcce7614ee9ed55b2fa3c3151af24a543b9d20e
|
7
|
+
data.tar.gz: 5094b1a51ae631f01163015b97131f7aaf78b349ca959f326823939de6b4205da8d64d750fad32837bdb28e74b76888644cf1518d9d51cdd2baba5318f61e595
|
data/.circleci/config.yml
CHANGED
@@ -7,8 +7,12 @@ workflows:
|
|
7
7
|
filters:
|
8
8
|
tags:
|
9
9
|
only: /.*/
|
10
|
+
- checks:
|
11
|
+
filters:
|
12
|
+
tags:
|
13
|
+
only: /.*/
|
10
14
|
- build-and-release:
|
11
|
-
requires: [test]
|
15
|
+
requires: [test, checks]
|
12
16
|
filters:
|
13
17
|
tags:
|
14
18
|
only: /\d+\.\d+\.\d+/
|
@@ -18,7 +22,7 @@ workflows:
|
|
18
22
|
jobs:
|
19
23
|
test:
|
20
24
|
docker:
|
21
|
-
- image: darthjee/circleci_ruby_270:1.
|
25
|
+
- image: darthjee/circleci_ruby_270:1.2.0
|
22
26
|
environment:
|
23
27
|
PROJECT: sinclair
|
24
28
|
steps:
|
@@ -32,12 +36,22 @@ jobs:
|
|
32
36
|
- run:
|
33
37
|
name: RSpec
|
34
38
|
command: bundle exec rspec
|
35
|
-
- run:
|
36
|
-
name: Rubocop
|
37
|
-
command: rubocop
|
38
39
|
- run:
|
39
40
|
name: Coverage Test Report
|
40
41
|
command: cc-test-reporter after-build --exit-code $?
|
42
|
+
checks:
|
43
|
+
docker:
|
44
|
+
- image: darthjee/circleci_ruby_270:1.2.0
|
45
|
+
environment:
|
46
|
+
PROJECT: sinclair
|
47
|
+
steps:
|
48
|
+
- checkout
|
49
|
+
- run:
|
50
|
+
name: Bundle Install
|
51
|
+
command: bundle install
|
52
|
+
- run:
|
53
|
+
name: Rubocop
|
54
|
+
command: rubocop
|
41
55
|
- run:
|
42
56
|
name: Yardstick coverage check
|
43
57
|
command: bundle exec rake verify_measurements
|
@@ -52,7 +66,7 @@ jobs:
|
|
52
66
|
command: check_specs
|
53
67
|
build-and-release:
|
54
68
|
docker:
|
55
|
-
- image: darthjee/circleci_ruby_270:1.
|
69
|
+
- image: darthjee/circleci_ruby_270:1.2.0
|
56
70
|
environment:
|
57
71
|
PROJECT: sinclair
|
58
72
|
steps:
|
data/.rubocop.yml
CHANGED
@@ -10,7 +10,7 @@ Metrics/BlockLength:
|
|
10
10
|
- 'spec/support/**/*.rb'
|
11
11
|
- '*.gemspec'
|
12
12
|
|
13
|
-
|
13
|
+
Layout/LineLength:
|
14
14
|
Max: 100
|
15
15
|
|
16
16
|
Lint/AmbiguousBlockAssociation:
|
@@ -20,6 +20,9 @@ Lint/AmbiguousBlockAssociation:
|
|
20
20
|
RSpec/AlignLeftLetBrace:
|
21
21
|
Enabled: true
|
22
22
|
|
23
|
+
RSpec/PredicateMatcher:
|
24
|
+
Exclude:
|
25
|
+
- 'spec/integration/yard/**/*_spec.rb'
|
23
26
|
|
24
27
|
RSpec/DescribedClass:
|
25
28
|
Exclude:
|
@@ -37,7 +40,7 @@ RSpec/MultipleExpectations:
|
|
37
40
|
- spec/lib/sinclair_spec.rb
|
38
41
|
|
39
42
|
RSpec/NestedGroups:
|
40
|
-
Max:
|
43
|
+
Max: 5
|
41
44
|
Exclude:
|
42
45
|
- spec/integration/yard/**/*.rb
|
43
46
|
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -13,9 +13,11 @@ This gem helps the creation of complex gems/concerns
|
|
13
13
|
that enables creation of methods on the fly through class
|
14
14
|
methods
|
15
15
|
|
16
|
+
Next release: [1.11.0](https://github.com/darthjee/sinclair/compare/1.10.0...master)
|
17
|
+
|
16
18
|
Yard Documentation
|
17
19
|
-------------------
|
18
|
-
[https://www.rubydoc.info/gems/sinclair/1.
|
20
|
+
[https://www.rubydoc.info/gems/sinclair/1.10.0](https://www.rubydoc.info/gems/sinclair/1.10.0)
|
19
21
|
|
20
22
|
Installation
|
21
23
|
---------------
|
@@ -475,6 +477,28 @@ Options allows projects to have an easy to configure option object
|
|
475
477
|
ConnectionOptions.new(invalid: 10) # raises Sinclair::Exception::InvalidOptions
|
476
478
|
```
|
477
479
|
|
480
|
+
### Sinclair::Comparable
|
481
|
+
Comparable allows a class to implement quickly a `==` method comparing given attributes
|
482
|
+
|
483
|
+
```ruby
|
484
|
+
class SampleModel
|
485
|
+
include Sinclair::Comparable
|
486
|
+
|
487
|
+
comparable_by :name
|
488
|
+
attr_reader :name, :age
|
489
|
+
|
490
|
+
def initialize(name: nil, age: nil)
|
491
|
+
@name = name
|
492
|
+
@age = age
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
model1 = model_class.new(name: 'jack', age: 21)
|
497
|
+
model2 = model_class.new(name: 'jack', age: 23)
|
498
|
+
|
499
|
+
model1 == model2 # returns true
|
500
|
+
```
|
501
|
+
|
478
502
|
RSspec matcher
|
479
503
|
---------------
|
480
504
|
|
data/config/check_specs.yml
CHANGED
data/config/yardstick.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
threshold:
|
1
|
+
threshold: 100
|
2
2
|
require_exact_threshold: false
|
3
3
|
rules:
|
4
4
|
ApiTag::Presence:
|
@@ -19,9 +19,14 @@ rules:
|
|
19
19
|
- Sinclair::Configurable#config
|
20
20
|
- Sinclair::Configurable#reset_config
|
21
21
|
- Sinclair::Configurable#configure
|
22
|
+
- Sinclair::EqualsChecker#initialize
|
22
23
|
- Sinclair::Options#==
|
23
24
|
- Sinclair::OptionsParser#options
|
24
25
|
- Sinclair::OptionsParser#options_object
|
26
|
+
- Sinclair::Matchers#add_method
|
27
|
+
- Sinclair::Matchers#add_class_method
|
28
|
+
- Sinclair::Matchers#change_method
|
29
|
+
- Sinclair::Matchers#change_class_method
|
25
30
|
ReturnTag:
|
26
31
|
enabled: true
|
27
32
|
exclude:
|
@@ -37,6 +42,7 @@ rules:
|
|
37
42
|
- Sinclair::ConfigFactory#initialize
|
38
43
|
- Sinclair::EnvSettable::Builder#initialize
|
39
44
|
- Sinclair::Exception::InvalidOptions#initialize
|
45
|
+
- Sinclair::EqualsChecker#initialize
|
40
46
|
- Sinclair::InputHash#initialize
|
41
47
|
- Sinclair::Matchers::AddInstanceMethodTo#initialize
|
42
48
|
- Sinclair::Matchers::AddClassMethodTo#initialize
|
@@ -48,7 +54,9 @@ rules:
|
|
48
54
|
- Sinclair::Matchers::ChangeInstanceMethodOn#initialize
|
49
55
|
- Sinclair::MethodBuilder
|
50
56
|
- Sinclair::MethodBuilder::Base#initialize
|
57
|
+
- Sinclair::MethodBuilder::Accessor#initialize
|
51
58
|
- Sinclair::MethodDefinition#initialize
|
59
|
+
- Sinclair::MethodDefinition::CallDefinition#initialize
|
52
60
|
- Sinclair::MethodDefinition::BlockDefinition#initialize
|
53
61
|
- Sinclair::MethodDefinition::StringDefinition#initialize
|
54
62
|
- Sinclair::Options#initialize
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Sinclair
|
4
|
+
module Comparable
|
5
|
+
# @api public
|
6
|
+
# @author darthjee
|
7
|
+
#
|
8
|
+
# Class methods of {Sinclair::Comparable}
|
9
|
+
#
|
10
|
+
# @example (see Sinclair::Comparable)
|
11
|
+
module ClassMethods
|
12
|
+
# Adds fields to the comparison algorythim
|
13
|
+
#
|
14
|
+
# @param attributes [Array<Symbol>] attributes to be added to comparison
|
15
|
+
#
|
16
|
+
# @see Sinclair::EqualsChecker
|
17
|
+
# @return (see Sinclair::EqualsChecker#add)
|
18
|
+
# @example (see Sinclair::Comparable)
|
19
|
+
def comparable_by(*attributes)
|
20
|
+
equals_checker.add(*attributes)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @api private
|
24
|
+
#
|
25
|
+
# Returns a comparable configured for the class
|
26
|
+
#
|
27
|
+
# @return [Sinclair::EqualsChecker]
|
28
|
+
def equals_checker
|
29
|
+
@equals_checker ||= Sinclair::EqualsChecker.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinclair/comparable/class_methods'
|
4
|
+
|
5
|
+
class Sinclair
|
6
|
+
# @api public
|
7
|
+
# @author darthjee
|
8
|
+
#
|
9
|
+
# Concern to be added on classes for easy +==+ comparison
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# class SampleModel
|
13
|
+
# include Sinclair::Comparable
|
14
|
+
#
|
15
|
+
# comparable_by :name
|
16
|
+
# attr_reader :name, :age
|
17
|
+
#
|
18
|
+
# def initialize(name: nil, age: nil)
|
19
|
+
# @name = name
|
20
|
+
# @age = age
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# model1 = model_class.new(name: 'jack', age: 21)
|
25
|
+
# model2 = model_class.new(name: 'jack', age: 23)
|
26
|
+
#
|
27
|
+
# model1 == model2 # returns true
|
28
|
+
module Comparable
|
29
|
+
extend ActiveSupport::Concern
|
30
|
+
|
31
|
+
# Checks if an instance of a comparable is equals another
|
32
|
+
#
|
33
|
+
# @param other [Object] an object that should be equal to comparable
|
34
|
+
#
|
35
|
+
# @return [Boolean]
|
36
|
+
# @example (see Sinclair::Comparable)
|
37
|
+
def ==(other)
|
38
|
+
klass = self.class
|
39
|
+
superklass = klass.superclass
|
40
|
+
|
41
|
+
return false unless klass.equals_checker.match?(self, other)
|
42
|
+
return true unless superklass.include?(Sinclair::Comparable)
|
43
|
+
|
44
|
+
superklass.equals_checker.match?(self, other)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -75,9 +75,11 @@ class Sinclair
|
|
75
75
|
# @todo get rid of @config_attributes when only
|
76
76
|
# Sinclair::ConfigClass are accepted
|
77
77
|
def method_included?(method_name)
|
78
|
+
klass = @config.class
|
79
|
+
|
78
80
|
@config_attributes.include?(method_name) ||
|
79
|
-
|
80
|
-
|
81
|
+
klass.is_a?(Sinclair::ConfigClass) &&
|
82
|
+
klass.config_attributes.include?(method_name)
|
81
83
|
end
|
82
84
|
end
|
83
85
|
end
|
@@ -81,6 +81,8 @@ class Sinclair
|
|
81
81
|
# @method as_options(options_hash = {})
|
82
82
|
# @api public
|
83
83
|
#
|
84
|
+
# Returns options with configurated values
|
85
|
+
#
|
84
86
|
# @param (see Sinclair::Config#as_options)
|
85
87
|
# @return (see Sinclair::Config#as_options)
|
86
88
|
# @example (see Sinclair::Config#as_options)
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
class Sinclair
|
6
|
+
# @api public
|
7
|
+
# @author darthjee
|
8
|
+
#
|
9
|
+
# Class responsible for checking if two instances of a class are the equals
|
10
|
+
#
|
11
|
+
# @example regular usage
|
12
|
+
# class SampleModel
|
13
|
+
# def initialize(name: nil, age: nil)
|
14
|
+
# @name = name
|
15
|
+
# @age = age
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# protected
|
19
|
+
#
|
20
|
+
# attr_reader :name
|
21
|
+
#
|
22
|
+
# private
|
23
|
+
#
|
24
|
+
# attr_reader :age
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# class OtherModel < SampleModel
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# checker = Sinclair::EqualsChecker.new(:name, :age)
|
31
|
+
#
|
32
|
+
# model1 = SampleModel.new(name: 'jack', age: 21)
|
33
|
+
# model2 = SampleModel.new(name: 'rose', age: 23)
|
34
|
+
#
|
35
|
+
# checker.match?(model1, model2) # returns false
|
36
|
+
#
|
37
|
+
# @example similar models
|
38
|
+
# checker = Sinclair::EqualsChecker.new(:name, :age)
|
39
|
+
#
|
40
|
+
# model1 = SampleModel.new(name: 'jack', age: 21)
|
41
|
+
# model2 = SampleModel.new(name: 'jack', age: 21)
|
42
|
+
#
|
43
|
+
# checker.match?(model1, model2) # returns true
|
44
|
+
#
|
45
|
+
# @example different classes
|
46
|
+
# checker = Sinclair::EqualsChecker.new(:name, :age)
|
47
|
+
#
|
48
|
+
# model1 = SampleModel.new(name: 'jack', age: 21)
|
49
|
+
# model2 = OtherModel.new(name: 'jack', age: 21)
|
50
|
+
#
|
51
|
+
# checker.match?(model1, model2) # returns false
|
52
|
+
class EqualsChecker
|
53
|
+
# @param attributes [Array<Symbol,String>] list of relevant attributes
|
54
|
+
def initialize(*attributes)
|
55
|
+
@attributes = Set.new(attributes.flatten)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Adds new fields to equals checker
|
59
|
+
#
|
60
|
+
# @param attributes [Array<Symbol,String>] list of relevant attributes
|
61
|
+
#
|
62
|
+
# @return [Set<Symbol,String>]
|
63
|
+
#
|
64
|
+
# @example adding fields to equal checker
|
65
|
+
# checker = Sinclair::EqualsChecker.new(:name)
|
66
|
+
#
|
67
|
+
# model1 = SampleModel.new(name: 'jack', age: 21)
|
68
|
+
# model2 = SampleModel.new(name: 'jack', age: 22)
|
69
|
+
#
|
70
|
+
# checker.match?(model1, model2) # returns true
|
71
|
+
#
|
72
|
+
# checker.add(:age)
|
73
|
+
#
|
74
|
+
# checker.match?(model1, model2) # returns false
|
75
|
+
def add(*attributes)
|
76
|
+
@attributes += Set.new(attributes.flatten)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns if 2 objects are equals
|
80
|
+
#
|
81
|
+
# The check takes into consideration:
|
82
|
+
# - They should be instances of the same class
|
83
|
+
# - Their attributes (method calls) should return the same value,
|
84
|
+
# for the configured attributes
|
85
|
+
# - Public and private attributes are checked
|
86
|
+
#
|
87
|
+
# @example (see Sinclair::EqualsChecker)
|
88
|
+
#
|
89
|
+
# @return [TrueClass,FalseClass]
|
90
|
+
def match?(model, other)
|
91
|
+
return false unless model.class == other.class
|
92
|
+
|
93
|
+
attributes.all? do |attr|
|
94
|
+
model.send(attr) == other.send(attr)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
attr_reader :attributes
|
101
|
+
|
102
|
+
# @private
|
103
|
+
# @api private
|
104
|
+
# @method attributes
|
105
|
+
#
|
106
|
+
# attributes relevant for checking difference
|
107
|
+
#
|
108
|
+
# @return [Set<Symbol,String>]
|
109
|
+
end
|
110
|
+
end
|
@@ -6,33 +6,33 @@ class Sinclair
|
|
6
6
|
# @author darthjee
|
7
7
|
#
|
8
8
|
# AddClassMethod is able to build an instance of {Sinclair::Matchers::AddClassMethodTo}
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
9
|
+
class AddClassMethod < AddMethod
|
10
|
+
# @method #to(target = nil)
|
11
|
+
# @example Checking if a class had a class method added
|
12
|
+
# RSpec.configure do |config|
|
13
|
+
# config.include Sinclair::Matchers
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# class MyModel
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# RSpec.describe 'MyBuilder' do
|
20
|
+
# let(:clazz) { Class.new(MyModel) }
|
21
|
+
#
|
22
|
+
# let(:block) do
|
23
|
+
# proc do
|
24
|
+
# clazz.define_singleton_method(:new_method) { 2 }
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# it do
|
29
|
+
# expect(&block).to add_class_method(:new_method).to(clazz)
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# # outputs
|
34
|
+
# # should add method class_method 'new_method' to #<Class:0x000055b4d0a25c80>
|
35
|
+
with_final_matcher :to, AddClassMethodTo
|
36
36
|
|
37
37
|
private
|
38
38
|
|
@@ -45,15 +45,6 @@ class Sinclair
|
|
45
45
|
'You should specify which class the method is being added to' \
|
46
46
|
"add_class_method(:#{method_name}).to(klass)"
|
47
47
|
end
|
48
|
-
|
49
|
-
# @private
|
50
|
-
#
|
51
|
-
# Class of the real matcher
|
52
|
-
#
|
53
|
-
# @return [Class<Sinclair::Matchers::Base>]
|
54
|
-
def add_method_to_class
|
55
|
-
AddClassMethodTo
|
56
|
-
end
|
57
48
|
end
|
58
49
|
end
|
59
50
|
end
|
@@ -7,56 +7,65 @@ class Sinclair
|
|
7
7
|
#
|
8
8
|
# AddInstanceMethod is able to build an instance of {Sinclair::Matchers::AddInstanceMethodTo}
|
9
9
|
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
10
|
+
class AddInstanceMethod < AddMethod
|
11
|
+
# @example Using inside RSpec and checking an instance method being added
|
12
|
+
# RSpec.configure do |config|
|
13
|
+
# config.include Sinclair::Matchers
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# class MyModel
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# RSpec.describe "MyBuilder" do
|
20
|
+
# let(:clazz) { Class.new(MyModel) }
|
21
|
+
# let(:builder) { Sinclair.new(clazz) }
|
22
|
+
#
|
23
|
+
# before do
|
24
|
+
# builder.add_method(:new_method, "2")
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# it do
|
28
|
+
# expect { builder.build }.to add_method(:new_method).to(clazz)
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # Outputs
|
33
|
+
# # 'should add method 'new_method' to #<Class:0x000056441bf46608> instances'
|
34
|
+
#
|
35
|
+
# @example Using inside RSpec and checking instance
|
36
|
+
# RSpec.configure do |config|
|
37
|
+
# config.include Sinclair::Matchers
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# class MyModel
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# RSpec.describe "MyBuilder" do
|
44
|
+
# let(:clazz) { Class.new(MyModel) }
|
45
|
+
# let(:builder) { Sinclair.new(clazz) }
|
46
|
+
# let(:instance) { clazz.new }
|
47
|
+
#
|
48
|
+
# before do
|
49
|
+
# builder.add_method(:the_method, "true")
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# it do
|
53
|
+
# expect { builder.build }.to add_method(:the_method).to(instance)
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# # Outputs
|
58
|
+
# # 'should add method 'the_method' to #<Class:0x000056441bf46608> instances'
|
59
|
+
with_final_matcher :to, AddInstanceMethodTo
|
60
|
+
|
61
|
+
# @method to(target = nil)
|
62
|
+
# @api public
|
63
|
+
#
|
64
|
+
# The matcher checks if an instance method was added to a class
|
65
|
+
#
|
66
|
+
# @param (see AddMethod#to)
|
67
|
+
#
|
68
|
+
# @return [AddClassMethodTo]
|
60
69
|
|
61
70
|
private
|
62
71
|
|
@@ -69,15 +78,6 @@ class Sinclair
|
|
69
78
|
'You should specify which instance the method is being added to' \
|
70
79
|
"add_method(:#{method_name}).to(instance)"
|
71
80
|
end
|
72
|
-
|
73
|
-
# @private
|
74
|
-
#
|
75
|
-
# Class of the real matcher
|
76
|
-
#
|
77
|
-
# @return [Class<Sinclair::Matchers::Base>]
|
78
|
-
def add_method_to_class
|
79
|
-
AddInstanceMethodTo
|
80
|
-
end
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|