mactag 0.3.3 → 0.4.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.
@@ -0,0 +1,31 @@
1
+ module Mactag
2
+ class TagsFile
3
+ def initialize(file)
4
+ @input = file
5
+ @output = output(file)
6
+ end
7
+
8
+ def create
9
+ system "/usr/local/Cellar/ctags/5.8/bin/ctags -o #{@output} -e #{@input}"
10
+ end
11
+
12
+ def delete
13
+ File.delete(@output)
14
+ end
15
+
16
+ def exist?
17
+ File.exists?(@output)
18
+ end
19
+
20
+ private
21
+
22
+ def output(file)
23
+ basename = File.basename(file, '.*')
24
+ dirname = File.dirname(file)
25
+
26
+ filename = [dirname.gsub(/\//, '_'), basename].join('_')
27
+
28
+ File.join(Rails.root, Mactag::Config.tags_dir, filename)
29
+ end
30
+ end
31
+ end
@@ -1,8 +1,21 @@
1
1
  task :environment
2
2
 
3
- desc "Creates a Ctags file"
4
- task :mactag => :environment do
5
- require File.join(Rails.root, "config", "mactag")
3
+ def load_configuration
4
+ require File.join(Rails.root, 'config', 'mactag')
5
+ end
6
+
7
+ namespace :mactag do
8
+ desc 'Creates Ctags file'
9
+ task :create => :environment do
10
+ load_configuration
11
+
12
+ Mactag::Builder.create
13
+ end
14
+
15
+ desc 'Starts the Mactag server'
16
+ task :server => :environment do
17
+ load_configuration
6
18
 
7
- Mactag::Builder.create
19
+ Mactag::Server.start
20
+ end
8
21
  end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Builder do
4
+ before do
5
+ @builder = Mactag::Builder.new
6
+ end
7
+
8
+ describe '#<<' do
9
+ before do
10
+ @tag = Mactag::Tag::App.new('app')
11
+ end
12
+
13
+ it 'should add single tag' do
14
+ @builder << @tag
15
+
16
+ @builder.instance_variable_get('@tags').should =~ [@tag]
17
+ end
18
+
19
+ it 'should add multiple tags' do
20
+ @builder << [@tag, @tag]
21
+
22
+ @builder.instance_variable_get('@tags').should =~ [@tag, @tag]
23
+ end
24
+ end
25
+
26
+ describe '#files' do
27
+ before do
28
+ Dir.stub!(:glob).and_return { |file| [file] }
29
+ File.stub!(:expand_path).and_return { |file| file }
30
+ File.stub!(:directory?).and_return(false)
31
+ end
32
+
33
+ it 'should flatten all files' do
34
+ @builder.stub!(:all).and_return([['app'], 'lib'])
35
+ @builder.files.should =~ ['app', 'lib']
36
+ end
37
+
38
+ it 'should compact all files' do
39
+ @builder.stub!(:all).and_return([nil, 'app', nil, 'lib', nil])
40
+ @builder.files.should =~ ['app', 'lib']
41
+ end
42
+
43
+ it 'should expand all files' do
44
+ @builder.stub!(:all).and_return(['app', 'lib'])
45
+ File.should_receive(:expand_path).with('app')
46
+ File.should_receive(:expand_path).with('lib')
47
+ @builder.files
48
+ end
49
+
50
+ it 'should glob all files' do
51
+ @builder.stub!(:all).and_return(['app', 'lib'])
52
+ Dir.should_receive(:glob).with('app')
53
+ Dir.should_receive(:glob).with('lib')
54
+ @builder.files
55
+ end
56
+
57
+ it 'should uniquify files' do
58
+ @builder.stub!(:all).and_return(['app', 'lib', 'lib', 'app'])
59
+ @builder.files.should =~ ['app', 'lib']
60
+ end
61
+
62
+ it 'should not return directories' do
63
+ @builder.stub!(:all).and_return(['app'])
64
+ Dir.stub!(:glob).and_return(['app'])
65
+ File.stub!(:directory?).and_return(true)
66
+ @builder.files.should be_empty
67
+ end
68
+ end
69
+
70
+ describe '#directories' do
71
+ it 'should return all file dirnames' do
72
+ @builder.stub!(:files).and_return(['app/models/user.rb', 'lib/validate.rb'])
73
+ @builder.directories.should =~ ['app/models', 'lib']
74
+ end
75
+
76
+ it 'should only return uniq directories' do
77
+ @builder.stub!(:files).and_return(['app/models/user.rb', 'app/models/post.rb'])
78
+ @builder.directories.should =~ ['app/models']
79
+ end
80
+ end
81
+
82
+ describe '#all' do
83
+ it 'should return all files' do
84
+ @builder << Mactag::Tag::App.new('app')
85
+ @builder << Mactag::Tag::App.new('lib')
86
+
87
+ @builder.all.should =~ ['app', 'lib']
88
+ end
89
+
90
+ it 'should return empty array when no tags' do
91
+ @builder.all.should be_empty
92
+ end
93
+ end
94
+
95
+ describe '#gems?' do
96
+ it 'should be true when tags exists' do
97
+ @builder.stub!(:all).and_return(['app'])
98
+
99
+ @builder.gems?.should be_true
100
+ end
101
+
102
+ it 'should be false when no tags exists' do
103
+ @builder.stub!(:all).and_return([])
104
+
105
+ @builder.gems?.should be_false
106
+ end
107
+ end
108
+
109
+ describe '#generate' do
110
+ it 'should accept a block as argument' do
111
+ lambda { Mactag::Builder.generate {} }.should_not raise_exception
112
+ end
113
+ end
114
+
115
+ describe '#gem_home_exists?' do
116
+ it 'should exist when directory exists' do
117
+ File.stub!(:directory?).and_return(true)
118
+
119
+ Mactag::Builder.gem_home_exists?.should be_true
120
+ end
121
+
122
+ it 'should not exist when directory does not exist' do
123
+ File.stub!(:directory?).and_return(false)
124
+
125
+ Mactag::Builder.gem_home_exists?.should be_false
126
+ end
127
+ end
128
+
129
+ describe '#builder' do
130
+ it 'should return builder instance' do
131
+ Mactag::Builder.generate {}
132
+ Mactag::Builder.builder.should == Mactag::Builder.instance_variable_get('@builder')
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Config do
4
+ describe '#binary' do
5
+ it 'should have correct command' do
6
+ Mactag::Config.binary.should == 'ctags -o {OUTPUT} -e {INPUT}'
7
+ end
8
+ end
9
+
10
+ describe '#tags_file' do
11
+ it 'should have correct name' do
12
+ Mactag::Config.tags_file.should == 'TAGS'
13
+ end
14
+ end
15
+
16
+ describe '#gem_home' do
17
+ context 'when using RVM' do
18
+ before do
19
+ Mactag::Config.stub!(:rvm).and_return(true)
20
+ File.stub!(:join).and_return('/path/to/rvm/gems')
21
+ end
22
+
23
+ it 'should be the correct gems path' do
24
+ Mactag::Config.gem_home.should == '/path/to/rvm/gems'
25
+ end
26
+ end
27
+
28
+ context 'when not using RVM' do
29
+ before do
30
+ Mactag::Config.stub!(:rvm).and_return(false)
31
+ end
32
+
33
+ it 'should be the default gem path' do
34
+ Mactag::Config.gem_home.should == '/Library/Ruby/Gems/1.8/gems'
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#rvm' do
40
+ it 'should be true by default' do
41
+ Mactag::Config.rvm.should be_true
42
+ end
43
+ end
44
+
45
+ describe '#tags_dir' do
46
+ it 'should have correct name' do
47
+ Mactag::Config.tags_dir.should == '.tags'
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Ctags do
4
+ before do
5
+ @ctags = Mactag::Ctags.new('in', 'out')
6
+ end
7
+
8
+ describe '#initialize' do
9
+ it 'should handle single file' do
10
+ @ctags = Mactag::Ctags.new('in', 'out')
11
+ @ctags.instance_variable_get('@input').should =~ ['in']
12
+ end
13
+
14
+ it 'should handle multiple files' do
15
+ @ctags = Mactag::Ctags.new(['in_1', 'in_2'], 'out')
16
+ @ctags.instance_variable_get('@input').should =~ ['in_1', 'in_2']
17
+ end
18
+ end
19
+
20
+ describe '#command' do
21
+ before do
22
+ Rails.stub!(:root).and_return('root')
23
+ @ctags.stub!(:binary).and_return('binary')
24
+ end
25
+
26
+ it 'should return correct command' do
27
+ @ctags.send(:command).should == 'cd root && binary'
28
+ end
29
+ end
30
+
31
+ describe '#binary' do
32
+ before do
33
+ Mactag::Config.stub!(:binary).and_return('ctags -o {OUTPUT} -e {INPUT}')
34
+ end
35
+
36
+ it 'should return correct command' do
37
+ @ctags.send(:binary).should == 'ctags -o out -e in'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Dsl do
4
+ before do
5
+ @builder = Mactag::Builder.new
6
+ @dsl = Mactag::Dsl.new(@builder)
7
+ end
8
+
9
+ describe '#app' do
10
+ it_should_support_dsl 'single argument' do
11
+ @dsl.app('lib/**/*.rb')
12
+ end
13
+ end
14
+
15
+ describe '#plugin' do
16
+ it_should_support_dsl 'without arguments' do
17
+ @dsl.plugin
18
+ end
19
+
20
+ it_should_support_dsl 'single argument' do
21
+ @dsl.plugin('devise')
22
+ end
23
+
24
+ it_should_support_dsl 'multiple arguments' do
25
+ @dsl.plugins('devise', 'rack')
26
+ end
27
+ end
28
+
29
+ describe '#gem' do
30
+ it_should_support_dsl 'without arguments' do
31
+ @dsl.gem
32
+ end
33
+
34
+ context 'single argument' do
35
+ it_should_support_dsl 'with version' do
36
+ @dsl.gem('devise', :version => '1.1.1')
37
+ end
38
+
39
+ it_should_support_dsl 'without version' do
40
+ @dsl.gem('devise')
41
+ end
42
+ end
43
+
44
+ it_should_support_dsl 'multiple arguments' do
45
+ @dsl.gem('devise', 'rack')
46
+ end
47
+ end
48
+
49
+ describe '#rails' do
50
+ it_should_support_dsl 'without arguments' do
51
+ @dsl.rails
52
+ end
53
+
54
+ it_should_support_dsl 'packages only' do
55
+ @dsl.rails(:only => [])
56
+ end
57
+
58
+ it_should_support_dsl 'packages except' do
59
+ @dsl.rails(:except => [])
60
+ end
61
+
62
+ it_should_support_dsl 'with version' do
63
+ @dsl.rails(:version => '3.0.0.rc')
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Server do
4
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Tag::App do
4
+ describe '#initialize' do
5
+ before do
6
+ @tag = 'app/**/*.rb'
7
+ @app = Mactag::Tag::App.new(@tag)
8
+ end
9
+
10
+ it 'should set the tag' do
11
+ @app.tag.should == @tag
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Tag::Gem do
4
+ before do
5
+ Mactag::Config.stub!(:gem_home).and_return('GEM_HOME')
6
+ end
7
+
8
+ describe '#tag' do
9
+ context 'for existing gem' do
10
+ context 'with no specified version' do
11
+ before do
12
+ Mactag::Tag::Gem.stub!(:most_recent).and_return('devise-1.1.1')
13
+
14
+ @gem = Mactag::Tag::Gem.new('devise')
15
+ @gem.stub!(:exists?).and_return(true)
16
+ end
17
+
18
+ it 'return correct tag' do
19
+ @gem.tag.should == 'GEM_HOME/devise-1.1.1/lib/**/*.rb'
20
+ end
21
+ end
22
+
23
+ context 'with specified version' do
24
+ before do
25
+ @gem = Mactag::Tag::Gem.new('devise', '1.1.1')
26
+ @gem.stub!(:exists?).and_return(true)
27
+ end
28
+
29
+ it 'return correct tag' do
30
+ @gem.tag.should == 'GEM_HOME/devise-1.1.1/lib/**/*.rb'
31
+ end
32
+ end
33
+ end
34
+
35
+ it 'return nil when gem does not exist' do
36
+ @gem = Mactag::Tag::Gem.new('devise')
37
+ @gem.stub!(:exists?).and_return(false)
38
+
39
+ @gem.tag.should be_nil
40
+ end
41
+ end
42
+
43
+ describe '#most_recent' do
44
+ it 'should return most recent gem if more than one version of same gem exists' do
45
+ Dir.stub!(:glob).and_return(['vendor/plugins/devise-1.1.1', 'vendor/plugins/devise-1.1.0'])
46
+
47
+ Mactag::Tag::Gem.most_recent('devise').should == 'devise-1.1.1'
48
+ end
49
+
50
+ it 'should return only gem if only one version of same gem exists' do
51
+ Dir.stub!(:glob).and_return(['vendor/plugins/devise-1.1.1'])
52
+
53
+ Mactag::Tag::Gem.most_recent('devise').should == 'devise-1.1.1'
54
+ end
55
+
56
+ it 'should return nil if no version of gem' do
57
+ Dir.stub!(:glob).and_return([])
58
+
59
+ Mactag::Tag::Gem.most_recent('devise').should be_nil
60
+ end
61
+ end
62
+
63
+ describe '#exists' do
64
+ context 'with specified version' do
65
+ before do
66
+ @gem = Mactag::Tag::Gem.new('devise', '1.1.1')
67
+ end
68
+
69
+ it 'should be true when gem exist' do
70
+ File.stub!(:directory?).and_return(true)
71
+
72
+ @gem.send(:exists?).should be_true
73
+ end
74
+
75
+ it 'should be false when gem does not exist' do
76
+ File.stub!(:directory?).and_return(false)
77
+
78
+ @gem.send(:exists?).should be_false
79
+ end
80
+ end
81
+
82
+ context 'with no specified version' do
83
+ before do
84
+ @gem = Mactag::Tag::Gem.new('devise')
85
+ end
86
+
87
+ it 'should be true when gem exists' do
88
+ Mactag::Tag::Gem.stub!(:most_recent).and_return('devise-1.1.1')
89
+
90
+ @gem.send(:exists?).should be_true
91
+ end
92
+
93
+ it 'should be false when gem does not exist' do
94
+ Mactag::Tag::Gem.stub!(:most_recent).and_return(nil)
95
+
96
+ @gem.send(:exists?).should be_false
97
+ end
98
+ end
99
+ end
100
+
101
+ describe '#splash' do
102
+ before do
103
+ @gem = Mactag::Tag::Gem.new('devise', '1.1.1')
104
+ end
105
+
106
+ it 'return gem name, dash, version' do
107
+ @gem.send(:splash).should == 'devise-1.1.1'
108
+ end
109
+ end
110
+ end