method_log 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +4 -6
- data/bin/method_log +22 -6
- data/lib/method_log/api.rb +16 -15
- data/lib/method_log/commit.rb +14 -2
- data/lib/method_log/method_commit.rb +11 -2
- data/lib/method_log/method_definition.rb +1 -1
- data/lib/method_log/method_diff.rb +1 -1
- data/lib/method_log/method_finder.rb +5 -3
- data/lib/method_log/repository.rb +15 -9
- data/lib/method_log/scope.rb +5 -5
- data/lib/method_log/source_file.rb +5 -5
- data/lib/method_log/version.rb +1 -1
- data/method_log.gemspec +2 -0
- data/spec/api_spec.rb +83 -95
- data/spec/commit_spec.rb +71 -73
- data/spec/method_commit_spec.rb +27 -23
- data/spec/method_definition_spec.rb +28 -24
- data/spec/method_diff_spec.rb +13 -9
- data/spec/method_finder_spec.rb +215 -219
- data/spec/scope_spec.rb +91 -89
- data/spec/source_file_spec.rb +41 -39
- data/spec/spec_helper.rb +25 -0
- metadata +3 -3
data/spec/commit_spec.rb
CHANGED
@@ -1,99 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
require 'method_log/repository'
|
2
4
|
require 'method_log/commit'
|
3
5
|
require 'method_log/source_file'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
module MethodLog
|
8
|
+
describe Commit do
|
9
|
+
let(:sha) { 'b54d38bbd989f4b54c38fd77767d89d1' }
|
10
|
+
let(:commit) { Commit.new(sha) }
|
11
|
+
let(:commit_with_same_sha) { Commit.new(sha) }
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
it 'is equal to another commit with same SHA' do
|
14
|
+
expect(commit).to eq(commit_with_same_sha)
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
it 'has same hash as another commit with same SHA' do
|
18
|
+
expect(commit.hash).to eq(commit_with_same_sha.hash)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
context 'using a real git repository' do
|
22
|
+
let(:repository_path) { File.expand_path('../repository.git', __FILE__) }
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
before do
|
25
|
+
FileUtils.mkdir_p(repository_path)
|
26
|
+
Rugged::Repository.init_at(repository_path, :bare)
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
after do
|
30
|
+
FileUtils.rm_rf(repository_path)
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
it 'stores source files added to a commit in the repository against a real commit' do
|
34
|
+
source_one = source(path: 'path/to/source_one.rb', source: 'source-one')
|
35
|
+
source_two = source(path: 'path/to/source_two.rb', source: 'source-two')
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
commit.add(source_one)
|
37
|
-
commit.add(source_two)
|
38
|
-
commit.apply
|
37
|
+
repository = Repository.new(repository_path)
|
38
|
+
commit = repository.commit(source_one, source_two)
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
repository = Repository.new(repository_path)
|
41
|
+
commit = repository.commits.first
|
42
|
+
expect(commit.source_files.to_a).to eq([source_one, source_two])
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
it 'only includes source files with ruby file extension' do
|
46
|
+
source_file = source(path: 'path/to/source_one.py', source: 'source-file')
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
commit.add(source_file)
|
51
|
-
commit.apply
|
48
|
+
repository = Repository.new(repository_path)
|
49
|
+
commit = repository.commit(source_file)
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
repository = Repository.new(repository_path)
|
52
|
+
commit = repository.commits.first
|
53
|
+
expect(commit.source_files.to_a).to be_empty
|
54
|
+
end
|
57
55
|
|
58
|
-
|
59
|
-
|
56
|
+
it 'indicates whether it contains a given source file' do
|
57
|
+
source_file = source(path: 'path/to/source.rb', source: 'source-file')
|
58
|
+
another_source_file = source(path: 'path/to/another_source.rb', source: 'another-source-file')
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
repository = Repository.new(repository_path)
|
61
|
+
commit = repository.commit(source_file)
|
62
|
+
source_file = commit.source_files.first
|
63
|
+
another_commit = repository.commit(another_source_file)
|
64
|
+
another_source_file = another_commit.source_files.first
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
expect(commit.contains?(source_file)).to be_true
|
70
|
-
end
|
66
|
+
repository = Repository.new(repository_path)
|
67
|
+
commit = repository.commits.to_a.last
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
expect(commit.contains?(source_file)).to be_true
|
70
|
+
expect(commit.contains?(another_source_file)).to be_false
|
71
|
+
end
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
commit.apply(user: user)
|
73
|
+
it 'makes author available' do
|
74
|
+
user = { email: 'test@example.com', name: 'test', time: Time.now.round }
|
75
|
+
source_file = source(path: 'path/to/source.rb', source: 'source')
|
80
76
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
repository = Repository.new(repository_path)
|
78
|
+
commit = repository.commit(source_file, user: user)
|
79
|
+
|
80
|
+
repository = Repository.new(repository_path)
|
81
|
+
commit = repository.commits.first
|
82
|
+
expect(commit.author).to eq(user)
|
83
|
+
end
|
85
84
|
|
86
|
-
|
87
|
-
|
85
|
+
it 'makes message available' do
|
86
|
+
source_file = source(path: 'path/to/source.rb', source: 'source')
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
commit.add(source_file)
|
92
|
-
commit.apply(message: 'commit-message')
|
88
|
+
repository = Repository.new(repository_path)
|
89
|
+
commit = repository.commit(source_file, message: 'commit-message')
|
93
90
|
|
94
|
-
|
95
|
-
|
96
|
-
|
91
|
+
repository = Repository.new(repository_path)
|
92
|
+
commit = repository.commits.first
|
93
|
+
expect(commit.message).to eq('commit-message')
|
94
|
+
end
|
97
95
|
end
|
98
96
|
end
|
99
|
-
end
|
97
|
+
end
|
data/spec/method_commit_spec.rb
CHANGED
@@ -1,33 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
require 'method_log/method_commit'
|
2
4
|
require 'method_log/commit'
|
3
5
|
require 'method_log/source_file'
|
4
6
|
require 'method_log/method_definition'
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
module MethodLog
|
9
|
+
describe MethodCommit do
|
10
|
+
let(:commit) { Commit.new(nil) }
|
11
|
+
let(:source_file) { source(path: '/path/to/source.rb', source: "line 0\nline 1\nline 2\n") }
|
12
|
+
let(:method_definition) { MethodDefinition.new(source_file, 0..1) }
|
13
|
+
let(:method_commit) {
|
14
|
+
MethodCommit.new(commit, method_definition)
|
15
|
+
}
|
16
|
+
let(:method_commit_with_same_commit_and_method_definition) {
|
17
|
+
MethodCommit.new(commit, method_definition)
|
18
|
+
}
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
it 'is equal to another method commit with same commit and method definition' do
|
21
|
+
expect(method_commit).to eq(method_commit_with_same_commit_and_method_definition)
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
it 'has same hash as another method commit with same commit and method definition' do
|
25
|
+
expect(method_commit.hash).to eq(method_commit_with_same_commit_and_method_definition.hash)
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
it 'returns method source with trailing newline' do
|
29
|
+
expect(method_commit.method_source).to eq("line 0\nline 1\n")
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
it 'returns nil if no method definition' do
|
33
|
+
method_commit = MethodCommit.new(commit, method_definition = nil)
|
34
|
+
expect(method_commit.method_source).to be_nil
|
35
|
+
end
|
32
36
|
end
|
33
|
-
end
|
37
|
+
end
|
@@ -1,34 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
require 'method_log/method_definition'
|
2
4
|
require 'method_log/source_file'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
|
6
|
+
module MethodLog
|
7
|
+
describe MethodDefinition do
|
8
|
+
let(:source_file) do
|
9
|
+
source(path: 'path/to/source.rb', source: %{
|
10
|
+
class Foo
|
11
|
+
def bar
|
12
|
+
# implementation
|
13
|
+
end
|
14
|
+
end
|
15
|
+
})
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
it 'is equal to another method definition with same source file and line numbers' do
|
19
|
+
definition_one = MethodDefinition.new(source_file, 1..3)
|
20
|
+
definition_two = MethodDefinition.new(source_file, 1..3)
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
expect(definition_one).to eq(definition_two)
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
it 'has same hash as another method definition with same path and line numbers' do
|
26
|
+
definition_one = MethodDefinition.new(source_file, 1..3)
|
27
|
+
definition_two = MethodDefinition.new(source_file, 1..3)
|
25
28
|
|
26
|
-
|
27
|
-
|
29
|
+
expect(definition_one.hash).to eq(definition_two.hash)
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
it 'provides access to the method source' do
|
33
|
+
definition = MethodDefinition.new(source_file, 1..3)
|
31
34
|
|
32
|
-
|
35
|
+
expect(definition.source).to eq(source_file.snippet(1..3))
|
36
|
+
end
|
33
37
|
end
|
34
|
-
end
|
38
|
+
end
|
data/spec/method_diff_spec.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
require 'method_log/method_diff'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
module MethodLog
|
6
|
+
describe MethodDiff do
|
7
|
+
let(:first_commit) { double(:first_commit) }
|
8
|
+
let(:second_commit) { double(:second_commit) }
|
9
|
+
let(:diff) { MethodDiff.new(first_commit, second_commit) }
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
it 'generates text diff of the method source for two commits' do
|
12
|
+
first_commit.stub(:method_source).and_return(%{line 1\nline 2\n})
|
13
|
+
second_commit.stub(:method_source).and_return(%{line 2\nline 3\n})
|
14
|
+
expect(diff.to_s).to eq(%{-line 1\n line 2\n+line 3\n})
|
15
|
+
end
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
data/spec/method_finder_spec.rb
CHANGED
@@ -3,249 +3,245 @@ require 'spec_helper'
|
|
3
3
|
require 'method_log/source_file'
|
4
4
|
require 'method_log/method_finder'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
it 'finds definition of instance method on module' do
|
23
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
24
|
-
module Foo
|
25
|
-
def bar
|
26
|
-
# implementation
|
27
|
-
end
|
28
|
-
end
|
29
|
-
}.strip)
|
30
|
-
|
31
|
-
method_finder = MethodLog::MethodFinder.new(source_file: foo)
|
32
|
-
method_definition = method_finder.find('Foo#bar')
|
33
|
-
|
34
|
-
expect(method_definition).to eq(MethodLog::MethodDefinition.new(source_file: foo, lines: 1..3))
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'finds definition of instance method on class within module' do
|
38
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
39
|
-
module Foo
|
40
|
-
class Bar
|
41
|
-
def baz
|
42
|
-
# implementation
|
6
|
+
module MethodLog
|
7
|
+
describe MethodFinder do
|
8
|
+
it 'finds definition of instance method on class' do
|
9
|
+
foo = source(path: 'foo.rb', source: %{
|
10
|
+
class Foo
|
11
|
+
def bar
|
12
|
+
# implementation
|
13
|
+
end
|
14
|
+
end
|
15
|
+
})
|
16
|
+
|
17
|
+
method_finder = MethodFinder.new(foo)
|
18
|
+
method_definition = method_finder.find('Foo#bar')
|
19
|
+
|
20
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 1..3))
|
43
21
|
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
}.strip)
|
47
|
-
|
48
|
-
method_finder = MethodLog::MethodFinder.new(source_file: foo)
|
49
|
-
method_definition = method_finder.find('Foo::Bar#baz')
|
50
|
-
|
51
|
-
expect(method_definition).to eq(MethodLog::MethodDefinition.new(source_file: foo, lines: 2..4))
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'finds definition of instance method on namespaced class within previously defined module' do
|
55
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
56
|
-
module Foo
|
57
|
-
end
|
58
|
-
|
59
|
-
class Foo::Bar
|
60
|
-
def baz
|
61
|
-
# implementation
|
62
|
-
end
|
63
|
-
end
|
64
|
-
}.strip)
|
65
|
-
|
66
|
-
method_finder = MethodLog::MethodFinder.new(source_file: foo)
|
67
|
-
method_definition = method_finder.find('Foo::Bar#baz')
|
68
22
|
|
69
|
-
|
70
|
-
|
23
|
+
it 'finds definition of instance method on module' do
|
24
|
+
foo = source(path: 'foo.rb', source: %{
|
25
|
+
module Foo
|
26
|
+
def bar
|
27
|
+
# implementation
|
28
|
+
end
|
29
|
+
end
|
30
|
+
})
|
71
31
|
|
72
|
-
|
73
|
-
|
74
|
-
module Foo
|
75
|
-
end
|
32
|
+
method_finder = MethodFinder.new(foo)
|
33
|
+
method_definition = method_finder.find('Foo#bar')
|
76
34
|
|
77
|
-
|
78
|
-
def baz
|
79
|
-
# implementation
|
80
|
-
end
|
81
|
-
end
|
82
|
-
}.strip)
|
83
|
-
|
84
|
-
method_finder = MethodLog::MethodFinder.new(source_file: foo)
|
85
|
-
method_definition = method_finder.find('Foo::Bar#baz')
|
86
|
-
|
87
|
-
expect(method_definition).to eq(MethodLog::MethodDefinition.new(source_file: foo, lines: 4..6))
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'finds definition of class method on class' do
|
91
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
92
|
-
module Foo
|
93
|
-
def self.bar
|
94
|
-
# implementation
|
95
|
-
end
|
96
|
-
end
|
97
|
-
}.strip)
|
98
|
-
|
99
|
-
method_finder = MethodLog::MethodFinder.new(source_file: foo)
|
100
|
-
method_definition = method_finder.find('Foo.bar')
|
101
|
-
|
102
|
-
expect(method_definition).to eq(MethodLog::MethodDefinition.new(source_file: foo, lines: 1..3))
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'finds definition of class method on class with explicit reference to class' do
|
106
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
107
|
-
module Foo
|
108
|
-
def Foo.bar
|
109
|
-
# implementation
|
110
|
-
end
|
111
|
-
end
|
112
|
-
}.strip)
|
113
|
-
|
114
|
-
method_finder = MethodLog::MethodFinder.new(source_file: foo)
|
115
|
-
method_definition = method_finder.find('Foo.bar')
|
116
|
-
|
117
|
-
expect(method_definition).to eq(MethodLog::MethodDefinition.new(source_file: foo, lines: 1..3))
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'finds definition of class method on class with explicit reference to namespaced class' do
|
121
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
122
|
-
module Foo
|
123
|
-
class Bar
|
124
|
-
def (Foo::Bar).baz
|
125
|
-
# implementation
|
35
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 1..3))
|
126
36
|
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
}.strip)
|
130
|
-
|
131
|
-
method_finder = MethodLog::MethodFinder.new(source_file: foo)
|
132
|
-
method_definition = method_finder.find('Foo::Bar.baz')
|
133
|
-
|
134
|
-
expect(method_definition).to eq(MethodLog::MethodDefinition.new(source_file: foo, lines: 2..4))
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'finds definition of class method on class with explicit reference to namespaced class outside current scope' do
|
138
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
139
|
-
class Foo
|
140
|
-
end
|
141
|
-
|
142
|
-
class Bar
|
143
|
-
def Foo.baz
|
144
|
-
# implementation
|
145
|
-
end
|
146
|
-
end
|
147
|
-
}.strip)
|
148
37
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
38
|
+
it 'finds definition of instance method on class within module' do
|
39
|
+
foo = source(path: 'foo.rb', source: %{
|
40
|
+
module Foo
|
41
|
+
class Bar
|
42
|
+
def baz
|
43
|
+
# implementation
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
})
|
48
|
+
|
49
|
+
method_finder = MethodFinder.new(foo)
|
50
|
+
method_definition = method_finder.find('Foo::Bar#baz')
|
51
|
+
|
52
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 2..4))
|
161
53
|
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
}.strip)
|
165
54
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
55
|
+
it 'finds definition of instance method on namespaced class within previously defined module' do
|
56
|
+
foo = source(path: 'foo.rb', source: %{
|
57
|
+
module Foo
|
58
|
+
end
|
59
|
+
class Foo::Bar
|
60
|
+
def baz
|
61
|
+
# implementation
|
62
|
+
end
|
63
|
+
end
|
64
|
+
})
|
65
|
+
|
66
|
+
method_finder = MethodFinder.new(foo)
|
67
|
+
method_definition = method_finder.find('Foo::Bar#baz')
|
68
|
+
|
69
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 3..5))
|
178
70
|
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
}.strip)
|
182
71
|
|
183
|
-
|
184
|
-
|
72
|
+
it 'finds definition of instance method on namespaced module within previously defined module' do
|
73
|
+
foo = source(path: 'foo.rb', source: %{
|
74
|
+
module Foo
|
75
|
+
end
|
76
|
+
module Foo::Bar
|
77
|
+
def baz
|
78
|
+
# implementation
|
79
|
+
end
|
80
|
+
end
|
81
|
+
})
|
82
|
+
|
83
|
+
method_finder = MethodFinder.new(foo)
|
84
|
+
method_definition = method_finder.find('Foo::Bar#baz')
|
85
|
+
|
86
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 3..5))
|
87
|
+
end
|
185
88
|
|
186
|
-
|
187
|
-
|
89
|
+
it 'finds definition of class method on class' do
|
90
|
+
foo = source(path: 'foo.rb', source: %{
|
91
|
+
module Foo
|
92
|
+
def self.bar
|
93
|
+
# implementation
|
94
|
+
end
|
95
|
+
end
|
96
|
+
})
|
188
97
|
|
189
|
-
|
190
|
-
|
191
|
-
class Foo
|
192
|
-
end
|
98
|
+
method_finder = MethodFinder.new(foo)
|
99
|
+
method_definition = method_finder.find('Foo.bar')
|
193
100
|
|
194
|
-
|
195
|
-
class << Foo
|
196
|
-
def bar
|
197
|
-
# implementation
|
101
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 1..3))
|
198
102
|
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
}.strip)
|
202
103
|
|
203
|
-
|
204
|
-
|
104
|
+
it 'finds definition of class method on class with explicit reference to class' do
|
105
|
+
foo = source(path: 'foo.rb', source: %{
|
106
|
+
module Foo
|
107
|
+
def Foo.bar
|
108
|
+
# implementation
|
109
|
+
end
|
110
|
+
end
|
111
|
+
})
|
205
112
|
|
206
|
-
|
207
|
-
|
113
|
+
method_finder = MethodFinder.new(foo)
|
114
|
+
method_definition = method_finder.find('Foo.bar')
|
208
115
|
|
209
|
-
|
210
|
-
foo = MethodLog::SourceFile.new(path: 'foo.rb', source: %{
|
211
|
-
class Foo
|
212
|
-
def initialize
|
213
|
-
@foo = new
|
214
|
-
class << @foo
|
215
|
-
def bar
|
216
|
-
# implementation
|
217
|
-
end
|
116
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 1..3))
|
218
117
|
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
}.strip)
|
222
118
|
|
223
|
-
|
224
|
-
|
119
|
+
it 'finds definition of class method on class with explicit reference to namespaced class' do
|
120
|
+
foo = source(path: 'foo.rb', source: %{
|
121
|
+
module Foo
|
122
|
+
class Bar
|
123
|
+
def (Foo::Bar).baz
|
124
|
+
# implementation
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
})
|
129
|
+
|
130
|
+
method_finder = MethodFinder.new(foo)
|
131
|
+
method_definition = method_finder.find('Foo::Bar.baz')
|
132
|
+
|
133
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 2..4))
|
134
|
+
end
|
225
135
|
|
226
|
-
|
227
|
-
|
136
|
+
it 'finds definition of class method on class with explicit reference to namespaced class outside current scope' do
|
137
|
+
foo = source(path: 'foo.rb', source: %{
|
138
|
+
class Foo
|
139
|
+
end
|
140
|
+
class Bar
|
141
|
+
def Foo.baz
|
142
|
+
# implementation
|
143
|
+
end
|
144
|
+
end
|
145
|
+
})
|
146
|
+
|
147
|
+
method_finder = MethodFinder.new(foo)
|
148
|
+
method_definition = method_finder.find('Foo.baz')
|
149
|
+
|
150
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 3..5))
|
151
|
+
end
|
228
152
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
153
|
+
it 'finds definition of class method on class when singleton class is re-opened' do
|
154
|
+
foo = source(path: 'foo.rb', source: %{
|
155
|
+
class Foo
|
156
|
+
class << self
|
157
|
+
def bar
|
158
|
+
# implementation
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
})
|
163
|
+
|
164
|
+
method_finder = MethodFinder.new(foo)
|
165
|
+
method_definition = method_finder.find('Foo.bar')
|
166
|
+
|
167
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 2..4))
|
168
|
+
end
|
234
169
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
170
|
+
it 'finds definition of class method on class when singleton class is re-opened with explicit reference to class' do
|
171
|
+
foo = source(path: 'foo.rb', source: %{
|
172
|
+
class Foo
|
173
|
+
class << Foo
|
174
|
+
def bar
|
175
|
+
# implementation
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
})
|
180
|
+
|
181
|
+
method_finder = MethodFinder.new(foo)
|
182
|
+
method_definition = method_finder.find('Foo.bar')
|
183
|
+
|
184
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 2..4))
|
185
|
+
end
|
239
186
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
end
|
244
|
-
|
187
|
+
it 'finds definition of class method on class when singleton class is re-opened with explicit reference to class outside current scope' do
|
188
|
+
foo = source(path: 'foo.rb', source: %{
|
189
|
+
class Foo
|
190
|
+
end
|
191
|
+
class Bar
|
192
|
+
class << Foo
|
193
|
+
def bar
|
194
|
+
# implementation
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
})
|
199
|
+
|
200
|
+
method_finder = MethodFinder.new(foo)
|
201
|
+
method_definition = method_finder.find('Foo.bar')
|
202
|
+
|
203
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 4..6))
|
204
|
+
end
|
245
205
|
|
246
|
-
|
247
|
-
|
206
|
+
it 'finds definition of class method on unknown object when singleton class is re-opened' do
|
207
|
+
foo = source(path: 'foo.rb', source: %{
|
208
|
+
class Foo
|
209
|
+
def initialize
|
210
|
+
@foo = new
|
211
|
+
class << @foo
|
212
|
+
def bar
|
213
|
+
# implementation
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
})
|
219
|
+
|
220
|
+
method_finder = MethodFinder.new(foo)
|
221
|
+
method_definition = method_finder.find('Foo::(ivar :@foo).bar')
|
222
|
+
|
223
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 4..6))
|
224
|
+
end
|
248
225
|
|
249
|
-
|
226
|
+
it 'finds definition of class method on ambiguous module referenced via top-level module' do
|
227
|
+
foo = source(path: 'foo.rb', source: %{
|
228
|
+
module Foo
|
229
|
+
class Bar; end
|
230
|
+
end
|
231
|
+
module Baz
|
232
|
+
module Foo
|
233
|
+
class Bar; end
|
234
|
+
end
|
235
|
+
def (::Foo::Bar).foo
|
236
|
+
# implementation
|
237
|
+
end
|
238
|
+
end
|
239
|
+
})
|
240
|
+
|
241
|
+
method_finder = MethodFinder.new(foo)
|
242
|
+
method_definition = method_finder.find('Foo::Bar.foo')
|
243
|
+
|
244
|
+
expect(method_definition).to eq(MethodDefinition.new(foo, 7..9))
|
245
|
+
end
|
250
246
|
end
|
251
247
|
end
|