yardcheck 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.buildkite/pipeline.yml +2 -2
- data/.ruby-version +1 -1
- data/lib/yardcheck/method_call.rb +9 -1
- data/lib/yardcheck/method_tracer.rb +4 -1
- data/lib/yardcheck/observation.rb +4 -0
- data/lib/yardcheck/proxy.rb +12 -5
- data/lib/yardcheck/version.rb +1 -1
- data/lib/yardcheck/violation.rb +32 -10
- data/spec/integration/yardcheck_spec.rb +4 -2
- data/spec/unit/yardcheck/method_tracer_spec.rb +2 -2
- data/spec/unit/yardcheck/runner_spec.rb +17 -7
- data/test_app/Gemfile.lock +13 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe668ef28d9117e65a7ef3507e3d43c5f19c817d
|
4
|
+
data.tar.gz: 3b03b4b15147cd4db2b7594b02e43f04f5d9f1e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15f0d9b8d5bf900d1b8f090738bdb44f0a5d53d60636afe9b0a9e17ca1612902f4d3a96eaaa71e6a6ece59b46be94a3c0ccebf8c298e9551cfc92e0aa2880bee
|
7
|
+
data.tar.gz: 0411aa5a17f544b2f5ae3389ee8b84739c3cad5faeeb574b9794bc41ad321992a7465dd54deb0455485610145de0b69143ecc8fa9033cd5d7ab6c989afe72f1c
|
data/.buildkite/pipeline.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
steps:
|
2
|
-
- command: "build/run 2.
|
2
|
+
- command: "build/run 2.4.1 'rspec'"
|
3
3
|
label: ":rspec: RSpec"
|
4
4
|
agents:
|
5
5
|
- queue=elastic
|
6
6
|
|
7
7
|
- name: ':rubocop: Rubocop'
|
8
|
-
command: build/run 2.
|
8
|
+
command: build/run 2.4.1 rubocop
|
9
9
|
agents:
|
10
10
|
- queue=elastic
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
@@ -7,7 +7,7 @@ module Yardcheck
|
|
7
7
|
:selector,
|
8
8
|
:namespace,
|
9
9
|
:params,
|
10
|
-
:
|
10
|
+
:example_metadata
|
11
11
|
)
|
12
12
|
|
13
13
|
def self.process(params:, **attributes)
|
@@ -19,6 +19,14 @@ module Yardcheck
|
|
19
19
|
new(params: params, **attributes)
|
20
20
|
end
|
21
21
|
|
22
|
+
def example_location
|
23
|
+
example_metadata.fetch(:location)
|
24
|
+
end
|
25
|
+
|
26
|
+
def example_id
|
27
|
+
example_metadata.fetch(:id)
|
28
|
+
end
|
29
|
+
|
22
30
|
def method_identifier
|
23
31
|
[namespace, selector, scope]
|
24
32
|
end
|
@@ -108,7 +108,10 @@ module Yardcheck
|
|
108
108
|
scope: event.defined_class.__send__(:singleton_class?) ? :class : :instance,
|
109
109
|
selector: event.method_id,
|
110
110
|
namespace: event.defined_class,
|
111
|
-
|
111
|
+
example_metadata: {
|
112
|
+
location: RSpec.current_example.location,
|
113
|
+
id: RSpec.current_example.id
|
114
|
+
}
|
112
115
|
}
|
113
116
|
end
|
114
117
|
|
data/lib/yardcheck/proxy.rb
CHANGED
@@ -11,7 +11,7 @@ module Yardcheck
|
|
11
11
|
undef_method :!
|
12
12
|
|
13
13
|
def method_missing(method_name, *args, &block)
|
14
|
-
if
|
14
|
+
if respond_to_missing?(method_name, true)
|
15
15
|
@target.__send__(method_name, *args, &block)
|
16
16
|
else
|
17
17
|
::Object
|
@@ -21,13 +21,20 @@ module Yardcheck
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
def target_respond_to?(method_name)
|
24
|
+
def respond_to_missing?(method_name, include_all = false)
|
27
25
|
::Object
|
28
26
|
.instance_method(:respond_to?)
|
29
27
|
.bind(@target)
|
30
|
-
.call(method_name,
|
28
|
+
.call(method_name, include_all)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def object_dispatch(receiver, method_name, *params)
|
34
|
+
::Object
|
35
|
+
.instance_method(method_name)
|
36
|
+
.bind(receiver)
|
37
|
+
.call(*params)
|
31
38
|
end
|
32
39
|
end # Proxy
|
33
40
|
end # Yardcheck
|
data/lib/yardcheck/version.rb
CHANGED
data/lib/yardcheck/violation.rb
CHANGED
@@ -5,9 +5,14 @@ module Yardcheck
|
|
5
5
|
extend Color
|
6
6
|
include Color
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(
|
9
|
+
observation,
|
10
|
+
test_locations = [observation.test_location],
|
11
|
+
test_ids = [observation.test_id]
|
12
|
+
)
|
9
13
|
@observation = observation
|
10
14
|
@test_locations = test_locations.sort.uniq
|
15
|
+
@test_ids = test_ids.sort.uniq
|
11
16
|
end
|
12
17
|
|
13
18
|
def offense
|
@@ -16,23 +21,26 @@ module Yardcheck
|
|
16
21
|
|
17
22
|
location_hint = indent(grey("source: #{observation.source_location}"))
|
18
23
|
test_lines = test_locations.map { |l| " - #{l}" }.join("\n")
|
24
|
+
|
19
25
|
tests_block = "tests:\n#{test_lines}"
|
20
26
|
test_hint = indent(grey(tests_block))
|
21
27
|
|
22
|
-
"
|
28
|
+
rerun_block = indent(grey("rerun with:\n #{rerun_command}"))
|
29
|
+
|
30
|
+
"#{explanation}\n\n#{location_hint}\n#{test_hint}\n#{rerun_block}\n#{source}\n"
|
23
31
|
end
|
24
32
|
|
25
33
|
def combine(other)
|
26
34
|
fail 'Cannot combine' unless combine_with?(other)
|
27
35
|
|
28
|
-
with_tests(other
|
36
|
+
with_tests(other)
|
29
37
|
end
|
30
38
|
|
31
39
|
def combination_identifier
|
32
40
|
combine_requirements.map(&method(:__send__))
|
33
41
|
end
|
34
42
|
|
35
|
-
attr_reader :test_locations
|
43
|
+
attr_reader :test_locations, :test_ids
|
36
44
|
|
37
45
|
private
|
38
46
|
|
@@ -43,7 +51,11 @@ module Yardcheck
|
|
43
51
|
end
|
44
52
|
|
45
53
|
def with_tests(other_test_locations)
|
46
|
-
self.class.new(observation, test_locations + other_test_locations)
|
54
|
+
self.class.new(observation, test_locations + other_test_locations, test_ids + other.test_ids)
|
55
|
+
end
|
56
|
+
|
57
|
+
def rerun_command
|
58
|
+
"rspec #{test_ids.map { |id| "'#{id}'" }.join(' ')}"
|
47
59
|
end
|
48
60
|
|
49
61
|
def indent(string)
|
@@ -70,7 +82,11 @@ module Yardcheck
|
|
70
82
|
"#{yellow('%<signature>s')} but observed " \
|
71
83
|
"#{red('%<observed_type>s')}"
|
72
84
|
|
73
|
-
def initialize(
|
85
|
+
def initialize(
|
86
|
+
observation,
|
87
|
+
test_locations = [observation.test_location],
|
88
|
+
test_ids = [observation.test_id]
|
89
|
+
)
|
74
90
|
super
|
75
91
|
end
|
76
92
|
|
@@ -103,10 +119,15 @@ module Yardcheck
|
|
103
119
|
class Param < self
|
104
120
|
include Equalizer.new(:name, :observation)
|
105
121
|
|
106
|
-
def initialize(
|
122
|
+
def initialize(
|
123
|
+
name,
|
124
|
+
observation,
|
125
|
+
test_locations = [observation.test_location],
|
126
|
+
test_ids = [observation.test_id]
|
127
|
+
)
|
107
128
|
@name = name
|
108
129
|
|
109
|
-
super(observation, test_locations)
|
130
|
+
super(observation, test_locations, test_ids)
|
110
131
|
end
|
111
132
|
|
112
133
|
FORMAT =
|
@@ -136,11 +157,12 @@ module Yardcheck
|
|
136
157
|
%i[name shorthand signature observed_type]
|
137
158
|
end
|
138
159
|
|
139
|
-
def with_tests(
|
160
|
+
def with_tests(other)
|
140
161
|
self.class.new(
|
141
162
|
name,
|
142
163
|
observation,
|
143
|
-
test_locations +
|
164
|
+
test_locations + other.test_locations,
|
165
|
+
test_ids + other.test_ids
|
144
166
|
)
|
145
167
|
end
|
146
168
|
|
@@ -42,8 +42,10 @@ RSpec.describe 'test app integration' do
|
|
42
42
|
|
43
43
|
it 'reports expectations' do
|
44
44
|
aggregate_failures do
|
45
|
-
expect_report('Expected TestApp::Namespace#add to return String but observed
|
46
|
-
expect_report(
|
45
|
+
expect_report('Expected TestApp::Namespace#add to return String but observed Integer')
|
46
|
+
expect_report(
|
47
|
+
'Expected #<Class:TestApp::Namespace>#add to return String but observed Integer'
|
48
|
+
)
|
47
49
|
expect_report(
|
48
50
|
'Expected TestApp::Namespace#documents_relative ' \
|
49
51
|
'to return TestApp::Namespace::Child but observed String'
|
@@ -42,7 +42,7 @@ RSpec.describe Yardcheck::MethodTracer do
|
|
42
42
|
namespace: Foo.singleton_class,
|
43
43
|
params: { baz: 'Hello' },
|
44
44
|
return_value: 'HELLO',
|
45
|
-
|
45
|
+
example_metadata: { location: RSpec.current_example.location, id: RSpec.current_example.id }
|
46
46
|
),
|
47
47
|
Yardcheck::MethodCall::Return.process(
|
48
48
|
scope: :instance,
|
@@ -50,7 +50,7 @@ RSpec.describe Yardcheck::MethodTracer do
|
|
50
50
|
namespace: Foo,
|
51
51
|
params: { baz: 'Hello' },
|
52
52
|
return_value: 'HELLO',
|
53
|
-
|
53
|
+
example_metadata: { location: RSpec.current_example.location, id: RSpec.current_example.id }
|
54
54
|
)
|
55
55
|
])
|
56
56
|
end
|
@@ -25,7 +25,7 @@ RSpec.describe Yardcheck::Runner do
|
|
25
25
|
namespace: TestApp::Namespace,
|
26
26
|
params: { left: 'foo', right: 3 },
|
27
27
|
return_value: 5,
|
28
|
-
|
28
|
+
example_metadata: { location: 'test_app_spec.rb:1', id: 'test_app_spec.rb[1:1]' }
|
29
29
|
),
|
30
30
|
Yardcheck::MethodCall::Return.process(
|
31
31
|
scope: :class,
|
@@ -33,18 +33,20 @@ RSpec.describe Yardcheck::Runner do
|
|
33
33
|
namespace: TestApp::Namespace.singleton_class,
|
34
34
|
params: { left: 2, right: 3 },
|
35
35
|
return_value: 5,
|
36
|
-
|
36
|
+
example_metadata: { location: 'test_app_spec.rb:2', id: 'test_app_spec.rb[1:2]' }
|
37
37
|
)
|
38
38
|
]
|
39
39
|
end
|
40
40
|
|
41
41
|
let(:output) do
|
42
42
|
<<~MSG
|
43
|
-
Expected #<Class:TestApp::Namespace>#add to return String but observed
|
43
|
+
Expected #<Class:TestApp::Namespace>#add to return String but observed Integer
|
44
44
|
|
45
45
|
source: ./test_app/lib/test_app.rb:15
|
46
46
|
tests:
|
47
47
|
- test_app_spec.rb:2
|
48
|
+
rerun with:
|
49
|
+
rspec 'test_app_spec.rb[1:2]'
|
48
50
|
|
49
51
|
# Singleton method with correct param definition and incorrect return
|
50
52
|
#
|
@@ -61,6 +63,8 @@ RSpec.describe Yardcheck::Runner do
|
|
61
63
|
source: ./test_app/lib/test_app.rb:25
|
62
64
|
tests:
|
63
65
|
- test_app_spec.rb:1
|
66
|
+
rerun with:
|
67
|
+
rspec 'test_app_spec.rb[1:1]'
|
64
68
|
|
65
69
|
# Instance method with correct param definition and incorrect return
|
66
70
|
#
|
@@ -72,11 +76,13 @@ RSpec.describe Yardcheck::Runner do
|
|
72
76
|
left + right
|
73
77
|
end
|
74
78
|
|
75
|
-
Expected TestApp::Namespace#add to return String but observed
|
79
|
+
Expected TestApp::Namespace#add to return String but observed Integer
|
76
80
|
|
77
81
|
source: ./test_app/lib/test_app.rb:25
|
78
82
|
tests:
|
79
83
|
- test_app_spec.rb:1
|
84
|
+
rerun with:
|
85
|
+
rspec 'test_app_spec.rb[1:1]'
|
80
86
|
|
81
87
|
# Instance method with correct param definition and incorrect return
|
82
88
|
#
|
@@ -118,7 +124,7 @@ RSpec.describe Yardcheck::Runner do
|
|
118
124
|
namespace: TestApp::Namespace,
|
119
125
|
params: { left: 'foo', right: 3 },
|
120
126
|
return_value: 'valid return type',
|
121
|
-
|
127
|
+
example_metadata: { location: 'test_app_spec.rb:1', id: 'test_app_spec.rb[1:1]' }
|
122
128
|
),
|
123
129
|
Yardcheck::MethodCall::Return.process(
|
124
130
|
scope: :instance,
|
@@ -126,7 +132,7 @@ RSpec.describe Yardcheck::Runner do
|
|
126
132
|
namespace: TestApp::Namespace,
|
127
133
|
params: { left: 'foo', right: 3 },
|
128
134
|
return_value: 'valid return type',
|
129
|
-
|
135
|
+
example_metadata: { location: 'test_app_spec.rb:2', id: 'test_app_spec.rb[1:2]' }
|
130
136
|
),
|
131
137
|
Yardcheck::MethodCall::Return.process(
|
132
138
|
scope: :instance,
|
@@ -134,7 +140,7 @@ RSpec.describe Yardcheck::Runner do
|
|
134
140
|
namespace: TestApp::Namespace,
|
135
141
|
params: { left: 1, right: 'now this one is wrong' },
|
136
142
|
return_value: 'valid return type',
|
137
|
-
|
143
|
+
example_metadata: { location: 'test_app_spec.rb:3', id: 'test_app_spec.rb[1:3]' }
|
138
144
|
)
|
139
145
|
]
|
140
146
|
end
|
@@ -147,6 +153,8 @@ RSpec.describe Yardcheck::Runner do
|
|
147
153
|
tests:
|
148
154
|
- test_app_spec.rb:1
|
149
155
|
- test_app_spec.rb:2
|
156
|
+
rerun with:
|
157
|
+
rspec 'test_app_spec.rb[1:1]' 'test_app_spec.rb[1:2]'
|
150
158
|
|
151
159
|
# Instance method with correct param definition and incorrect return
|
152
160
|
#
|
@@ -163,6 +171,8 @@ RSpec.describe Yardcheck::Runner do
|
|
163
171
|
source: ./test_app/lib/test_app.rb:25
|
164
172
|
tests:
|
165
173
|
- test_app_spec.rb:3
|
174
|
+
rerun with:
|
175
|
+
rspec 'test_app_spec.rb[1:3]'
|
166
176
|
|
167
177
|
# Instance method with correct param definition and incorrect return
|
168
178
|
#
|
data/test_app/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
yardcheck (0.0.
|
4
|
+
yardcheck (0.0.3)
|
5
5
|
anima (~> 0.3)
|
6
6
|
coderay (~> 1.1)
|
7
7
|
concord (~> 0.1)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
concord (0.1.5)
|
27
27
|
adamantium (~> 0.2.0)
|
28
28
|
equalizer (~> 0.0.9)
|
29
|
-
diff-lcs (1.
|
29
|
+
diff-lcs (1.3)
|
30
30
|
equalizer (0.0.11)
|
31
31
|
ice_nine (0.11.2)
|
32
32
|
memoizable (0.4.2)
|
@@ -41,19 +41,19 @@ GEM
|
|
41
41
|
pry-byebug (3.4.2)
|
42
42
|
byebug (~> 9.0)
|
43
43
|
pry (~> 0.10)
|
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.6.0)
|
45
|
+
rspec-core (~> 3.6.0)
|
46
|
+
rspec-expectations (~> 3.6.0)
|
47
|
+
rspec-mocks (~> 3.6.0)
|
48
|
+
rspec-core (3.6.0)
|
49
|
+
rspec-support (~> 3.6.0)
|
50
|
+
rspec-expectations (3.6.0)
|
51
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
-
rspec-support (~> 3.
|
53
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.6.0)
|
53
|
+
rspec-mocks (3.6.0)
|
54
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
-
rspec-support (~> 3.
|
56
|
-
rspec-support (3.
|
55
|
+
rspec-support (~> 3.6.0)
|
56
|
+
rspec-support (3.6.0)
|
57
57
|
slop (3.6.0)
|
58
58
|
thread_safe (0.3.6)
|
59
59
|
yard (0.9.8)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yardcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.6.11
|
180
180
|
signing_key:
|
181
181
|
specification_version: 4
|
182
182
|
summary: Validate YARD docs by running specs
|