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/scope_spec.rb
CHANGED
@@ -2,95 +2,97 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'method_log/scope'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
5
|
+
module MethodLog
|
6
|
+
describe Scope do
|
7
|
+
let(:root) { Scope::Root.new }
|
8
|
+
|
9
|
+
it 'ruby interactive style method identifier for top-level module' do
|
10
|
+
a = root.define(:A)
|
11
|
+
expect(a.method_identifier('foo')).to eq('A#foo')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'ruby interactive style method identifier for module nested inside top-level module' do
|
15
|
+
a = root.define(:A)
|
16
|
+
b = a.define(:B)
|
17
|
+
expect(b.method_identifier('foo')).to eq('A::B#foo')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'ruby interactive style method identifier for module nested inside module nested inside top-level module' do
|
21
|
+
a = root.define(:A)
|
22
|
+
b = a.define(:B)
|
23
|
+
c = b.define(:C)
|
24
|
+
expect(c.method_identifier('foo')).to eq('A::B::C#foo')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'ruby interactive style method identifier for method on singleton class' do
|
28
|
+
a = root.define(:A)
|
29
|
+
singleton = a.singleton
|
30
|
+
expect(singleton.method_identifier('foo')).to eq('A.foo')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'ruby interactive style method identifier for method on singleton class nested inside top-level module' do
|
34
|
+
a = root.define(:A)
|
35
|
+
b = a.define(:B)
|
36
|
+
singleton = b.singleton
|
37
|
+
expect(singleton.method_identifier('foo')).to eq('A::B.foo')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'looks up scope for top-level module' do
|
41
|
+
a = root.define(:A)
|
42
|
+
expect(a.lookup(:A)).to eq(a)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'looks up scopes for top-level module and nested module from nested module' do
|
46
|
+
a = root.define(:A)
|
47
|
+
b = a.define(:B)
|
48
|
+
expect(b.lookup(:A)).to eq(a)
|
49
|
+
expect(b.lookup(:B)).to eq(b)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'looks up scopes for modules from double-nested module' do
|
53
|
+
a = root.define(:A)
|
54
|
+
b = a.define(:B)
|
55
|
+
c = b.define(:C)
|
56
|
+
expect(c.lookup(:A)).to eq(a)
|
57
|
+
expect(c.lookup(:B)).to eq(b)
|
58
|
+
expect(c.lookup(:C)).to eq(c)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'looks up qualified module' do
|
62
|
+
a = root.define(:A)
|
63
|
+
b = a.define(:B)
|
64
|
+
c = b.define(:C)
|
65
|
+
expect(c.for([:A])).to eq(a)
|
66
|
+
expect(c.for([:A, :B])).to eq(b)
|
67
|
+
expect(c.for([:A, :B, :C])).to eq(c)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'defines missing modules' do
|
71
|
+
root.for([:A, :B, :C])
|
72
|
+
a = root.lookup(:A)
|
73
|
+
b = a.lookup(:B)
|
74
|
+
c = b.lookup(:C)
|
75
|
+
expect(a).not_to be_nil
|
76
|
+
expect(b).not_to be_nil
|
77
|
+
expect(c).not_to be_nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns root scope' do
|
81
|
+
a = root.define(:A)
|
82
|
+
b = a.define(:B)
|
83
|
+
c = b.define(:C)
|
84
|
+
expect(c.root).to eq(root)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'looks up ambiguous module via top-level module' do
|
88
|
+
a = root.define(:A)
|
89
|
+
b = a.define(:B)
|
90
|
+
c = root.define(:C)
|
91
|
+
aa = c.define(:A)
|
92
|
+
bb = aa.define(:B)
|
93
|
+
|
94
|
+
expect(c.for([:root, :A, :B])).to eq(b)
|
95
|
+
end
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
data/spec/source_file_spec.rb
CHANGED
@@ -2,44 +2,46 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'method_log/source_file'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
repository
|
42
|
-
|
43
|
-
|
5
|
+
module MethodLog
|
6
|
+
describe SourceFile do
|
7
|
+
let(:sha) { 'b54d38bbd989f4b54c38fd77767d89d1' }
|
8
|
+
let(:repository) { double(:repository) }
|
9
|
+
let(:blob) { double(:blob, text: 'source') }
|
10
|
+
|
11
|
+
it 'is equal to another source file with same path and source' do
|
12
|
+
file_one = source(path: 'path/to/source.rb', source: 'source-one')
|
13
|
+
file_two = source(path: 'path/to/source.rb', source: 'source-one')
|
14
|
+
|
15
|
+
expect(file_one).to eq(file_two)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has same hash as another source file with same path and source' do
|
19
|
+
file_one = source(path: 'path/to/source.rb', source: 'source-one')
|
20
|
+
file_two = source(path: 'path/to/source.rb', source: 'source-one')
|
21
|
+
|
22
|
+
expect(file_one.hash).to eq(file_two.hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'describes source file' do
|
26
|
+
file = source(path: 'path/to/source.rb', source: unindent(%{
|
27
|
+
class Foo
|
28
|
+
def bar
|
29
|
+
# implementation
|
30
|
+
end
|
31
|
+
end
|
32
|
+
}))
|
33
|
+
|
34
|
+
expect(file.snippet(1..3)).to eq(indent(unindent(%{
|
35
|
+
def bar
|
36
|
+
# implementation
|
37
|
+
end
|
38
|
+
})))
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'looks up source in repository using SHA if no source set' do
|
42
|
+
repository.stub(:lookup).with(sha).and_return(blob)
|
43
|
+
file = source(path: 'path/to/source.rb', repository: repository, sha: sha)
|
44
|
+
expect(file.source).to eq('source')
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1,26 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
2
|
+
|
3
|
+
module MethodLog
|
4
|
+
module SourceHelper
|
5
|
+
def source(options = {})
|
6
|
+
options[:source] = options[:source] ? unindent(options[:source]) : options[:source]
|
7
|
+
SourceFile.new(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def unindent(code)
|
11
|
+
lines = code.split($/)
|
12
|
+
indent = lines.reject { |l| l.strip.length == 0 }.map { |l| l[/^\s*/].length }.min
|
13
|
+
fixed_lines = lines.map { |l| l.sub(Regexp.new(' ' * indent), '') }
|
14
|
+
fixed_lines.drop_while { |l| l.strip.length == 0 }.take_while { |l| l.strip.length > 0 }.join($/)
|
15
|
+
end
|
16
|
+
|
17
|
+
def indent(code, spaces = 2)
|
18
|
+
lines = code.split($/)
|
19
|
+
lines.map { |l| "#{' ' * spaces}#{l}"}.join($/)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.include MethodLog::SourceHelper
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Mead
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|
@@ -154,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
154
|
requirements:
|
155
155
|
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
157
|
+
version: 1.9.3
|
158
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
159
|
requirements:
|
160
160
|
- - ">="
|