sinclair 1.6.2 → 1.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +37 -2
  3. data/Dockerfile +2 -2
  4. data/README.md +6 -2
  5. data/config/check_specs.yml +3 -0
  6. data/config/yardstick.yml +8 -1
  7. data/lib/sinclair/matchers.rb +37 -10
  8. data/lib/sinclair/matchers/add_class_method.rb +16 -13
  9. data/lib/sinclair/matchers/add_class_method_to.rb +9 -23
  10. data/lib/sinclair/matchers/add_instance_method.rb +16 -18
  11. data/lib/sinclair/matchers/add_instance_method_to.rb +12 -16
  12. data/lib/sinclair/matchers/add_method.rb +13 -30
  13. data/lib/sinclair/matchers/add_method_to.rb +4 -56
  14. data/lib/sinclair/matchers/base.rb +45 -0
  15. data/lib/sinclair/matchers/change_class_method.rb +42 -0
  16. data/lib/sinclair/matchers/change_class_method_on.rb +64 -0
  17. data/lib/sinclair/matchers/change_instance_method.rb +42 -0
  18. data/lib/sinclair/matchers/change_instance_method_on.rb +98 -0
  19. data/lib/sinclair/matchers/change_method_on.rb +25 -0
  20. data/lib/sinclair/matchers/method_to.rb +82 -0
  21. data/lib/sinclair/options.rb +47 -46
  22. data/lib/sinclair/options/builder.rb +1 -1
  23. data/lib/sinclair/options/class_methods.rb +99 -0
  24. data/lib/sinclair/version.rb +1 -1
  25. data/spec/integration/readme/sinclair/options_spec.rb +8 -0
  26. data/spec/integration/yard/sinclair/options_parser_spec.rb +9 -0
  27. data/spec/integration/yard/sinclair/options_spec.rb +17 -6
  28. data/spec/lib/sinclair/matchers/add_class_method_to_spec.rb +40 -16
  29. data/spec/lib/sinclair/matchers/add_instance_method_to_spec.rb +36 -12
  30. data/spec/lib/sinclair/matchers/change_class_method_on_spec.rb +138 -0
  31. data/spec/lib/sinclair/matchers/change_class_method_spec.rb +38 -0
  32. data/spec/lib/sinclair/matchers/change_instance_method_on_spec.rb +149 -0
  33. data/spec/lib/sinclair/matchers/change_instance_method_spec.rb +38 -0
  34. data/spec/lib/sinclair/matchers_spec.rb +30 -0
  35. data/spec/lib/sinclair/options/builder_spec.rb +16 -8
  36. data/spec/lib/sinclair/options/class_methods_spec.rb +255 -0
  37. data/spec/lib/sinclair/options_spec.rb +90 -78
  38. data/spec/support/models/builder_options.rb +7 -0
  39. data/spec/support/models/open_options.rb +7 -0
  40. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15c8c49649134851cc9f1fb6a92d4ea19ff82cc2e68ce2d09339987b2623a5d4
4
- data.tar.gz: def1468dbdf88b1f700edc6fd172cc6dc06d56b9aba07171cb6d7c3a7bcdc32e
3
+ metadata.gz: ecab9b7d077c8641fa413a2e8e8b673e2412a900f5a9322b81dff53e47a7c51d
4
+ data.tar.gz: 816d60a81f193492df1fa44cc5ae405e8521c4dca914ff862171e3381e9e4c7f
5
5
  SHA512:
6
- metadata.gz: fcaf42f0c6ee8b2cdb4986e003b487f1f53184d9486c9479477fcfe4fb38550ff9deecc4b3029da563812179152ecee68c379b5673f60eedfb7df9a4f945b30c
7
- data.tar.gz: 622f77edaeb7d9b247a15c071ecb80981e82d915124dbeb57851c86153c1790bd301ea7be067b9020281dc9aeecd6cec54ec4403a74972bf7f8d9d89cf444020
6
+ metadata.gz: 75b74e8881fe963bccff4b154727e354eeb9189d73774f86cbc53bbcea345d89cb34cc09fcd38db5136e9aad819f90179707ff7e6016e749c4fd336ef680169d
7
+ data.tar.gz: 195d742d548b6d9cfe218dc23ba8ae8194882abf0203b5cda7c90f4f06f122e1768da71d7f51e05ca3f32563ef5335046ab0f5d5e9513fcaf1dd36eec50059cf
@@ -1,8 +1,24 @@
1
1
  version: 2
2
+ workflows:
3
+ version: 2
4
+ test-and-build:
5
+ jobs:
6
+ - test:
7
+ filters:
8
+ tags:
9
+ only: /.*/
10
+ - build-and-release:
11
+ requires: [test]
12
+ filters:
13
+ tags:
14
+ only: /\d+\.\d+\.\d+/
15
+ branches:
16
+ only:
17
+ - master
2
18
  jobs:
3
- build:
19
+ test:
4
20
  docker:
5
- - image: darthjee/circleci_ruby_gems:0.5.0
21
+ - image: darthjee/circleci_ruby_gems:0.5.3
6
22
  environment:
7
23
  PROJECT: sinclair
8
24
  steps:
@@ -34,3 +50,22 @@ jobs:
34
50
  - run:
35
51
  name: Check unit tests
36
52
  command: check_specs
53
+ build-and-release:
54
+ docker:
55
+ - image: darthjee/circleci_ruby_gems:0.5.3
56
+ environment:
57
+ PROJECT: sinclair
58
+ steps:
59
+ - checkout
60
+ - run:
61
+ name: Bundle Install
62
+ command: bundle install
63
+ - run:
64
+ name: Signin
65
+ command: build_gem.sh signin
66
+ - run:
67
+ name: Build Gem
68
+ command: build_gem.sh build
69
+ - run:
70
+ name: Push Gem
71
+ command: build_gem.sh push
data/Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
- FROM darthjee/scripts:0.1.7 as scripts
1
+ FROM darthjee/scripts:0.1.8 as scripts
2
2
 
3
- FROM darthjee/ruby_gems:0.5.0 as base
3
+ FROM darthjee/ruby_gems:0.5.3 as base
4
4
 
5
5
  COPY --chown=app:app ./ /home/app/app/
6
6
 
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.2](https://www.rubydoc.info/gems/sinclair/1.6.2)
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
  ---------------
@@ -409,7 +409,7 @@ Configurations can also be done through custom classes
409
409
  Client.config.url # returns 'http://interstella.com:8080'
410
410
  ```
411
411
 
412
- ### Sinclair::Settable
412
+ ### Sinclair::EnvSettable
413
413
 
414
414
  Settable allows classes to extract configuration from environments through
415
415
  a simple meta-programable way
@@ -452,6 +452,8 @@ Options allows projects to have an easy to configure option object
452
452
  ```ruby
453
453
  class ConnectionOptions < Sinclair::Options
454
454
  with_options :timeout, :retries, port: 443, protocol: 'https'
455
+
456
+ # skip_validation if you dont want to validate intialization arguments
455
457
  end
456
458
 
457
459
  options = ConnectionOptions.new(
@@ -463,6 +465,8 @@ Options allows projects to have an easy to configure option object
463
465
  options.retries # returns nil
464
466
  options.protocol # returns 'http'
465
467
  options.port # returns 443
468
+
469
+ ConnectionOptions.new(invalid: 10) # raises Sinclair::Exception::InvalidOptions
466
470
  ```
467
471
 
468
472
  RSspec matcher
@@ -4,3 +4,6 @@ ignore:
4
4
  - lib/sinclair/version.rb
5
5
  - lib/sinclair/method_builder/base.rb
6
6
  - lib/sinclair/exception.rb
7
+ - lib/sinclair/matchers/method_to.rb
8
+ - lib/sinclair/matchers/base.rb
9
+ - lib/sinclair/matchers/change_method_on.rb
@@ -1,4 +1,4 @@
1
- threshold: 100
1
+ threshold: 99.8
2
2
  require_exact_threshold: false
3
3
  rules:
4
4
  ApiTag::Presence:
@@ -19,6 +19,7 @@ rules:
19
19
  - Sinclair::Configurable#config
20
20
  - Sinclair::Configurable#reset_config
21
21
  - Sinclair::Configurable#configure
22
+ - Sinclair::Options#==
22
23
  - Sinclair::OptionsParser#options
23
24
  - Sinclair::OptionsParser#options_object
24
25
  ReturnTag:
@@ -27,6 +28,8 @@ rules:
27
28
  - Sinclair::Matchers::AddClassMethodTo#raise_block_syntax_error
28
29
  - Sinclair::Matchers::AddInstanceMethodTo#raise_block_syntax_error
29
30
  - Sinclair::MethodBuilder#build_from_definition
31
+ - Sinclair::Matchers::ChangeClassMethodOn#raise_block_syntax_error
32
+ - Sinclair::Matchers::ChangeInstanceMethodOn#raise_block_syntax_error
30
33
  Summary::Presence:
31
34
  enabled: true
32
35
  exclude:
@@ -35,10 +38,14 @@ rules:
35
38
  - Sinclair::EnvSettable::Builder#initialize
36
39
  - Sinclair::Exception::InvalidOptions#initialize
37
40
  - Sinclair::InputHash#initialize
41
+ - Sinclair::Matchers::AddInstanceMethodTo#initialize
38
42
  - Sinclair::Matchers::AddClassMethodTo#initialize
39
43
  - Sinclair::Matchers::AddInstanceMethodTo#instance
40
44
  - Sinclair::Matchers::AddMethod#initialize
41
45
  - Sinclair::Matchers::AddMethodTo#initialize
46
+ - Sinclair::Matchers::Base#initialize
47
+ - Sinclair::Matchers::ChangeClassMethodOn#initialize
48
+ - Sinclair::Matchers::ChangeInstanceMethodOn#initialize
42
49
  - Sinclair::MethodBuilder
43
50
  - Sinclair::MethodBuilder::Base#initialize
44
51
  - Sinclair::MethodDefinition#initialize
@@ -28,12 +28,19 @@ class Sinclair
28
28
  # end
29
29
  # end
30
30
  module Matchers
31
- autoload :AddMethod, 'sinclair/matchers/add_method'
32
- autoload :AddInstanceMethod, 'sinclair/matchers/add_instance_method'
33
- autoload :AddClassMethod, 'sinclair/matchers/add_class_method'
34
- autoload :AddMethodTo, 'sinclair/matchers/add_method_to'
35
- autoload :AddInstanceMethodTo, 'sinclair/matchers/add_instance_method_to'
36
- autoload :AddClassMethodTo, 'sinclair/matchers/add_class_method_to'
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(method)
45
- Sinclair::Matchers::AddInstanceMethod.new(method)
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(method)
55
- Sinclair::Matchers::AddClassMethod.new(method)
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 < AddMethod
35
- # @abstract
34
+ class AddClassMethod < Base
35
+ include AddMethod
36
+
37
+ private
38
+
39
+ # @private
36
40
  #
37
- # Raise a warning on the usage as this is only a builder for AddClassMethodTo
41
+ # Error description on wrong usage
38
42
  #
39
- # @raise SyntaxError
40
- def matches?(_actual)
41
- raise SyntaxError, 'You should specify which class the method is being added to' \
42
- "add_class_method(:#{method}).to(klass)"
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
- # Creates a matcher {AddClassMethodTo}
49
+ # @private
46
50
  #
47
- # @param target [Class]
48
- # class where the method should be added to
51
+ # Class of the real matcher
49
52
  #
50
- # @return [AddClassMethodTo] the correct matcher
51
- def to(target = nil)
52
- AddClassMethodTo.new(target, method)
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 method [SYmbol,String] method name
40
- def initialize(klass, method)
39
+ # @param method_name [SYmbol,String] method name
40
+ def initialize(klass, method_name)
41
41
  @klass = klass
42
- super(method)
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 class_method '#{method}' to #{klass}"
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 class_method '#{method}' to be added to #{klass} but " \
57
- "#{@initial_state ? 'it already existed' : "it didn't"}"
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 class_method '#{method}' not to be added to #{klass} but it was"
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 method_defined?
87
- klass.methods(false).include?(method.to_sym)
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 < AddMethod
59
- # @abstract
58
+ class AddInstanceMethod < Base
59
+ include AddMethod
60
+
61
+ private
62
+
63
+ # @private
60
64
  #
61
- # Raise a warning on the usage as this is only a builder for {AddInstanceMethodTo}
65
+ # Error description on wrong usage
62
66
  #
63
- # @raise SyntaxError
64
- def matches?(_actual)
65
- raise SyntaxError, 'You should specify which instance the method is being added to' \
66
- "add_method(:#{method}).to(instance)"
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
- # Creates a matcher AddInstanceMethodTo
70
- #
71
- # @overload to(klass)
72
- # @param [Class] klass
73
- # class where the method should be added to
73
+ # @private
74
74
  #
75
- # @overload to(instance)
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 [AddInstanceMethodTo] the correct matcher
80
- def to(target = nil)
81
- AddInstanceMethodTo.new(target, method)
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
- # Returns a new instance of AddInstanceMethodTo
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, method)
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 method [Symbol,String] method name
44
- def initialize(target, method)
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(method)
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 '#{method}' to #{klass} instances"
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 '#{method}' to be added to #{klass} but " \
65
- "#{@initial_state ? 'it already existed' : "it didn't"}"
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 '#{method}' not to be added to #{klass} but it was"
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 method_defined?
105
- klass.method_defined?(method)
100
+ def state
101
+ klass.method_defined?(method_name)
106
102
  end
107
103
 
108
104
  # @private