mactag 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -3
- data/VERSION +1 -1
- data/lib/generators/mactag/templates/mactag.rb +1 -1
- data/lib/mactag.rb +7 -1
- data/lib/mactag/builder.rb +90 -0
- data/lib/mactag/ctags.rb +23 -0
- data/lib/mactag/parser.rb +61 -0
- data/lib/mactag/tag.rb +0 -1
- data/lib/mactag/tag/app.rb +4 -4
- data/lib/mactag/tag/gem.rb +43 -38
- data/lib/mactag/tag/plugin.rb +19 -14
- data/lib/mactag/tag/rails.rb +3 -8
- data/lib/tasks/mactag.rake +1 -1
- data/test/mactag/builder_test.rb +77 -0
- data/test/mactag/config_test.rb +4 -8
- data/test/mactag/parser_test.rb +66 -0
- data/test/mactag/tag/app_test.rb +4 -4
- data/test/mactag/tag/gem_test.rb +100 -47
- data/test/mactag/tag/plugin_test.rb +28 -29
- data/test/mactag/tag/rails_test.rb +40 -28
- metadata +14 -71
- data/features/app.feature +0 -110
- data/features/gem.feature +0 -154
- data/features/plugin.feature +0 -115
- data/features/rails.feature +0 -6
- data/features/step_definitions/mactag_steps.rb +0 -43
- data/features/support/env.rb +0 -14
- data/features/support/rails_app.rb +0 -46
- data/features/support/tags_file.rb +0 -24
- data/lib/mactag/table.rb +0 -66
- data/lib/mactag/tag/parser.rb +0 -43
data/lib/tasks/mactag.rake
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BuilderTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@builder = Mactag::Builder.new
|
6
|
+
end
|
7
|
+
|
8
|
+
context '#<<' do
|
9
|
+
setup do
|
10
|
+
@tag = Mactag::Tag::App.new('app')
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'add single tag to tags' do
|
14
|
+
@builder << @tag
|
15
|
+
|
16
|
+
assert_equal 1, @builder.instance_variable_get('@tags').size
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'add multiple tags to tags' do
|
20
|
+
@builder << [@tag, @tag]
|
21
|
+
|
22
|
+
assert_equal 2, @builder.instance_variable_get('@tags').size
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#all' do
|
27
|
+
should 'return all tags if existing tags' do
|
28
|
+
app = Mactag::Tag::App.new('app')
|
29
|
+
lib = Mactag::Tag::App.new('lib')
|
30
|
+
|
31
|
+
@builder << app
|
32
|
+
@builder << lib
|
33
|
+
|
34
|
+
assert_same_elements ['app', 'lib'], @builder.all
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'return an empty array if no tags' do
|
38
|
+
assert_same_elements [], @builder.all
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '#gems?' do
|
43
|
+
should 'return true if existing tags' do
|
44
|
+
@builder.stubs(:all).returns(['app'])
|
45
|
+
|
46
|
+
assert @builder.gems?
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'return false if no existing tags' do
|
50
|
+
@builder.stubs(:all).returns([])
|
51
|
+
|
52
|
+
assert !@builder.gems?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context '#generate' do
|
57
|
+
should 'accept a block as argument' do
|
58
|
+
assert_nothing_raised do
|
59
|
+
Mactag::Builder.generate {}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context '#gem_home_exists?' do
|
65
|
+
should 'exist if directory exists in system' do
|
66
|
+
File.stubs(:directory?).returns(true)
|
67
|
+
|
68
|
+
assert Mactag::Builder.gem_home_exists?
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'not exist if directory does not exist in system' do
|
72
|
+
File.stubs(:directory?).returns(false)
|
73
|
+
|
74
|
+
assert !Mactag::Builder.gem_home_exists?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/test/mactag/config_test.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ConfigTest < ActiveSupport::TestCase
|
4
|
-
context 'binary' do
|
5
|
-
setup do
|
6
|
-
@binary = Mactag::Config.binary
|
7
|
-
end
|
8
|
-
|
4
|
+
context '#binary' do
|
9
5
|
should 'be right command' do
|
10
|
-
assert_equal 'ctags -o TAGS -e',
|
6
|
+
assert_equal 'ctags -o TAGS -e', Mactag::Config.binary
|
11
7
|
end
|
12
8
|
end
|
13
9
|
|
14
|
-
context '
|
10
|
+
context '#gem_home' do
|
15
11
|
context 'when using RVM' do
|
16
12
|
setup do
|
17
13
|
Mactag::Config.stubs(:rvm).returns(true)
|
@@ -20,7 +16,7 @@ class ConfigTest < ActiveSupport::TestCase
|
|
20
16
|
@gem_home = Mactag::Config.gem_home
|
21
17
|
end
|
22
18
|
|
23
|
-
should 'correct' do
|
19
|
+
should 'be correct' do
|
24
20
|
assert_equal '/path/to/rvm/gems', @gem_home
|
25
21
|
end
|
26
22
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ParserTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@builder = Mactag::Builder.new
|
6
|
+
@parser = Mactag::Parser.new(@builder)
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'app' do
|
10
|
+
should 'be able to handle single argument' do
|
11
|
+
@parser.app('lib/**/*.rb')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'plugin' do
|
16
|
+
should 'be able to handle no arguments' do
|
17
|
+
@parser.plugin
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'be able to handle single argument' do
|
21
|
+
@parser.plugin('devise')
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be able to handle multiple arguments' do
|
25
|
+
@parser.plugins('devise', 'rack')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'gem' do
|
30
|
+
should 'be able to handle no arguments' do
|
31
|
+
@parser.gem
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'single argument' do
|
35
|
+
should 'be able to handle version' do
|
36
|
+
@parser.gem('devise', :version => '1.1.1')
|
37
|
+
end
|
38
|
+
|
39
|
+
should 'be able to handle no version' do
|
40
|
+
@parser.gem('devise')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'be able to handle multiple arguments' do
|
45
|
+
@parser.gem('devise', 'rack')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'rails' do
|
50
|
+
should 'be able to handle no arguments' do
|
51
|
+
@parser.rails
|
52
|
+
end
|
53
|
+
|
54
|
+
should 'be able to handle only' do
|
55
|
+
@parser.rails(:only => [])
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'be able to handle except' do
|
59
|
+
@parser.rails(:except => [])
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'be able to handle version' do
|
63
|
+
@parser.rails(:version => '3.0.0.rc')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/test/mactag/tag/app_test.rb
CHANGED
@@ -3,12 +3,12 @@ require 'test_helper'
|
|
3
3
|
class AppTest < ActiveSupport::TestCase
|
4
4
|
context 'application tag' do
|
5
5
|
setup do
|
6
|
-
@
|
7
|
-
@app = Mactag::Tag::App.new(@
|
6
|
+
@tag = 'app/**/*.rb'
|
7
|
+
@app = Mactag::Tag::App.new(@tag)
|
8
8
|
end
|
9
9
|
|
10
|
-
should 'return the
|
11
|
-
|
10
|
+
should 'return the same file as array' do
|
11
|
+
assert_equal @tag, @app.tag
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/test/mactag/tag/gem_test.rb
CHANGED
@@ -1,83 +1,136 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class GemTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
setup do
|
5
|
+
Mactag::Config.stubs(:gem_home).returns('GEM_HOME')
|
6
6
|
end
|
7
|
+
|
8
|
+
context '#tag' do
|
9
|
+
context 'for existing gem' do
|
10
|
+
context 'with no specified version' do
|
11
|
+
setup do
|
12
|
+
Mactag::Tag::Gem.stubs(:most_recent).returns('devise-1.1.1')
|
13
|
+
|
14
|
+
@gem = Mactag::Tag::Gem.new('devise')
|
15
|
+
@gem.stubs(:exists?).returns(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'return correct tag' do
|
19
|
+
assert_equal 'GEM_HOME/devise-1.1.1/lib/**/*.rb', @gem.tag
|
20
|
+
end
|
21
|
+
end
|
7
22
|
|
8
|
-
|
9
|
-
|
10
|
-
|
23
|
+
context 'with specified version' do
|
24
|
+
setup do
|
25
|
+
@gem = Mactag::Tag::Gem.new('devise', '1.1.1')
|
26
|
+
@gem.stubs(:exists?).returns(true)
|
27
|
+
end
|
11
28
|
|
12
|
-
|
29
|
+
should 'return correct tag' do
|
30
|
+
assert_equal 'GEM_HOME/devise-1.1.1/lib/**/*.rb', @gem.tag
|
31
|
+
end
|
32
|
+
end
|
13
33
|
end
|
14
34
|
|
15
|
-
should 'return
|
16
|
-
|
35
|
+
should 'return nil when gem does not exist' do
|
36
|
+
@gem = Mactag::Tag::Gem.new('devise')
|
37
|
+
@gem.stubs(:exists?).returns(false)
|
38
|
+
|
39
|
+
assert_nil @gem.tag
|
17
40
|
end
|
18
41
|
end
|
19
42
|
|
20
|
-
context '
|
21
|
-
|
22
|
-
|
23
|
-
Dir.stubs(:glob).returns(['whenever-0.3.7'])
|
43
|
+
context '#all' do
|
44
|
+
setup do
|
45
|
+
require 'bundler'
|
24
46
|
|
25
|
-
|
26
|
-
end
|
47
|
+
@runtime = Bundler.load
|
27
48
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
49
|
+
devise = ::Gem::Specification.new
|
50
|
+
devise.name = 'devise'
|
51
|
+
devise.version = '1.1.1'
|
32
52
|
|
33
|
-
|
34
|
-
|
35
|
-
|
53
|
+
rack = ::Gem::Specification.new
|
54
|
+
rack.name = 'rack'
|
55
|
+
rack.version = '1.2.1'
|
36
56
|
|
37
|
-
|
38
|
-
|
57
|
+
@runtime.stubs(:specs).returns([devise, rack])
|
58
|
+
end
|
39
59
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
60
|
+
should 'return the correct gems' do
|
61
|
+
devise = Mactag::Tag::Gem.all.first
|
62
|
+
assert_equal 'devise', devise.instance_variable_get('@name')
|
63
|
+
assert_equal '1.1.1', devise.instance_variable_get('@version')
|
64
|
+
|
65
|
+
rack = Mactag::Tag::Gem.all.last
|
66
|
+
assert_equal 'rack', rack.instance_variable_get('@name')
|
67
|
+
assert_equal '1.2.1', rack.instance_variable_get('@version')
|
44
68
|
end
|
45
69
|
end
|
46
70
|
|
47
|
-
context '
|
48
|
-
|
49
|
-
Dir.stubs(:glob).returns([])
|
50
|
-
File.stubs(:directory?).returns(false)
|
71
|
+
context '#most_recent' do
|
72
|
+
should 'return most recent gem if more than one version of same gem exists' do
|
73
|
+
Dir.stubs(:glob).returns(['vendor/plugins/devise-1.1.1', 'vendor/plugins/devise-1.1.0'])
|
51
74
|
|
52
|
-
|
75
|
+
assert_equal 'devise-1.1.1', Mactag::Tag::Gem.most_recent('devise')
|
53
76
|
end
|
54
77
|
|
55
|
-
should '
|
56
|
-
|
57
|
-
|
58
|
-
|
78
|
+
should 'return only gem if only one version of same gem exists' do
|
79
|
+
Dir.stubs(:glob).returns(['vendor/plugins/devise-1.1.1'])
|
80
|
+
|
81
|
+
assert_equal 'devise-1.1.1', Mactag::Tag::Gem.most_recent('devise')
|
59
82
|
end
|
60
|
-
end
|
61
83
|
|
62
|
-
|
63
|
-
|
64
|
-
|
84
|
+
should 'return nil if no version of gem' do
|
85
|
+
Dir.stubs(:glob).returns([])
|
86
|
+
|
87
|
+
assert_nil Mactag::Tag::Gem.most_recent('devise')
|
65
88
|
end
|
89
|
+
end
|
66
90
|
|
67
|
-
|
91
|
+
context '#exists' do
|
92
|
+
context 'with specified version' do
|
68
93
|
setup do
|
94
|
+
@gem = Mactag::Tag::Gem.new('devise', '1.1.1')
|
95
|
+
end
|
96
|
+
|
97
|
+
should 'return true when gem exists' do
|
69
98
|
File.stubs(:directory?).returns(true)
|
99
|
+
|
100
|
+
assert @gem.send(:exists?)
|
70
101
|
end
|
71
102
|
|
72
|
-
should 'exist' do
|
73
|
-
|
103
|
+
should 'return false when gem does not exist' do
|
104
|
+
File.stubs(:directory?).returns(false)
|
105
|
+
|
106
|
+
assert !@gem.send(:exists?)
|
74
107
|
end
|
75
108
|
end
|
76
|
-
|
77
|
-
context 'with no
|
78
|
-
|
79
|
-
|
109
|
+
|
110
|
+
context 'with no specified version' do
|
111
|
+
setup do
|
112
|
+
@gem = Mactag::Tag::Gem.new('devise')
|
80
113
|
end
|
114
|
+
|
115
|
+
should 'return true when gem exists' do
|
116
|
+
Mactag::Tag::Gem.stubs(:most_recent).returns('devise-1.1.1')
|
117
|
+
|
118
|
+
assert @gem.send(:exists?)
|
119
|
+
end
|
120
|
+
|
121
|
+
should 'return false when gem does not exist' do
|
122
|
+
Mactag::Tag::Gem.stubs(:most_recent).returns(nil)
|
123
|
+
|
124
|
+
assert !@gem.send(:exists?)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context '#splash' do
|
130
|
+
should 'return gem name, dash, version' do
|
131
|
+
@gem = Mactag::Tag::Gem.new('devise', '1.1.1')
|
132
|
+
|
133
|
+
assert_equal 'devise-1.1.1', @gem.send(:splash)
|
81
134
|
end
|
82
135
|
end
|
83
136
|
end
|
@@ -5,54 +5,53 @@ class PluginTest < ActiveSupport::TestCase
|
|
5
5
|
assert_equal 'vendor/plugins', Mactag::Tag::Plugin::PLUGIN_PATH
|
6
6
|
end
|
7
7
|
|
8
|
-
context '
|
8
|
+
context '#tag' do
|
9
9
|
setup do
|
10
|
-
@plugin = Mactag::Tag::Plugin.new
|
10
|
+
@plugin = Mactag::Tag::Plugin.new('devise')
|
11
11
|
end
|
12
12
|
|
13
|
-
should 'return
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with single plugin' do
|
19
|
-
setup do
|
20
|
-
File.stubs(:exist?).returns(true)
|
13
|
+
should 'return correct tag when plugin exists' do
|
14
|
+
@plugin.stubs(:exists?).returns(true)
|
21
15
|
|
22
|
-
@plugin
|
16
|
+
assert_equal 'vendor/plugins/devise/lib/**/*.rb', @plugin.tag
|
23
17
|
end
|
24
18
|
|
25
|
-
should 'return
|
26
|
-
|
19
|
+
should 'return nil when plugin does not exist' do
|
20
|
+
@plugin.stubs(:exists?).returns(false)
|
21
|
+
|
22
|
+
assert_nil @plugin.tag
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
|
-
context '
|
26
|
+
context '#exists' do
|
31
27
|
setup do
|
32
|
-
|
28
|
+
@plugin = Mactag::Tag::Plugin.new('devise')
|
29
|
+
end
|
33
30
|
|
34
|
-
|
31
|
+
should 'return true when plugin exists' do
|
32
|
+
File.stubs(:directory?).returns(true)
|
33
|
+
|
34
|
+
assert @plugin.send(:exists?)
|
35
35
|
end
|
36
36
|
|
37
|
-
should 'return
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
]
|
37
|
+
should 'return false when plugin does not exist' do
|
38
|
+
File.stubs(:directory?).returns(false)
|
39
|
+
|
40
|
+
assert !@plugin.send(:exists?)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
context '
|
46
|
-
|
47
|
-
|
44
|
+
context '#all' do
|
45
|
+
should 'return plugins when they exists' do
|
46
|
+
Dir.stubs(:glob).returns(['plugin/one', 'plugin/two'])
|
48
47
|
|
49
|
-
|
48
|
+
assert_same_elements Mactag::Tag::Plugin.all, ['one', 'two']
|
50
49
|
end
|
51
50
|
|
52
|
-
should '
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
should 'return an empty array when no plugins exist' do
|
52
|
+
Dir.stubs(:glob).returns([])
|
53
|
+
|
54
|
+
assert_same_elements Mactag::Tag::Plugin.all, []
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|