mactag 0.4.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mactag::Bundler do
4
+ end
@@ -2,49 +2,43 @@ require 'spec_helper'
2
2
 
3
3
  describe Mactag::Config do
4
4
  describe '#binary' do
5
- it 'should have correct command' do
6
- Mactag::Config.binary.should == 'ctags -o {OUTPUT} -e {INPUT}'
5
+ it 'is correct command' do
6
+ Mactag::Config.binary.should eq('ctags -o {OUTPUT} -e {INPUT}')
7
7
  end
8
8
  end
9
-
9
+
10
10
  describe '#tags_file' do
11
- it 'should have correct name' do
12
- Mactag::Config.tags_file.should == 'TAGS'
11
+ it 'is correct name' do
12
+ Mactag::Config.tags_file.should eq('TAGS')
13
13
  end
14
14
  end
15
15
 
16
16
  describe '#gem_home' do
17
17
  context 'when using RVM' do
18
18
  before do
19
- Mactag::Config.stub!(:rvm).and_return(true)
20
- File.stub!(:join).and_return('/path/to/rvm/gems')
19
+ Mactag::Config.stub(:rvm) { true }
20
+ File.stub(:join) { '/path/to/rvm/gems' }
21
21
  end
22
22
 
23
- it 'should be the correct gems path' do
24
- Mactag::Config.gem_home.should == '/path/to/rvm/gems'
23
+ it 'is the correct gems path' do
24
+ Mactag::Config.gem_home.should eq('/path/to/rvm/gems')
25
25
  end
26
26
  end
27
27
 
28
28
  context 'when not using RVM' do
29
29
  before do
30
- Mactag::Config.stub!(:rvm).and_return(false)
30
+ Mactag::Config.stub(:rvm) { false }
31
31
  end
32
32
 
33
- it 'should be the default gem path' do
34
- Mactag::Config.gem_home.should == '/Library/Ruby/Gems/1.8/gems'
33
+ it 'is the default gem path' do
34
+ Mactag::Config.gem_home.should eq('/Library/Ruby/Gems/1.8/gems')
35
35
  end
36
36
  end
37
37
  end
38
38
 
39
39
  describe '#rvm' do
40
- it 'should be true by default' do
40
+ it 'is true by default' do
41
41
  Mactag::Config.rvm.should be_true
42
42
  end
43
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
44
  end
@@ -6,35 +6,35 @@ describe Mactag::Ctags do
6
6
  end
7
7
 
8
8
  describe '#initialize' do
9
- it 'should handle single file' do
9
+ it 'handles a single file' do
10
10
  @ctags = Mactag::Ctags.new('in', 'out')
11
- @ctags.instance_variable_get('@input').should =~ ['in']
11
+ @ctags.instance_variable_get('@input').should eq(['in'])
12
12
  end
13
13
 
14
- it 'should handle multiple files' do
14
+ it 'handles multiple files' do
15
15
  @ctags = Mactag::Ctags.new(['in_1', 'in_2'], 'out')
16
- @ctags.instance_variable_get('@input').should =~ ['in_1', 'in_2']
16
+ @ctags.instance_variable_get('@input').should eq(['in_1', 'in_2'])
17
17
  end
18
18
  end
19
19
 
20
20
  describe '#command' do
21
21
  before do
22
- Rails.stub!(:root).and_return('root')
23
- @ctags.stub!(:binary).and_return('binary')
22
+ Rails.stub(:root) { 'root' }
23
+ @ctags.stub(:binary) { 'binary' }
24
24
  end
25
25
 
26
- it 'should return correct command' do
27
- @ctags.send(:command).should == 'cd root && binary'
26
+ it 'is correct command' do
27
+ @ctags.send(:command).should eq('cd root && binary')
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#binary' do
32
32
  before do
33
- Mactag::Config.stub!(:binary).and_return('ctags -o {OUTPUT} -e {INPUT}')
33
+ Mactag::Config.stub(:binary) { 'ctags -o {OUTPUT} -e {INPUT}' }
34
34
  end
35
35
 
36
- it 'should return correct command' do
37
- @ctags.send(:binary).should == 'ctags -o out -e in'
36
+ it 'returns correct command' do
37
+ @ctags.send(:binary).should eq('ctags -o out -e in')
38
38
  end
39
39
  end
40
40
  end
@@ -2,65 +2,92 @@ require 'spec_helper'
2
2
 
3
3
  describe Mactag::Dsl do
4
4
  before do
5
- @builder = Mactag::Builder.new
6
- @dsl = Mactag::Dsl.new(@builder)
5
+ @dsl = Mactag::Dsl.new(Mactag::Builder.new)
7
6
  end
8
7
 
9
8
  describe '#app' do
10
- it_should_support_dsl 'single argument' do
9
+ it_does_not_support_dsl 'without arguments' do
10
+ @dsl.app
11
+ end
12
+
13
+ it_supports_dsl 'with single argument' do
11
14
  @dsl.app('lib/**/*.rb')
12
15
  end
16
+
17
+ it_supports_dsl 'with multiple arguments' do
18
+ @dsl.app('lib/**/*.rb', 'app/**/*.rb')
19
+ end
13
20
  end
14
21
 
15
22
  describe '#plugin' do
16
- it_should_support_dsl 'without arguments' do
23
+ it_supports_dsl 'without arguments' do
17
24
  @dsl.plugin
18
25
  end
19
26
 
20
- it_should_support_dsl 'single argument' do
27
+ it_supports_dsl 'with single argument' do
21
28
  @dsl.plugin('devise')
22
29
  end
23
30
 
24
- it_should_support_dsl 'multiple arguments' do
31
+ it_supports_dsl 'with multiple arguments' do
25
32
  @dsl.plugins('devise', 'rack')
26
33
  end
27
34
  end
28
35
 
29
36
  describe '#gem' do
30
- it_should_support_dsl 'without arguments' do
37
+ it_supports_dsl 'without arguments' do
31
38
  @dsl.gem
32
39
  end
33
40
 
34
- context 'single argument' do
35
- it_should_support_dsl 'with version' do
36
- @dsl.gem('devise', :version => '1.1.1')
41
+ context 'with single argument' do
42
+ it_supports_dsl 'without version' do
43
+ @dsl.gem('devise')
37
44
  end
38
45
 
39
- it_should_support_dsl 'without version' do
40
- @dsl.gem('devise')
46
+ it_supports_dsl 'with version' do
47
+ @dsl.gem('devise', :version => '1.1.1')
41
48
  end
42
49
  end
43
50
 
44
- it_should_support_dsl 'multiple arguments' do
45
- @dsl.gem('devise', 'rack')
51
+ context 'with multiple arguments' do
52
+ it_supports_dsl 'without version' do
53
+ @dsl.gems('devise', 'rack')
54
+ end
55
+
56
+ it_does_not_support_dsl 'with version' do
57
+ @dsl.gems('devise', 'rack', :version => '1.1.1')
58
+ end
46
59
  end
47
60
  end
48
61
 
49
62
  describe '#rails' do
50
- it_should_support_dsl 'without arguments' do
63
+ it_supports_dsl 'without arguments' do
51
64
  @dsl.rails
52
65
  end
53
66
 
54
- it_should_support_dsl 'packages only' do
67
+ it_supports_dsl 'with packages only' do
55
68
  @dsl.rails(:only => [])
56
69
  end
57
70
 
58
- it_should_support_dsl 'packages except' do
71
+ it_supports_dsl 'with packages except' do
59
72
  @dsl.rails(:except => [])
60
73
  end
61
74
 
62
- it_should_support_dsl 'with version' do
63
- @dsl.rails(:version => '3.0.0.rc')
75
+ context 'with version' do
76
+ it_supports_dsl do
77
+ @dsl.rails(:version => '3.0.0')
78
+ end
79
+
80
+ it_supports_dsl 'with only' do
81
+ @dsl.rails(:version => '3.0.0', :only => [])
82
+ end
83
+
84
+ it_supports_dsl 'with except' do
85
+ @dsl.rails(:version => '3.0.0', :except => [])
86
+ end
87
+ end
88
+
89
+ it_does_not_support_dsl 'with only and except' do
90
+ @dsl.rails(:only => [], :except => [])
64
91
  end
65
92
  end
66
93
  end
@@ -1,14 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
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
4
+ subject do
5
+ Mactag::Tag::App.new('app')
13
6
  end
7
+
8
+ it_should_behave_like 'tagger'
14
9
  end
@@ -1,110 +1,106 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mactag::Tag::Gem do
4
+ subject do
5
+ Mactag::Tag::Gem.new('devise')
6
+ end
7
+
8
+ it_should_behave_like 'tagger'
9
+
4
10
  before do
5
- Mactag::Config.stub!(:gem_home).and_return('GEM_HOME')
11
+ Mactag::Config.stub(:gem_home) { 'GEM_HOME' }
12
+
13
+ @gem = Mactag::Tag::Gem.new('devise')
6
14
  end
7
15
 
8
16
  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')
17
+ context 'when gem exists' do
18
+ before do
19
+ @gem.stub(:exists?) { true }
20
+ end
13
21
 
14
- @gem = Mactag::Tag::Gem.new('devise')
15
- @gem.stub!(:exists?).and_return(true)
22
+ context 'without version' do
23
+ before do
24
+ Mactag::Tag::Gem.stub(:last) { '1.1.1' }
16
25
  end
17
26
 
18
- it 'return correct tag' do
19
- @gem.tag.should == 'GEM_HOME/devise-1.1.1/lib/**/*.rb'
27
+ it 'returns path to gem' do
28
+ @gem.tag.should eq('GEM_HOME/devise-1.1.1/lib/**/*.rb')
20
29
  end
21
30
  end
22
31
 
23
- context 'with specified version' do
32
+ context 'with version' do
24
33
  before do
25
- @gem = Mactag::Tag::Gem.new('devise', '1.1.1')
26
- @gem.stub!(:exists?).and_return(true)
34
+ @gem.stub(:version) { '1.1.1' }
27
35
  end
28
36
 
29
- it 'return correct tag' do
30
- @gem.tag.should == 'GEM_HOME/devise-1.1.1/lib/**/*.rb'
37
+ it 'returns path to gem' do
38
+ @gem.tag.should eq('GEM_HOME/devise-1.1.1/lib/**/*.rb')
31
39
  end
32
40
  end
33
41
  end
34
42
 
35
- it 'return nil when gem does not exist' do
36
- @gem = Mactag::Tag::Gem.new('devise')
37
- @gem.stub!(:exists?).and_return(false)
43
+ context 'when gem does not exist' do
44
+ before do
45
+ @gem.stub(:exists?) { false }
46
+ end
38
47
 
39
- @gem.tag.should be_nil
48
+ it 'raises exception' do
49
+ proc {
50
+ @gem.tag
51
+ }.should raise_exception(Mactag::GemNotFoundError)
52
+ end
40
53
  end
41
54
  end
42
55
 
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
56
+ describe '#exists?' do
57
+ context 'without version' do
58
+ it 'is true when single version of gem exists' do
59
+ Dir.stub(:glob) { ['devise-1.1.1'] }
60
+ @gem.exists?.should be_true
61
+ end
55
62
 
56
- it 'should return nil if no version of gem' do
57
- Dir.stub!(:glob).and_return([])
63
+ it 'is true when multiple versions of gem exists' do
64
+ Dir.stub(:glob) { %w(devise-1.1.0 devise-1.1.1) }
65
+ @gem.exists?.should be_true
66
+ end
58
67
 
59
- Mactag::Tag::Gem.most_recent('devise').should be_nil
68
+ it 'is false when gem does not exist' do
69
+ Dir.stub(:glob) { [] }
70
+ @gem.exists?.should be_false
71
+ end
60
72
  end
61
73
  end
62
74
 
63
- describe '#exists' do
64
- context 'with specified version' do
75
+ describe '#last' do
76
+ context 'when no gems exists' do
65
77
  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
78
+ Mactag::Tag::Gem.stub(:dirs) { [] }
73
79
  end
74
80
 
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
81
+ it 'returns nil' do
82
+ Mactag::Tag::Gem.last('devise').should be_nil
79
83
  end
80
84
  end
81
85
 
82
- context 'with no specified version' do
86
+ context 'when single version of gem exist' do
83
87
  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
88
+ Mactag::Tag::Gem.stub(:dirs) { ['devise-1.1.1'] }
91
89
  end
92
90
 
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
91
+ it 'returns nil' do
92
+ Mactag::Tag::Gem.last('devise').should eq('1.1.1')
97
93
  end
98
94
  end
99
- end
100
95
 
101
- describe '#splash' do
102
- before do
103
- @gem = Mactag::Tag::Gem.new('devise', '1.1.1')
104
- end
96
+ context 'when multiple versions of gem exist' do
97
+ before do
98
+ Mactag::Tag::Gem.stub(:dirs) { ['devise-1.1.0', 'devise-1.1.1'] }
99
+ end
105
100
 
106
- it 'return gem name, dash, version' do
107
- @gem.send(:splash).should == 'devise-1.1.1'
101
+ it 'returns nil' do
102
+ Mactag::Tag::Gem.last('devise').should eq('1.1.1')
103
+ end
108
104
  end
109
105
  end
110
106
  end
@@ -1,57 +1,68 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mactag::Tag::Plugin do
4
- it 'should have correct plugin path' do
5
- Mactag::Tag::Plugin::PLUGIN_PATH.should == 'vendor/plugins'
4
+ subject do
5
+ Mactag::Tag::Plugin.new('devise')
6
+ end
7
+
8
+ before do
9
+ @plugin = Mactag::Tag::Plugin.new('devise')
6
10
  end
7
11
 
8
- describe '#tag' do
9
- before do
10
- @plugin = Mactag::Tag::Plugin.new('devise')
11
- end
12
+ it_should_behave_like 'tagger'
12
13
 
13
- it 'should return tag when plugin exist' do
14
- @plugin.stub!(:exists?).and_return(true)
14
+ it 'has correct plugin path' do
15
+ Mactag::Tag::Plugin::PLUGIN_PATH.should eq(['vendor', 'plugins'])
16
+ end
15
17
 
16
- @plugin.tag.should == 'vendor/plugins/devise/lib/**/*.rb'
18
+ describe '#tag' do
19
+ it 'returns path to plugin when plugin exists' do
20
+ @plugin.stub(:exists?) { true }
21
+ @plugin.tag.should eq('vendor/plugins/devise/lib/**/*.rb')
17
22
  end
18
23
 
19
- it 'should return nil when plugin does not exist' do
20
- @plugin.stub!(:exists?).and_return(false)
21
-
22
- @plugin.tag.should be_nil
24
+ it 'raises exception when plugin does not exist' do
25
+ @plugin.stub(:exists?) { false }
26
+ proc {
27
+ @plugin.tag
28
+ }.should raise_exception(Mactag::PluginNotFoundError)
23
29
  end
24
30
  end
25
31
 
26
- describe '#exists' do
27
- before do
28
- @plugin = Mactag::Tag::Plugin.new('devise')
32
+ describe '#path' do
33
+ it 'return path to plugin' do
34
+ @plugin.path.should eq('vendor/plugins/devise')
29
35
  end
36
+ end
30
37
 
31
- it 'should be true when plugin exist' do
32
- File.stub!(:directory?).and_return(true)
33
-
34
- @plugin.send(:exists?).should be_true
38
+ describe '#exists?' do
39
+ it 'is true when plugin directory exists' do
40
+ File.stub(:directory?) { true }
41
+ @plugin.exists?.should be_true
35
42
  end
36
43
 
37
- it 'should be false when plugin does not exist' do
38
- File.stub!(:directory?).and_return(false)
39
-
40
- @plugin.send(:exists?).should be_false
44
+ it 'is false when plugin directory does not exist' do
45
+ File.stub(:directory?) { false }
46
+ @plugin.exists?.should be_false
41
47
  end
42
48
  end
43
49
 
44
50
  describe '#all' do
45
- it 'return plugins when they exist' do
46
- Dir.stub!(:glob).and_return(['plugin/one', 'plugin/two'])
47
-
48
- Mactag::Tag::Plugin.all.should =~ ['one', 'two']
51
+ it 'returns empty array when no plugins' do
52
+ Dir.stub(:glob) { [] }
53
+ Mactag::Tag::Plugin.all.should be_empty
49
54
  end
50
55
 
51
- it 'return empty array when no plugins exist' do
52
- Dir.stub!(:glob).and_return([])
56
+ it 'returns plugin name when single plugin' do
57
+ Dir.stub(:glob) { ['vendor/plugins/devise'] }
58
+ Mactag::Tag::Plugin.all.should eq(['devise'])
59
+ end
53
60
 
54
- Mactag::Tag::Plugin.all.should be_empty
61
+ it 'returns plugin names when multiple plugins' do
62
+ Dir.stub(:glob) {
63
+ ['vendor/plugins/devise', 'vendor/plugins/simple_form']
64
+ }
65
+ Mactag::Tag::Plugin.all.should eq(['devise', 'simple_form'])
55
66
  end
56
67
  end
57
68
  end