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.
@@ -2,95 +2,97 @@ require 'spec_helper'
2
2
 
3
3
  require 'method_log/scope'
4
4
 
5
- describe MethodLog::Scope do
6
- let(:root) { MethodLog::Scope::Root.new }
7
-
8
- it 'ruby interactive style method identifier for top-level module' do
9
- a = root.define(:A)
10
- expect(a.method_identifier('foo')).to eq('A#foo')
11
- end
12
-
13
- it 'ruby interactive style method identifier for module nested inside top-level module' do
14
- a = root.define(:A)
15
- b = a.define(:B)
16
- expect(b.method_identifier('foo')).to eq('A::B#foo')
17
- end
18
-
19
- it 'ruby interactive style method identifier for module nested inside module nested inside top-level module' do
20
- a = root.define(:A)
21
- b = a.define(:B)
22
- c = b.define(:C)
23
- expect(c.method_identifier('foo')).to eq('A::B::C#foo')
24
- end
25
-
26
- it 'ruby interactive style method identifier for method on singleton class' do
27
- a = root.define(:A)
28
- singleton = a.singleton
29
- expect(singleton.method_identifier('foo')).to eq('A.foo')
30
- end
31
-
32
- it 'ruby interactive style method identifier for method on singleton class nested inside top-level module' do
33
- a = root.define(:A)
34
- b = a.define(:B)
35
- singleton = b.singleton
36
- expect(singleton.method_identifier('foo')).to eq('A::B.foo')
37
- end
38
-
39
- it 'looks up scope for top-level module' do
40
- a = root.define(:A)
41
- expect(a.lookup(:A)).to eq(a)
42
- end
43
-
44
- it 'looks up scopes for top-level module and nested module from nested module' do
45
- a = root.define(:A)
46
- b = a.define(:B)
47
- expect(b.lookup(:A)).to eq(a)
48
- expect(b.lookup(:B)).to eq(b)
49
- end
50
-
51
- it 'looks up scopes for modules from double-nested module' do
52
- a = root.define(:A)
53
- b = a.define(:B)
54
- c = b.define(:C)
55
- expect(c.lookup(:A)).to eq(a)
56
- expect(c.lookup(:B)).to eq(b)
57
- expect(c.lookup(:C)).to eq(c)
58
- end
59
-
60
- it 'looks up qualified module' do
61
- a = root.define(:A)
62
- b = a.define(:B)
63
- c = b.define(:C)
64
- expect(c.for([:A])).to eq(a)
65
- expect(c.for([:A, :B])).to eq(b)
66
- expect(c.for([:A, :B, :C])).to eq(c)
67
- end
68
-
69
- it 'defines missing modules' do
70
- root.for([:A, :B, :C])
71
- a = root.lookup(:A)
72
- b = a.lookup(:B)
73
- c = b.lookup(:C)
74
- expect(a).not_to be_nil
75
- expect(b).not_to be_nil
76
- expect(c).not_to be_nil
77
- end
78
-
79
- it 'returns root scope' do
80
- a = root.define(:A)
81
- b = a.define(:B)
82
- c = b.define(:C)
83
- expect(c.root).to eq(root)
84
- end
85
-
86
- it 'looks up ambiguous module via top-level module' do
87
- a = root.define(:A)
88
- b = a.define(:B)
89
- c = root.define(:C)
90
- aa = c.define(:A)
91
- bb = aa.define(:B)
92
-
93
- expect(c.for([:root, :A, :B])).to eq(b)
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
 
@@ -2,44 +2,46 @@ require 'spec_helper'
2
2
 
3
3
  require 'method_log/source_file'
4
4
 
5
- describe MethodLog::SourceFile do
6
- let(:sha) { 'b54d38bbd989f4b54c38fd77767d89d1' }
7
- let(:repository) { double(:repository) }
8
- let(:blob) { double(:blob, text: 'source') }
9
-
10
- it 'is equal to another source file with same path and source' do
11
- file_one = MethodLog::SourceFile.new(path: 'path/to/source.rb', source: 'source-one')
12
- file_two = MethodLog::SourceFile.new(path: 'path/to/source.rb', source: 'source-one')
13
-
14
- expect(file_one).to eq(file_two)
15
- end
16
-
17
- it 'has same hash as another source file with same path and source' do
18
- file_one = MethodLog::SourceFile.new(path: 'path/to/source.rb', source: 'source-one')
19
- file_two = MethodLog::SourceFile.new(path: 'path/to/source.rb', source: 'source-one')
20
-
21
- expect(file_one.hash).to eq(file_two.hash)
22
- end
23
-
24
- it 'describes source file' do
25
- file = MethodLog::SourceFile.new(path: 'path/to/source.rb', source: %{
26
- class Foo
27
- def bar
28
- # implementation
29
- end
30
- end
31
- }.strip)
32
-
33
- expect(file.snippet(1..3).strip).to eq(%{
34
- def bar
35
- # implementation
36
- end
37
- }.strip)
38
- end
39
-
40
- it 'looks up source in repository using SHA if no source set' do
41
- repository.stub(:lookup).with(sha).and_return(blob)
42
- file = MethodLog::SourceFile.new(path: 'path/to/source.rb', repository: repository, sha: sha)
43
- expect(file.source).to eq('source')
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
@@ -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.5
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-02-26 00:00:00.000000000 Z
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: '0'
157
+ version: 1.9.3
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  requirements:
160
160
  - - ">="