sdoc_all 0.1.0 → 0.2.0.1

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,66 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ class SdocAll
4
+ describe Gems do
5
+ def gem_mock(name, version)
6
+ mock(:gem, {
7
+ :name => name,
8
+ :version => version,
9
+ :full_name => "#{name}-#{version.join('.')}",
10
+ :sort_obj => [name, version],
11
+ :rdoc_options => [],
12
+ :full_gem_path => name,
13
+ :require_paths => [],
14
+ :extra_rdoc_files => []
15
+ })
16
+ end
17
+
18
+ before do
19
+ one_1 = gem_mock('one', [1])
20
+ one_2 = gem_mock('one', [2])
21
+ two_1 = gem_mock('two', [1])
22
+ two_2 = gem_mock('two', [2])
23
+ two_3 = gem_mock('two', [3])
24
+ three = gem_mock('three', [1])
25
+ four = gem_mock('four', [1])
26
+ five = gem_mock('five', [1])
27
+
28
+ @all_specs = [one_1, one_2, two_1, two_2, two_3, three, four, five]
29
+ @latest_specs = [one_2, two_3, three, four, five]
30
+
31
+ Gems.stub!(:latest_specs).and_return(@latest_specs)
32
+ Gems.stub!(:all_specs).and_return(@all_specs)
33
+ end
34
+
35
+ it "should add one selected tasks" do
36
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'gems.one-2'))
37
+ Gems.new('one').add_tasks
38
+ end
39
+
40
+ it "should add two selected tasks" do
41
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'gems.one-2'))
42
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'gems.two-3'))
43
+ Gems.new(['one', 'two']).add_tasks
44
+ end
45
+
46
+ it "should add tasks except excluded" do
47
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'gems.four-1'))
48
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'gems.five-1'))
49
+ Gems.new(:exclude => ['one', 'two', 'three']).add_tasks
50
+ end
51
+
52
+ it "should add tasks for latest gems" do
53
+ @latest_specs.each do |gem_spec|
54
+ Base.should_receive(:add_task).with(hash_including(:doc_path => "gems.#{gem_spec.full_name}"))
55
+ end
56
+ Gems.new({}).add_tasks
57
+ end
58
+
59
+ it "should add tasks for all gems" do
60
+ @all_specs.each do |gem_spec|
61
+ Base.should_receive(:add_task).with(hash_including(:doc_path => "gems.#{gem_spec.full_name}"))
62
+ end
63
+ Gems.new(:versions => 'all').add_tasks
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ class SdocAll
4
+ describe Paths do
5
+ it "should determine common path part" do
6
+ paths = %w(/aaa/bbb/ccc/ddd/a.rb /aaa/bbb/ccc/ddd/b.rb /aaa/bbb/ccc/readme).map{ |path| Pathname.new(path) }
7
+ Paths.common_path(paths).should == Pathname.new('/aaa/bbb')
8
+ end
9
+
10
+ it "should add task for string config" do
11
+ @roots = {}
12
+ [:a, :b, :c].each do |sym|
13
+ @roots[sym] = mock(sym, :expand_path => mock("#{sym}_exp".to_sym, :exist? => true, :relative_path_from => "lala/#{sym}_exp"))
14
+ Pathname.should_receive(:new).with("#{sym}").and_return(@roots[sym])
15
+ Base.should_receive(:add_task).with(:doc_path => "paths.lala/#{sym}_exp", :src_path => @roots[sym].expand_path)
16
+ end
17
+ Paths.should_receive(:common_path).with([@roots[:a], @roots[:b], @roots[:c]].map(&:expand_path)).and_return('/common')
18
+
19
+ File.should_receive(:expand_path).with('*').and_return('/common/lala/*')
20
+ Dir.should_receive(:[]).with('/common/lala/*').and_return(['a', 'b', 'c'])
21
+ Paths.new('*').add_tasks
22
+ end
23
+
24
+ it "should add task for array of strings config" do
25
+ @roots = {}
26
+ [:a, :b, :d, :e].each do |sym|
27
+ @roots[sym] = mock(sym, :expand_path => mock("#{sym}_exp".to_sym, :exist? => true, :relative_path_from => "lala/#{sym}_exp"))
28
+ Pathname.should_receive(:new).with("#{sym}").and_return(@roots[sym])
29
+ Base.should_receive(:add_task).with(:doc_path => "paths.lala/#{sym}_exp", :src_path => @roots[sym].expand_path)
30
+ end
31
+ Paths.should_receive(:common_path).with([@roots[:a], @roots[:b], @roots[:d], @roots[:e]].map(&:expand_path)).and_return('/common')
32
+
33
+ File.should_receive(:expand_path).with('*').and_return('/common/lala/*')
34
+ File.should_receive(:expand_path).with('**').and_return('/common/common/lala/*')
35
+ Dir.should_receive(:[]).with('/common/lala/*').and_return(['a', 'b'])
36
+ Dir.should_receive(:[]).with('/common/common/lala/*').and_return(['d', 'e'])
37
+ Paths.new(['*', '**']).add_tasks
38
+ end
39
+
40
+ describe "for hash config" do
41
+ before do
42
+ @root = mock(:root, :expand_path => mock(:root_exp, :exist? => true, :relative_path_from => "lala/root"))
43
+ Pathname.should_receive(:new).with('/lalala/lala/root').and_return(@root)
44
+ Paths.should_receive(:common_path).with([@root.expand_path]).and_return('/common')
45
+ end
46
+
47
+ it "should add task" do
48
+ Base.should_receive(:add_task).with(:doc_path => "paths.lala/root", :src_path => @root.expand_path)
49
+ Paths.new({:root => '/lalala/lala/root'}).add_tasks
50
+ end
51
+
52
+ it "should add task with main" do
53
+ Base.should_receive(:add_task).with(:doc_path => "paths.lala/root", :src_path => @root.expand_path, :main => 'special_readme')
54
+ Paths.new({:root => '/lalala/lala/root', :main => 'special_readme'}).add_tasks
55
+ end
56
+
57
+ it "should add task with with one include" do
58
+ @file_list = mock(:file_list, :resolve => true)
59
+ Rake::FileList.stub!(:new).and_return(@file_list)
60
+ Dir.should_receive(:chdir).with(@root.expand_path).and_yield
61
+ @file_list.should_receive(:include).with('*.rb')
62
+ @file_list.should_receive(:to_a).and_return(['a.rb', 'b.rb'])
63
+
64
+ Base.should_receive(:add_task).with(:doc_path => "paths.lala/root", :src_path => @root.expand_path, :paths => ['a.rb', 'b.rb'])
65
+ Paths.new({:root => '/lalala/lala/root', :paths => '*.rb'}).add_tasks
66
+ end
67
+
68
+ it "should add task with with array of includes and excludes" do
69
+ @file_list = mock(:file_list, :resolve => true)
70
+ Rake::FileList.stub!(:new).and_return(@file_list)
71
+ Dir.should_receive(:chdir).with(@root.expand_path).and_yield
72
+ @file_list.should_receive(:include).ordered.with('*.*')
73
+ @file_list.should_receive(:exclude).ordered.with('*.cgi')
74
+ @file_list.should_receive(:include).ordered.with('README')
75
+ @file_list.should_receive(:include).ordered.with('README_*')
76
+ @file_list.should_receive(:exclude).ordered.with('*.tmp')
77
+ @file_list.should_receive(:to_a).and_return(['a.rb', 'b.rb', 'README', 'README_en'])
78
+
79
+ Base.should_receive(:add_task).with(:doc_path => "paths.lala/root", :src_path => @root.expand_path, :paths => ['a.rb', 'b.rb', 'README', 'README_en'])
80
+ Paths.new({:root => '/lalala/lala/root', :paths => ['*.*', '-*.cgi', '+README', '+README_*', '-*.tmp']}).add_tasks
81
+ end
82
+ end
83
+
84
+ describe "for array of hashes config" do
85
+ it "should add task" do
86
+ @root = mock(:root, :expand_path => mock(:root_exp, :exist? => true, :relative_path_from => "lala/root"))
87
+ Pathname.should_receive(:new).with('/lalala/lala/root').and_return(@root)
88
+
89
+ @other = mock(:other, :expand_path => mock(:other_exp, :exist? => true, :relative_path_from => "lolo/other"))
90
+ Pathname.should_receive(:new).with('/lalala/lolo/other').and_return(@other)
91
+
92
+ Paths.should_receive(:common_path).with([@root, @other].map(&:expand_path)).and_return('/common')
93
+
94
+ Base.should_receive(:add_task).with(:doc_path => "paths.lala/root", :src_path => @root.expand_path)
95
+ Base.should_receive(:add_task).with(:doc_path => "paths.lolo/other", :src_path => @other.expand_path)
96
+
97
+ Paths.new([{:root => '/lalala/lala/root'}, {:root => '/lalala/lolo/other'}]).add_tasks
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ class SdocAll
4
+ describe Plugins do
5
+ def plugin_mock(name, options = {})
6
+ mock(:plugin, :basename => name, :directory? => !options[:not_directory], :+ => mock(:git_dir, :directory? => !options[:no_git]))
7
+ end
8
+
9
+ before do
10
+ @one = mock(:one, :expand_path => mock(:one_expanded, :directory? => true))
11
+ end
12
+
13
+ describe "path" do
14
+ before do
15
+ @one.stub!(:mkpath)
16
+ @one.expand_path.stub!(:children).and_return([])
17
+ end
18
+
19
+ it "should set default path if none given" do
20
+ Plugins.stub!(:sources_path).and_return('sources/plugins')
21
+ Pathname.should_receive(:new).with('sources/plugins').and_return(@one)
22
+ Plugins.new(nil).add_tasks
23
+ end
24
+
25
+ it "should asume that lone argument is path" do
26
+ Pathname.should_receive(:new).with('one').and_return(@one)
27
+ Plugins.new('one').add_tasks
28
+ end
29
+ end
30
+
31
+ describe "update" do
32
+ before do
33
+ @a = plugin_mock('a')
34
+ @b = plugin_mock('b', :no_git => true)
35
+ @c = plugin_mock('c', :not_directory => true)
36
+ @one.expand_path.should_receive(:children).and_return([@a, @b, @c])
37
+ Pathname.should_receive(:new).with('one').and_return(@one)
38
+ end
39
+
40
+ it "should update plugins using git" do
41
+ Base.should_receive(:system).once.with("git fetch origin && git reset --hard origin")
42
+ Base.stub!(:add_task)
43
+ Plugins.new(:path => 'one').add_tasks(:update => true)
44
+ end
45
+
46
+ it "should not update plugins when config disables it" do
47
+ Base.should_not_receive(:system)
48
+ Base.stub!(:add_task)
49
+ Plugins.new(:path => 'one', :update => false).add_tasks
50
+ end
51
+ end
52
+
53
+ describe "adding" do
54
+ before do
55
+ @a = plugin_mock('a')
56
+ @b = plugin_mock('b')
57
+ @c = plugin_mock('c')
58
+ @one.expand_path.should_receive(:children).and_return([@a, @b, @c])
59
+ Pathname.should_receive(:new).with('one').and_return(@one)
60
+ end
61
+
62
+ it "should add tasks" do
63
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'plugins.a'))
64
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'plugins.b'))
65
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'plugins.c'))
66
+ Plugins.new(:path => 'one').add_tasks
67
+ end
68
+
69
+ it "should add only selected tasks" do
70
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'plugins.a'))
71
+ Plugins.new(:path => 'one', :only => 'a').add_tasks
72
+ end
73
+
74
+ it "should add not excluded tasks" do
75
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'plugins.a'))
76
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'plugins.c'))
77
+ Plugins.new(:path => 'one', :exclude => 'b').add_tasks
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ class SdocAll
4
+ describe Rails do
5
+ before do
6
+ Rails.stub!(:versions).and_return(['1.2.3', '1.3.5', '1.5.9'])
7
+ end
8
+
9
+ describe "adding task" do
10
+ before do
11
+ File.should_receive(:open).with('vendor/rails/railties/lib/tasks/documentation.rake')
12
+ end
13
+
14
+ it "should add task" do
15
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'rails-1.3.5'))
16
+ Rails.new(:version => '1.3.5').add_tasks
17
+ end
18
+
19
+ it "should use latest version if none given" do
20
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'rails-1.5.9'))
21
+ Rails.new(nil).add_tasks
22
+ end
23
+
24
+ it "should use lone argument as version" do
25
+ Base.should_receive(:add_task).with(hash_including(:doc_path => 'rails-1.3.5'))
26
+ Rails.new('1.3.5').add_tasks
27
+ end
28
+ end
29
+
30
+ it "should raise for wrong version" do
31
+ proc{
32
+ Rails.new('1.1.1').add_tasks
33
+ }.should raise_error(SdocAll::ConfigError)
34
+ end
35
+
36
+ describe "creating app" do
37
+ before do
38
+ Base.stub!(:add_task)
39
+ File.stub!(:open)
40
+ end
41
+
42
+ it "should create rails app" do
43
+ FileTest.should_receive(:directory?).with("sources/rails/1.3.5").and_return(false)
44
+ Base.should_receive(:remove_if_present).with(Pathname.new("sources/rails"))
45
+ Base.should_receive(:system).with("rails", Pathname.new("sources/rails/1.3.5"), "--freeze")
46
+ Rails.new('1.3.5').add_tasks
47
+ end
48
+
49
+ it "should not create rails app if it already exists" do
50
+ FileTest.should_receive(:directory?).with("sources/rails/1.3.5").and_return(true)
51
+ Base.should_not_receive(:remove_if_present)
52
+ Base.should_not_receive(:system)
53
+ Rails.new('1.3.5').add_tasks
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,199 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ class SdocAll
4
+ describe Ruby do
5
+ describe "subroutines" do
6
+ describe "match_ruby_archive" do
7
+ it "should return nil if does not match" do
8
+ Ruby.match_ruby_archive('').should be_nil
9
+ Ruby.match_ruby_archive('ruby').should be_nil
10
+ Ruby.match_ruby_archive('ruby-1.2.3-p666.tar').should be_nil
11
+ end
12
+
13
+ %w(tar.bz2 tar.gz zip).each do |ext|
14
+ it "should return info if match" do
15
+ @archive = Ruby.match_ruby_archive("path/ruby-1.2.3-p666.#{ext}")
16
+ @archive.should be_an(Ruby::ArchiveInfo)
17
+ @archive.path.should == "path/ruby-1.2.3-p666.#{ext}"
18
+ @archive.name.should == "ruby-1.2.3-p666.#{ext}"
19
+ @archive.full_version.should == "1.2.3-p666"
20
+ @archive.extension.should == ext
21
+ @archive.version.should == [1, 2, 3, 666]
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "last_matching_ruby_archive" do
27
+ it "should return nil if could nothing match" do
28
+ Ruby.last_matching_ruby_archive('2.0.0', %w(path/ruby-1.2.3-p666.zip .DS_Store)).should be_nil
29
+ end
30
+
31
+ it "should return latest matching" do
32
+ @archive = Ruby.last_matching_ruby_archive('2.0.0', %w(
33
+ path/ruby-1.0.0-p333.zip
34
+ path/ruby-2.0.0-p444.zip
35
+ path/ruby-3.0.0-p444.zip
36
+ path/ruby-2.0.0-p666.zip
37
+ path/ruby-3.0.0-p666.zip
38
+ path/ruby-2.0.0-p555.zip
39
+ path/ruby-3.0.0-p777.zip
40
+ .DS_Store
41
+ ))
42
+ @archive.should be_an(Ruby::ArchiveInfo)
43
+ @archive.path.should == "path/ruby-2.0.0-p666.zip"
44
+ end
45
+ end
46
+
47
+ describe "find_matching_archive" do
48
+ it "should call last_matching_ruby_archive for all files in sources" do
49
+ @files = mock(:files)
50
+ @children = mock(:children)
51
+ @children.should_receive(:select).and_return(@files)
52
+ @sources_path = mock(:sources_path, :parent => mock(:parent, :children => @children))
53
+ Ruby.stub!(:sources_path).and_return(@sources_path)
54
+
55
+ Ruby.should_receive(:last_matching_ruby_archive).with('1.2.3', @files)
56
+ Ruby.find_matching_archive('1.2.3')
57
+ end
58
+ end
59
+
60
+ describe "download_matching_archive" do
61
+ before do
62
+ @ftp = mock(:ftp, :debug_mode= => nil, :passive= => nil, :login => nil)
63
+ @ftp.should_receive(:chdir).with('/pub/ruby')
64
+ @list = ['mode user ... a', 'mode user ... b', 'mode user ... c']
65
+ @paths = ['/pub/ruby/a', '/pub/ruby/b', '/pub/ruby/c']
66
+ @ftp.should_receive(:list).with('ruby-*.tar.bz2').and_return(@list)
67
+ Net::FTP.should_receive(:open).with('ftp.ruby-lang.org').and_yield(@ftp)
68
+ end
69
+
70
+ it "should not download anything if no matces" do
71
+ @ftp.should_not_receive(:size)
72
+ @ftp.should_not_receive(:getbinaryfile)
73
+
74
+ Ruby.should_receive(:last_matching_ruby_archive).with('1.2.3', @paths).and_return(nil)
75
+ Ruby.download_matching_archive('1.2.3')
76
+ end
77
+
78
+ describe "when match" do
79
+ before do
80
+ @tar = mock(:tar, :name => 'abc', :path => '/path')
81
+ end
82
+
83
+ it "should download if it does not exist locally" do
84
+ File.stub!(:exist?).and_return(false)
85
+ @ftp.should_receive(:getbinaryfile)
86
+
87
+ Ruby.should_receive(:last_matching_ruby_archive).with('1.2.3', @paths).and_return(@tar)
88
+ Ruby.download_matching_archive('1.2.3')
89
+ end
90
+
91
+ it "should download if local file size is not equal to remote" do
92
+ File.stub!(:exist?).and_return(true)
93
+ File.stub!(:size).and_return(1000)
94
+ @ftp.stub!(:size).and_return(2000)
95
+ @ftp.should_receive(:getbinaryfile)
96
+
97
+ Ruby.should_receive(:last_matching_ruby_archive).with('1.2.3', @paths).and_return(@tar)
98
+ Ruby.download_matching_archive('1.2.3')
99
+ end
100
+
101
+ it "should not download if local file size is to remote" do
102
+ File.stub!(:exist?).and_return(true)
103
+ File.stub!(:size).and_return(2000)
104
+ @ftp.stub!(:size).and_return(2000)
105
+ @ftp.should_not_receive(:getbinaryfile)
106
+
107
+ Ruby.should_receive(:last_matching_ruby_archive).with('1.2.3', @paths).and_return(@tar)
108
+ Ruby.download_matching_archive('1.2.3')
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "find_or_download_matching_archive" do
114
+ before do
115
+ @archive = mock(:archive)
116
+ end
117
+
118
+ it "should immediately return match if update not allowed" do
119
+ Ruby.should_receive(:find_matching_archive).with('1.2.3').once.and_return(@archive)
120
+ Ruby.should_not_receive(:download_matching_archive)
121
+
122
+ Ruby.find_or_download_matching_archive('1.2.3', :update => false).should == @archive
123
+ end
124
+
125
+ it "should downlaod and return match if update allowed" do
126
+ Ruby.should_receive(:download_matching_archive).with('1.2.3').once.ordered
127
+ Ruby.should_receive(:find_matching_archive).with('1.2.3').once.ordered.and_return(@archive)
128
+
129
+ Ruby.find_or_download_matching_archive('1.2.3', :update => true).should == @archive
130
+ end
131
+
132
+ it "should downlaod and return match if not found local" do
133
+ Ruby.should_receive(:find_matching_archive).with('1.2.3').once.ordered.and_return(nil, @archive)
134
+ Ruby.should_receive(:download_matching_archive).with('1.2.3').once.ordered
135
+
136
+ Ruby.find_or_download_matching_archive('1.2.3').should == @archive
137
+ end
138
+
139
+ it "should raise if can not find local or downlaod archive" do
140
+ Ruby.should_receive(:find_matching_archive).with('1.2.3').once.ordered.and_return(nil, nil)
141
+ Ruby.should_receive(:download_matching_archive).with('1.2.3').once.ordered
142
+
143
+ proc{
144
+ Ruby.find_or_download_matching_archive('1.2.3').should == @archive
145
+ }.should raise_error(SdocAll::ConfigError)
146
+ end
147
+ end
148
+ end
149
+
150
+ it "should raise error if version not specified" do
151
+ proc{ Ruby.new(nil).add_tasks }.should raise_error(SdocAll::ConfigError)
152
+ end
153
+
154
+ it "should raise error if version is blank" do
155
+ proc{ Ruby.new(:version => ' ').add_tasks }.should raise_error(SdocAll::ConfigError)
156
+ end
157
+
158
+ describe "extracting archive and adding task" do
159
+ before do
160
+ @path = mock(:path)
161
+ @sources_path = mock(:sources_path)
162
+ @archive = mock(:archive, :full_version => '1.2.3-p666', :extension => 'tar.bz2', :path => 'sources/ruby-1.2.3-p666.tar.bz2')
163
+ @sources_path.should_receive(:+).with('1.2.3-p666').and_return(@path)
164
+ Ruby.stub!(:sources_path).and_return(@sources_path)
165
+ Ruby.should_receive(:find_or_download_matching_archive).with('1.2.3')
166
+ Ruby.should_receive(:find_or_download_matching_archive).with('1.2.3', :update => true).and_return(@archive)
167
+ Base.stub!(:add_task)
168
+ end
169
+
170
+ it "should not extract archive if matching directory already exists" do
171
+ @path.stub!(:directory?).and_return(true)
172
+ Base.should_not_receive(:remove_if_present)
173
+ Base.should_not_receive(:system)
174
+
175
+ Ruby.new(:version => '1.2.3').add_tasks(:update => true)
176
+ end
177
+
178
+ it "should extract archive if matching directory does not exist" do
179
+ @path.stub!(:directory?).and_return(false)
180
+ Base.should_receive(:remove_if_present).with(@sources_path)
181
+ Base.should_receive(:system).with("tar", "-xjf", "sources/ruby-1.2.3-p666.tar.bz2", "-C", @sources_path)
182
+ @path2 = mock(:path2)
183
+ @sources_path.should_receive(:+).with('ruby-1.2.3-p666').and_return(@path2)
184
+ File.should_receive(:rename).with(@path2, @path)
185
+
186
+ Ruby.new(:version => '1.2.3').add_tasks(:update => true)
187
+ end
188
+
189
+ it "should finally add task" do
190
+ @path.stub!(:directory?).and_return(true)
191
+ Base.should_not_receive(:remove_if_present)
192
+ Base.should_not_receive(:system)
193
+ Base.should_receive(:add_task).with(:doc_path => "ruby-1.2.3-p666", :src_path => @path)
194
+
195
+ Ruby.new(:version => '1.2.3').add_tasks(:update => true)
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe SdocAll do
4
+ config_yaml = %Q{
5
+ sdoc:
6
+ - ruby:
7
+ path: 1.8.6
8
+ - rails
9
+ - rails:
10
+ - gems:
11
+ exclude:
12
+ - rails
13
+ - mysql
14
+ - plugins:
15
+ path: ~/.plugins
16
+ - path: ~/lib/bin
17
+ }
18
+
19
+ describe "run" do
20
+ it "should call read_config, call run for each task and merge docs" do
21
+ SdocAll::Base.stub!(:docs_path).and_return(Pathname.new('/docs'))
22
+ SdocAll::Base.stub!(:public_path).and_return(Pathname.new('/public'))
23
+
24
+ @tasks = []
25
+ @each = @tasks.should_receive(:each_with_progress)
26
+ %w(a b c).each do |c|
27
+ task = mock(c, :doc_path => "#{c}", :src_path => "/sources/#{c}", :title => "<#{c}>")
28
+ task.should_receive(:run)
29
+ File.should_receive(:file?).with(Pathname.new("/docs/#{c}/index.html")).and_return(true)
30
+ @each.and_yield(task)
31
+ @tasks << task
32
+ end
33
+
34
+ SdocAll.should_receive(:read_config)
35
+ SdocAll::Base.should_receive(:tasks).and_return(@tasks)
36
+ SdocAll::Base.should_receive(:system).with('sdoc-merge', '-o', Pathname.new('/public'), '-t', 'all', '-n', '<a>,<b>,<c>', '-u', '/docs/a /docs/b /docs/c', 'a', 'b', 'c')
37
+ SdocAll.should_receive(:store_current_sdoc_version)
38
+ SdocAll.run
39
+ end
40
+ end
41
+
42
+ describe "read_config" do
43
+ it "should read config" do
44
+ YAML.should_receive(:load_file).with('config.yml').and_return(YAML.load(config_yaml))
45
+
46
+ SdocAll::Base.should_receive(:to_document).ordered.with('ruby', {'path' => '1.8.6'})
47
+ SdocAll::Base.should_receive(:to_document).ordered.with('rails', {})
48
+ SdocAll::Base.should_receive(:to_document).ordered.with('rails', nil)
49
+ SdocAll::Base.should_receive(:to_document).ordered.with('gems', {'exclude' => ['rails', 'mysql']})
50
+ SdocAll::Base.should_receive(:to_document).ordered.with('plugins', {'path' => '~/.plugins'})
51
+ SdocAll::Base.should_receive(:to_document).ordered.with('path', '~/lib/bin')
52
+
53
+ SdocAll.read_config
54
+ end
55
+
56
+ it "should raise if config is empty" do
57
+ YAML.stub!(:load_file).and_return(nil)
58
+ proc{ SdocAll.read_config }.should raise_error(SdocAll::ConfigError)
59
+ end
60
+
61
+ it "should raise if config is not a hash" do
62
+ YAML.stub!(:load_file).and_return('')
63
+ proc{ SdocAll.read_config }.should raise_error(SdocAll::ConfigError)
64
+ end
65
+
66
+ it "should raise if sdoc is empty" do
67
+ YAML.stub!(:load_file).and_return('')
68
+ proc{ SdocAll.read_config }.should raise_error(SdocAll::ConfigError)
69
+ end
70
+
71
+ it "should raise if sdoc entry is wrong" do
72
+ YAML.stub!(:load_file).and_return YAML.load(%Q{
73
+ sdoc:
74
+ - ruby:
75
+ version: 1.8.6
76
+ })
77
+ proc{ SdocAll.read_config }.should raise_error(SdocAll::ConfigError)
78
+ end
79
+ end
80
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ gem 'rspec'
3
+ require 'spec'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require 'sdoc_all'
8
+
9
+ Spec::Runner.configure do |config|
10
+ config.prepend_before do
11
+ SdocAll::Base.stub!(:system)
12
+ SdocAll::Base.stub!(:remove_if_present)
13
+ Dir.stub!(:chdir).and_yield
14
+ Net::FTP.stub!(:open)
15
+ File.stub!(:symlink)
16
+
17
+ SdocAll.constants.each do |constant|
18
+ klass = SdocAll.const_get(constant)
19
+ if klass.is_a?(Class) && klass.superclass == SdocAll::Base
20
+ klass.stub!(:sources_path).and_return(Pathname.new("sources/#{constant.downcase}"))
21
+ end
22
+ end
23
+ end
24
+ end