uptyped 0.1.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 +7 -0
- data/Rakefile +2 -0
- data/lib/uptyped/inherited_interface.rb +51 -0
- data/lib/uptyped/interface_validator.rb +67 -0
- data/lib/uptyped/version.rb +3 -0
- data/lib/uptyped.rb +4 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d501e11734efcd96ece3c6bf2ef54adc439ef93d
|
4
|
+
data.tar.gz: 5db79e56fb78309fbcf9572c5f557c7e486dadda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b70ada3e4685accedc1929b630788e895cc24d5a97859f2b5eb4e64df552b8ee9555107fca8c16f686bf6609cd27cb670e45bdcced674927e051aac095ed238e
|
7
|
+
data.tar.gz: 01a99e7c9befdcfd389ca36a60a3e1d25c5a6d4904305f2ba98324f8e21fda7338ce4b2786ae5f9933d76d79280ad498bc36d10231547c46644573fa6feb5768
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "uptyped/version"
|
2
|
+
require "uptyped/interface_validator"
|
3
|
+
|
4
|
+
module Uptyped
|
5
|
+
module InheritedInterface
|
6
|
+
def self.included(scope)
|
7
|
+
scope.include_context "inherits interface"
|
8
|
+
end
|
9
|
+
|
10
|
+
shared_context 'inherits interface' do
|
11
|
+
unless described_class.superclass == Object
|
12
|
+
describe "public methods:" do
|
13
|
+
it "should contain only public instance methods that are inherited" do
|
14
|
+
validator = Uptyped::InterfaceValidator.new(described_class)
|
15
|
+
|
16
|
+
expect(validator.public_instance_method_errors).to be_empty, validator.public_instance_method_errors
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should contain only public class methods that are inherited" do
|
20
|
+
validator = Uptyped::InterfaceValidator.new(described_class)
|
21
|
+
expect(validator.public_class_method_errors).to be_empty, validator.public_class_method_errors
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "arity:" do
|
26
|
+
context "instance methods" do
|
27
|
+
it "should have the same public instance method arity as its superclass" do
|
28
|
+
validator = Uptyped::InterfaceValidator.new(described_class)
|
29
|
+
|
30
|
+
expect(validator.instance_method_arity_errors).to be_empty, validator.instance_method_arity_errors
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "class methods" do
|
35
|
+
it "should have the same public instance method arity as its superclass" do
|
36
|
+
validator = Uptyped::InterfaceValidator.new(described_class)
|
37
|
+
|
38
|
+
expect(validator.class_method_arity_errors).to be_empty, validator.class_method_arity_errors
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.configure
|
46
|
+
RSpec.configure do |config|
|
47
|
+
config.include InheritedInterface
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class Uptyped::InterfaceValidator
|
2
|
+
attr_reader :public_instance_method_errors, :public_class_method_errors, :instance_method_arity_errors, :class_method_arity_errors
|
3
|
+
|
4
|
+
def initialize(klass)
|
5
|
+
@validated_class = klass
|
6
|
+
@public_instance_method_errors = []
|
7
|
+
@public_class_method_errors = []
|
8
|
+
@instance_method_arity_errors = []
|
9
|
+
@class_method_arity_errors = []
|
10
|
+
check_for_extra_subclass_instance_methods
|
11
|
+
check_for_extra_subclass_class_methods
|
12
|
+
check_instance_methods_for_arity_mismatches
|
13
|
+
check_class_methods_for_arity_mismatches
|
14
|
+
end
|
15
|
+
|
16
|
+
def success?
|
17
|
+
(public_instance_method_errors + public_class_method_errors + instance_method_arity_errors + class_method_arity_errors).empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def validated_class
|
23
|
+
@validated_class
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_for_extra_subclass_instance_methods
|
27
|
+
extra_instance_methods = validated_class.instance_methods - validated_class.superclass.instance_methods
|
28
|
+
unless extra_instance_methods.empty?
|
29
|
+
error_message = "expected #{validated_class} to have the same public instance methods as #{validated_class.superclass}, got #{extra_instance_methods}."
|
30
|
+
@public_instance_method_errors << error_message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_for_extra_subclass_class_methods
|
35
|
+
local_public_methods = validated_class.methods
|
36
|
+
superclass_public_methods = validated_class.superclass.methods
|
37
|
+
extra_public_methods = local_public_methods - superclass_public_methods
|
38
|
+
unless extra_public_methods.empty?
|
39
|
+
error_message = "expected #{validated_class} to have the same public class methods as #{validated_class.superclass}, got #{extra_public_methods}."
|
40
|
+
@public_class_method_errors << error_message
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def check_instance_methods_for_arity_mismatches
|
45
|
+
(validated_class.superclass.instance_methods - validated_class.superclass.superclass.instance_methods).push(:initialize).each do |method|
|
46
|
+
klass_arity = validated_class.instance_method(method).arity
|
47
|
+
superklass_arity = validated_class.superclass.instance_method(method).arity
|
48
|
+
|
49
|
+
unless klass_arity == superklass_arity
|
50
|
+
error_message = "#{validated_class}##{method.to_s} takes #{klass_arity} argument(s) while #{validated_class.superclass}##{method.to_s} takes #{superklass_arity} argument(s)."
|
51
|
+
instance_method_arity_errors << error_message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_class_methods_for_arity_mismatches
|
57
|
+
(validated_class.superclass.methods - validated_class.superclass.superclass.methods).each do |method|
|
58
|
+
klass_arity = validated_class.method(method).arity
|
59
|
+
superklass_arity = validated_class.superclass.method(method).arity
|
60
|
+
|
61
|
+
unless klass_arity == superklass_arity
|
62
|
+
error_message = "#{validated_class}.#{method.to_s} takes #{klass_arity} argument(s) while #{validated_class.superclass}.#{method.to_s} takes #{superklass_arity} argument(s)."
|
63
|
+
@class_method_arity_errors << error_message
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/uptyped.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uptyped
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeffrey Matthias
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shoulda-matchers
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.99'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.99'
|
69
|
+
description: Currently adds tests to anything that doesn't inherit from Object.
|
70
|
+
email:
|
71
|
+
- jeffrey@sendgrid.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Rakefile
|
77
|
+
- lib/uptyped.rb
|
78
|
+
- lib/uptyped/inherited_interface.rb
|
79
|
+
- lib/uptyped/interface_validator.rb
|
80
|
+
- lib/uptyped/version.rb
|
81
|
+
homepage: https://github.com/sendgrid/uptyped
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Adds tests to enforce that interface is only inherited from superclass.
|
105
|
+
test_files: []
|