mactag 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,5 +4,5 @@ desc "Creates a Ctags file"
4
4
  task :mactag => :environment do
5
5
  require File.join(Rails.root, "config", "mactag")
6
6
 
7
- Mactag::Table.create
7
+ Mactag::Builder.create
8
8
  end
@@ -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
@@ -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', @binary
6
+ assert_equal 'ctags -o TAGS -e', Mactag::Config.binary
11
7
  end
12
8
  end
13
9
 
14
- context 'gem home' do
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
@@ -3,12 +3,12 @@ require 'test_helper'
3
3
  class AppTest < ActiveSupport::TestCase
4
4
  context 'application tag' do
5
5
  setup do
6
- @tags = ['app/**/*.rb', 'public/javascripts/*.js']
7
- @app = Mactag::Tag::App.new(@tags)
6
+ @tag = 'app/**/*.rb'
7
+ @app = Mactag::Tag::App.new(@tag)
8
8
  end
9
9
 
10
- should 'return the correct files' do
11
- assert_same_elements [@tags], @app.files
10
+ should 'return the same file as array' do
11
+ assert_equal @tag, @app.tag
12
12
  end
13
13
  end
14
14
  end
@@ -1,83 +1,136 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GemTest < ActiveSupport::TestCase
4
- def setup
5
- File.stubs(:directory?).returns(true)
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
- context 'gem with version' do
9
- setup do
10
- Mactag::Config.stubs(:gem_home).returns('GEM_HOME')
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
- @gem = Mactag::Tag::Gem.new('thinking-sphinx', :version => '1.0.0')
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 the gem with that version' do
16
- assert_contains @gem.files, File.join('GEM_HOME', 'thinking-sphinx-1.0.0', 'lib', '**', '*.rb')
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 'gem without version' do
21
- context 'single gem' do
22
- setup do
23
- Dir.stubs(:glob).returns(['whenever-0.3.7'])
43
+ context '#all' do
44
+ setup do
45
+ require 'bundler'
24
46
 
25
- @gem = Mactag::Tag::Gem.new('whenever')
26
- end
47
+ @runtime = Bundler.load
27
48
 
28
- should 'return that gem' do
29
- assert_contains @gem.files, File.join('whenever-0.3.7', 'lib', '**', '*.rb')
30
- end
31
- end
49
+ devise = ::Gem::Specification.new
50
+ devise.name = 'devise'
51
+ devise.version = '1.1.1'
32
52
 
33
- context 'multiple gems' do
34
- setup do
35
- Dir.stubs(:glob).returns(['whenever-0.3.7', 'whenever-0.3.6'])
53
+ rack = ::Gem::Specification.new
54
+ rack.name = 'rack'
55
+ rack.version = '1.2.1'
36
56
 
37
- @gem = Mactag::Tag::Gem.new('whenever')
38
- end
57
+ @runtime.stubs(:specs).returns([devise, rack])
58
+ end
39
59
 
40
- should 'return the gem with the latest version' do
41
- assert_contains @gem.files, File.join('whenever-0.3.7', 'lib', '**', '*.rb')
42
- assert_does_not_contain @gem.files, File.join('whenever-0.3.6', 'lib', '**', '*.rb')
43
- end
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 'gem that does not exist' do
48
- setup do
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
- @gem = Mactag::Tag::Gem.new('whenever')
75
+ assert_equal 'devise-1.1.1', Mactag::Tag::Gem.most_recent('devise')
53
76
  end
54
77
 
55
- should 'not raise exception because no such gem' do
56
- assert_nothing_raised do
57
- assert_equal [], @gem.files
58
- end
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
- context '#exists?' do
63
- setup do
64
- @gem = Mactag::Tag::Gem.new('whatever')
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
- context 'with valid gem' do
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
- assert @gem.send(:exists?, 'whatever')
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 gem' do
78
- should 'exist' do
79
- assert !@gem.send(:exists?, nil)
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 'with no arguments' do
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 all plugins as path' do
14
- assert_equal @plugin.files, 'vendor/plugins/*/lib/**/*.rb'
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 = Mactag::Tag::Plugin.new('thinking-sphinx')
16
+ assert_equal 'vendor/plugins/devise/lib/**/*.rb', @plugin.tag
23
17
  end
24
18
 
25
- should 'return the path to that plugin' do
26
- assert_same_elements ['vendor/plugins/thinking-sphinx/lib/**/*.rb'], @plugin.files
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 'with multiple plugins' do
26
+ context '#exists' do
31
27
  setup do
32
- File.stubs(:exist?).returns(true)
28
+ @plugin = Mactag::Tag::Plugin.new('devise')
29
+ end
33
30
 
34
- @plugin = Mactag::Tag::Plugin.new('thinking-sphinx', 'formtastic')
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 the paths to those plugins' do
38
- assert_same_elements @plugin.files, [
39
- 'vendor/plugins/thinking-sphinx/lib/**/*.rb',
40
- 'vendor/plugins/formtastic/lib/**/*.rb'
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 'plugin that does not exist' do
46
- setup do
47
- File.stubs(:exist?).returns(false)
44
+ context '#all' do
45
+ should 'return plugins when they exists' do
46
+ Dir.stubs(:glob).returns(['plugin/one', 'plugin/two'])
48
47
 
49
- @plugin = Mactag::Tag::Plugin.new('typo')
48
+ assert_same_elements Mactag::Tag::Plugin.all, ['one', 'two']
50
49
  end
51
50
 
52
- should 'not raise exception because no such plugin' do
53
- assert_nothing_raised do
54
- assert_same_elements [], @plugin.files
55
- end
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