rake_tasks 1.1.0 → 2.0.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,276 @@
1
+ #--
2
+ ################################################################################
3
+ # Copyright (C) 2011 Travis Herrick #
4
+ ################################################################################
5
+ # #
6
+ # \v^V,^!v\^/ #
7
+ # ~% %~ #
8
+ # { _ _ } #
9
+ # ( * - ) #
10
+ # | / | #
11
+ # \ _, / #
12
+ # \__.__/ #
13
+ # #
14
+ ################################################################################
15
+ # This program is free software: you can redistribute it #
16
+ # and/or modify it under the terms of the GNU Lesser General Public License #
17
+ # as published by the Free Software Foundation, #
18
+ # either version 3 of the License, or (at your option) any later version. #
19
+ ################################################################################
20
+ # This program is distributed in the hope that it will be useful, #
21
+ # but WITHOUT ANY WARRANTY; #
22
+ # without even the implied warranty of MERCHANTABILITY #
23
+ # or FITNESS FOR A PARTICULAR PURPOSE. #
24
+ # See the GNU Lesser General Public License for more details. #
25
+ # #
26
+ # You should have received a copy of the GNU Lesser General Public License #
27
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
28
+ ################################################################################
29
+ #++
30
+
31
+ require_relative File.join('../require'.split('/'))
32
+
33
+ class GemUnitTest < Test::Unit::TestCase
34
+ def setup
35
+ @class = RakeTasks::Gem
36
+ @spec_class = Gem::Specification
37
+ end
38
+
39
+ def test_proper_gem_name_failure
40
+ simple_expectation :getwd
41
+ File.stubs(:file? => false).with(gem_file)
42
+
43
+ assert_equal nil, @class.gem_title
44
+ end
45
+
46
+ def test_proper_gem_name
47
+ simple_expectation :getwd
48
+ simple_expectation :file?
49
+ simple_expectation :load_gem_spec
50
+
51
+ assert_equal 'TestGem', @class.gem_title
52
+ end
53
+
54
+ def test_set_version_error
55
+ simple_expectation :getwd
56
+ simple_expectation :file?
57
+ simple_expectation :load_gem_spec
58
+ simple_expectation :file_open
59
+
60
+ temp_file = StringIO.new
61
+ temp_file.expects(:close).with.at_least_once
62
+ temp_file.expects(:unlink).with.at_least_once
63
+ temp_file.expects(:flush).with.at_least_once
64
+ temp_file.expects(:path => '/tmp/path/file_name').with
65
+
66
+ Tempfile.expects(:new => temp_file)
67
+
68
+ FileUtils.stubs(:mv).raises(Errno::ENOENT)
69
+
70
+ assert_raises(Errno::ENOENT) { @class.version! '3.2.1' }
71
+ end
72
+
73
+ def test_set_version_in_different_formats
74
+ simple_expectation :getwd
75
+ simple_expectation :file?
76
+ simple_expectation :load_gem_spec
77
+ simple_expectation :mv
78
+
79
+ [
80
+ " = '0.0.1'",
81
+ "='0.0.1'",
82
+ " = '0.0.1'",
83
+ ' = "0.0.1"',
84
+ ' ="0.0.1"',
85
+ ].each do |version|
86
+ temp = simple_expectation :new_tempfile
87
+ new_spec = gem_spec_single_line(
88
+ version.sub(/(['"])\d+?\.\d+?\.\d+?(['"])/, "\\13.2.1\\1"))
89
+
90
+ File.expects(:open => gem_spec_single_line(version)).
91
+ with(gem_file, 'r').once
92
+
93
+ @class.version! '3.2.1'
94
+
95
+ assert_equal new_spec.string.strip, temp.string.strip
96
+ end
97
+ end
98
+
99
+ def test_set_version
100
+ simple_expectation :getwd
101
+ simple_expectation :file?
102
+ simple_expectation :load_gem_spec
103
+ simple_expectation :mv
104
+
105
+ temp_file = StringIO.new
106
+ temp_file.expects(:path => '/tmp/path/file_name').with.once
107
+
108
+ Tempfile.expects(:new => temp_file).once
109
+ File.expects(:open => gem_spec).with(gem_file, 'r').once
110
+
111
+ temp_file.expects(:close).with.once
112
+ temp_file.expects(:unlink).with.once
113
+ temp_file.expects(:flush).with.once
114
+
115
+ @class.version! '3.2.1'
116
+ assert_equal gem_spec('3.2.1').string.strip, temp_file.string.strip
117
+ end
118
+
119
+ def test_gem_version_defaults
120
+ spec = mock.responds_like(@spec_class.new)
121
+ spec.expects(:name).with.returns(gem_name).once
122
+ spec.expects(:version).with.returns(gem_version).once
123
+
124
+ @class.expects(:gem_spec).with.returns(spec).once
125
+
126
+ assert_equal version(gem_name, gem_version), @class.version
127
+ end
128
+
129
+ def test_gem_version
130
+ spec = mock.responds_like(@spec_class.new)
131
+ spec.expects(:name).with.returns(gem_name).once
132
+ spec.expects(:version).with.returns(gem_version).once
133
+ assert_equal version(gem_name, gem_version), @class.version(spec)
134
+ end
135
+
136
+ def test_gem_version_without_gemspec
137
+ assert_equal nil, @class.version(nil)
138
+ end
139
+
140
+ def test_no_gem_spec
141
+ simple_expectation :getwd
142
+ File.expects(:file?).with(gem_file).returns(false).once
143
+
144
+ spec = mock.responds_like(@spec_class)
145
+
146
+ assert_nil @class.gem_spec(spec)
147
+ end
148
+
149
+ def test_gem_spec
150
+ simple_expectation :getwd
151
+ simple_expectation :file?
152
+
153
+ spec = mock.responds_like(@spec_class)
154
+ gem_spec = mock.responds_like(@spec_class.new)
155
+
156
+ spec.expects(:load).with(gem_file).returns(gem_spec).once
157
+
158
+ gem_spec.expects(:kind_of?).with(spec).returns(true)
159
+
160
+ assert_kind_of spec, @class.gem_spec(spec)
161
+ end
162
+
163
+ def test_gem_spec_file
164
+ simple_expectation :getwd
165
+ File.expects(:file?).with(gem_file).returns(true, false).twice
166
+
167
+ assert_equal gem_file, @class.gem_spec_file
168
+ assert_equal nil, @class.gem_spec_file
169
+ end
170
+
171
+ def test_gem_file_existence
172
+ simple_expectation :getwd
173
+
174
+ File.expects(:file?).returns(true, false).with(gem_file).twice
175
+
176
+ assert_equal true, @class.gem_file?
177
+ assert_equal false, @class.gem_file?
178
+ end
179
+
180
+ ############################################################################
181
+ private
182
+ ############################################################################
183
+
184
+ def simple_expectation(method)
185
+ case method
186
+ when :getwd then Dir.expects(method => path).with.at_least_once
187
+ when :file? then File.expects(method => true).with(gem_file).at_least_once
188
+ when :load_gem_spec
189
+ @spec_class.expects(:load => gem_spec_stub).with(gem_file).at_least_once
190
+ when :mv then FileUtils.expects(:mv).at_least_once
191
+ when :file_open
192
+ File.expects(:open => gem_spec).with(gem_file, 'r').once
193
+ when :new_tempfile
194
+ temp_file = StringIO.new
195
+ temp_file.expects(:close).with.at_least_once
196
+ temp_file.expects(:unlink).with.at_least_once
197
+ temp_file.expects(:flush).with.at_least_once
198
+ temp_file.expects(:path => '/tmp/path/file_name').with
199
+ Tempfile.expects(:new => temp_file)
200
+ return temp_file
201
+ end
202
+ end
203
+
204
+ def gem_spec_stub
205
+ spec = mock.responds_like(@spec_class.new)
206
+ spec.stubs(
207
+ :name => gem_name,
208
+ :version => gem_version,
209
+ )
210
+ return spec
211
+ end
212
+
213
+ def gem_version
214
+ '0.0.1'
215
+ end
216
+
217
+ def gem_name
218
+ 'test_gem'
219
+ end
220
+
221
+ def version(gem, version)
222
+ '%s version %s' % [gem, version]
223
+ end
224
+
225
+ def gem_file
226
+ File.basename(path) + '.gemspec'
227
+ end
228
+
229
+ def path
230
+ '/root/path/' + gem_name
231
+ end
232
+
233
+ def gem_spec_single_line(version)
234
+ StringIO.new %Q{
235
+ Gem::Specification.new do |s|
236
+ s.name = 'test_gem'
237
+ s.version#{version}
238
+ end
239
+ }.strip
240
+
241
+ end
242
+
243
+ def gem_spec(version = gem_version)
244
+ StringIO.new %Q{
245
+ Gem::Specification.new do |s|
246
+ s.name = 'test_gem'
247
+ s.version = '#{version}'
248
+
249
+ s.summary = 'Basic test gem.'
250
+ s.description = %Q{
251
+ This gem is a test gem.
252
+ It is used in tests.
253
+ }.strip
254
+
255
+ s.author = 'Travis Herrick'
256
+ s.email = 'tthetoad@gmail.com'
257
+ s.homepage = 'http://www.bitbucket.org/ToadJamb/gems_test_gem'
258
+
259
+ s.license = 'LGPLv3'
260
+
261
+ s.extra_rdoc_files << 'README'
262
+
263
+ s.require_paths = ['lib']
264
+ s.files = Dir['*', 'lib/**/*.rb', 'license/*']
265
+ s.test_files = Dir['test/**/*.rb']
266
+
267
+ s.add_dependency 'rdoc', '~> 3.9.4'
268
+ s.add_dependency 'rake', '~> 0.9.2'
269
+
270
+ s.add_development_dependency 'mocha', '~> 0.10.0'
271
+
272
+ s.has_rdoc = true
273
+ end
274
+ }.strip
275
+ end
276
+ end
@@ -0,0 +1,125 @@
1
+ #--
2
+ ################################################################################
3
+ # Copyright (C) 2011 Travis Herrick #
4
+ ################################################################################
5
+ # #
6
+ # \v^V,^!v\^/ #
7
+ # ~% %~ #
8
+ # { _ _ } #
9
+ # ( * - ) #
10
+ # | / | #
11
+ # \ _, / #
12
+ # \__.__/ #
13
+ # #
14
+ ################################################################################
15
+ # This program is free software: you can redistribute it #
16
+ # and/or modify it under the terms of the GNU Lesser General Public License #
17
+ # as published by the Free Software Foundation, #
18
+ # either version 3 of the License, or (at your option) any later version. #
19
+ ################################################################################
20
+ # This program is distributed in the hope that it will be useful, #
21
+ # but WITHOUT ANY WARRANTY; #
22
+ # without even the implied warranty of MERCHANTABILITY #
23
+ # or FITNESS FOR A PARTICULAR PURPOSE. #
24
+ # See the GNU Lesser General Public License for more details. #
25
+ # #
26
+ # You should have received a copy of the GNU Lesser General Public License #
27
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
28
+ ################################################################################
29
+ #++
30
+
31
+ require_relative File.join('../require'.split('/'))
32
+
33
+ class TestsUnitTest < Test::Unit::TestCase
34
+ def setup
35
+ @class = RakeTasks::Tests
36
+ end
37
+
38
+ def test_file_name_to_task_name
39
+ assert_equal 'something', @class.task_name('test/unit/something_test.rb')
40
+ assert_equal 'something', @class.task_name('test/unit/test_something.rb')
41
+ end
42
+
43
+ def test_tests_exist
44
+ @class.expects(:root => 'root').with.once
45
+ Dir.expects(:[] => []).with('root/**').once
46
+ assert_equal false, @class.exist?
47
+
48
+ @class.expects(:root => 'root').with.once
49
+ Dir.expects(:[] => ['root/path']).with('root/**').once
50
+ assert @class.exist?
51
+ end
52
+
53
+ def test_file_list
54
+ @class.stubs(:root => 'root').with
55
+ @class.expects(:types => ['alphabet', 'number']).with.once
56
+
57
+ patterns.each do |pattern|
58
+ Dir.expects(
59
+ :[] => []).with("root/#{pattern}").once
60
+ case pattern
61
+ when /^\*/
62
+ Dir.expects(
63
+ :[] => ['root/alphabet/abc_test.rb', 'root/alphabet/def_test.rb']).
64
+ with("root/alphabet/#{pattern}").once
65
+ Dir.expects(
66
+ :[] => ['root/number/add_test.rb']).
67
+ with("root/number/#{pattern}").once
68
+ when /\*.rb$/
69
+ Dir.expects(:[] => []).with("root/alphabet/#{pattern}").once
70
+ Dir.expects(:[] => []).with("root/number/#{pattern}").once
71
+ end
72
+ end
73
+
74
+ assert_equal [
75
+ 'root/alphabet/abc_test.rb',
76
+ 'root/alphabet/def_test.rb',
77
+ 'root/number/add_test.rb',
78
+ ],
79
+ @class.file_list
80
+ end
81
+
82
+ def test_types
83
+ @class.stubs(:root => 'root')
84
+
85
+ File.stubs(:directory? => true)
86
+ File.expects(:directory? => false).with('root/file.rb').once
87
+
88
+ Dir.expects(:[] => [
89
+ 'root/mammal', 'root/marsupial', 'root/primate', 'root/file.rb']).
90
+ with('root/**').once
91
+
92
+ patterns.each do |pattern|
93
+ [
94
+ "root/mammal/#{pattern}",
95
+ "root/marsupial/#{pattern}",
96
+ "root/primate/#{pattern}",
97
+ ].each do |path|
98
+ if path =~ /primate/
99
+ Dir.expects(:[] => []).with(path).once
100
+ else
101
+ Dir.expects(:[] => [File.join(File.dirname(path), 'file_test.rb')]).
102
+ with(path).at_least(0)
103
+ end
104
+ end
105
+ end
106
+ #~ File.expects(:directory? => true).with('root/mammal').once
107
+ #~ File.expects(:directory? => true).with('root/marsupial').once
108
+ #~ File.expects(:directory? => true).with('root/primate').once
109
+ #~ File.expects(:directory? => false).with('root/file.rb').once
110
+
111
+ assert_equal ['mammal', 'marsupial'], @class.types
112
+ end
113
+
114
+ ############################################################################
115
+ private
116
+ ############################################################################
117
+
118
+ # The patterns that indicate that a file contains tests.
119
+ def patterns
120
+ [
121
+ '*_test.rb',
122
+ 'test_*.rb',
123
+ ]
124
+ end
125
+ end
metadata CHANGED
@@ -3,10 +3,10 @@ name: rake_tasks
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
7
- - 1
6
+ - 2
8
7
  - 0
9
- version: 1.1.0
8
+ - 0
9
+ version: 2.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Travis Herrick
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-26 00:00:00 -04:00
17
+ date: 2011-10-11 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,21 @@ dependencies:
47
47
  version: 0.9.2
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: mocha
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 10
61
+ - 0
62
+ version: 0.10.0
63
+ type: :development
64
+ version_requirements: *id003
50
65
  description: |-
51
66
  RakeTasks provides basic rake tasks for generating documentation,
52
67
  building and installing gems, and running tests.
@@ -65,14 +80,24 @@ files:
65
80
  - README
66
81
  - rakefile
67
82
  - rake_tasks.gemspec
83
+ - lib/rake_tasks.rb
68
84
  - lib/rake_tasks/rdoc.rb
69
85
  - lib/rake_tasks/gem.rb
70
86
  - lib/rake_tasks/doc.rb
71
87
  - lib/rake_tasks/test.rb
72
- - lib/rake_tasks.rb
73
- - license/gpl
74
- - license/lgpl
75
- - license/lgplv3-88x31.png
88
+ - lib/rake_tasks/lib/tests.rb
89
+ - lib/rake_tasks/lib/gem.rb
90
+ - lib/rake_tasks/lib/doc.rb
91
+ - license/lgplv3
92
+ - license/lgplv3.png
93
+ - license/gplv3
94
+ - test/require.rb
95
+ - test/unit/gem_unit_test.rb
96
+ - test/unit/tests_unit_test.rb
97
+ - test/unit/doc_unit_test.rb
98
+ - test/integration/tests_integration_test.rb
99
+ - test/integration/gem_integration_test.rb
100
+ - test/integration/doc_integration_test.rb
76
101
  has_rdoc: true
77
102
  homepage: http://www.bitbucket.org/ToadJamb/gems_rake_tasks
78
103
  licenses:
@@ -105,5 +130,11 @@ rubygems_version: 1.3.7
105
130
  signing_key:
106
131
  specification_version: 3
107
132
  summary: Basic rake tasks. You know you want some.
108
- test_files: []
109
-
133
+ test_files:
134
+ - test/require.rb
135
+ - test/unit/gem_unit_test.rb
136
+ - test/unit/tests_unit_test.rb
137
+ - test/unit/doc_unit_test.rb
138
+ - test/integration/tests_integration_test.rb
139
+ - test/integration/gem_integration_test.rb
140
+ - test/integration/doc_integration_test.rb