mattknox-jeweler 0.7.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,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class <%= constant_name %>Test < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require '<%= file_name_prefix %>'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,81 @@
1
+ class Jeweler
2
+ class Version
3
+ attr_accessor :base_dir
4
+ attr_reader :major, :minor, :patch
5
+
6
+ def initialize(base_dir)
7
+ self.base_dir = base_dir
8
+
9
+ if File.exists?(yaml_path)
10
+ parse_yaml
11
+ end
12
+ end
13
+
14
+ def bump_major
15
+ @major += 1
16
+ @minor = 0
17
+ @patch = 0
18
+ end
19
+
20
+ def bump_minor
21
+ @minor += 1
22
+ @patch = 0
23
+ end
24
+
25
+ def bump_patch
26
+ @patch += 1
27
+ end
28
+
29
+ def update_to(major, minor, patch)
30
+ @major = major
31
+ @minor = minor
32
+ @patch = patch
33
+ end
34
+
35
+ def write
36
+ File.open(yaml_path, 'w+') do |f|
37
+ YAML.dump(self.to_hash, f)
38
+ end
39
+ end
40
+
41
+ def to_s
42
+ "#{major}.#{minor}.#{patch}"
43
+ end
44
+
45
+ def to_hash
46
+ {
47
+ :major => major,
48
+ :minor => minor,
49
+ :patch => patch
50
+ }
51
+ end
52
+
53
+ def refresh
54
+ parse_yaml
55
+ end
56
+
57
+ def yaml_path
58
+ denormalized_path = File.join(@base_dir, 'VERSION.yml')
59
+ absolute_path = File.expand_path(denormalized_path)
60
+ absolute_path.gsub(Dir.getwd + File::SEPARATOR, '')
61
+ end
62
+
63
+ protected
64
+
65
+ def parse_yaml
66
+ yaml = read_yaml
67
+ @major = (yaml['major'] || yaml[:major]).to_i
68
+ @minor = (yaml['minor'] || yaml[:minor]).to_i
69
+ @patch = (yaml['patch'] || yaml[:patch]).to_i
70
+ end
71
+
72
+ def read_yaml
73
+ if File.exists?(yaml_path)
74
+ YAML.load_file(yaml_path)
75
+ else
76
+ raise VersionYmlError, "#{yaml_path} does not exist!"
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ major: 1
3
+ minor: 5
4
+ patch: 2
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class JewelerGeneratorInitializerTest < Test::Unit::TestCase
4
+ context "given a nil github repo name" do
5
+ setup do
6
+ @block = lambda { Jeweler::Generator.new(nil) }
7
+ end
8
+
9
+ should "raise an error" do
10
+ assert_raise Jeweler::NoGitHubRepoNameGiven do
11
+ @block.call
12
+ end
13
+ end
14
+ end
15
+
16
+ context "without git user's name set" do
17
+ setup do
18
+ Jeweler::Generator.any_instance.stubs(:read_git_config).returns({'user.email' => 'bar@example.com'})
19
+ end
20
+
21
+ context "instantiating new generator" do
22
+ setup do
23
+ @block = lambda { Jeweler::Generator.new('the-perfect-gem')}
24
+ end
25
+
26
+ should "raise no git user name exception" do
27
+ assert_raise Jeweler::NoGitUserName do
28
+ @block.call
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ context "without git user's email set" do
35
+ setup do
36
+ Jeweler::Generator.any_instance.stubs(:read_git_config).returns({'user.name' => 'foo'})
37
+ end
38
+
39
+ context "instantiating new generator" do
40
+ setup do
41
+ @block = lambda { Jeweler::Generator.new('the-perfect-gem')}
42
+ end
43
+
44
+ should "raise no git user name exception" do
45
+ assert_raise Jeweler::NoGitUserEmail do
46
+ @block.call
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ context "without github username set" do
53
+ setup do
54
+ Jeweler::Generator.any_instance.stubs(:read_git_config).
55
+ returns({'user.email' => 'bar@example.com', 'user.name' => 'foo'})
56
+ end
57
+
58
+ context "instantiating new generator" do
59
+ setup do
60
+ @block = lambda { Jeweler::Generator.new('the-perfect-gem')}
61
+ end
62
+
63
+ should "raise no github user exception" do
64
+ assert_raise Jeweler::NoGitHubUser do
65
+ @block.call
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ context "without github token set" do
72
+ setup do
73
+ Jeweler::Generator.any_instance.stubs(:read_git_config).
74
+ returns({'user.email' => 'bar@example.com', 'user.name' => 'foo', 'github.user' => 'technicalpickles'})
75
+ end
76
+
77
+ context "instantiating new generator" do
78
+ setup do
79
+ @block = lambda { Jeweler::Generator.new('the-perfect-gem')}
80
+ end
81
+
82
+ should "raise no github user exception" do
83
+ assert_raise Jeweler::NoGitHubToken do
84
+ @block.call
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ context "with valid git user configuration" do
91
+ setup do
92
+ Jeweler::Generator.any_instance.stubs(:read_git_config).
93
+ returns({'user.name' => 'foo', 'user.email' => 'bar@example.com', 'github.user' => 'technicalpickles', 'github.token' => 'zomgtoken'})
94
+ end
95
+
96
+ context "for technicalpickle's the-perfect-gem repository" do
97
+ setup do
98
+ @generator = Jeweler::Generator.new('the-perfect-gem')
99
+ end
100
+
101
+ should "assign 'foo' to user's name" do
102
+ assert_equal 'foo', @generator.user_name
103
+ end
104
+
105
+ should "assign 'bar@example.com to user's email" do
106
+ assert_equal 'bar@example.com', @generator.user_email
107
+ end
108
+
109
+ should "assign github remote" do
110
+ assert_equal 'git@github.com:technicalpickles/the-perfect-gem.git', @generator.github_remote
111
+ end
112
+
113
+ should "determine github username as technicalpickles" do
114
+ assert_equal 'technicalpickles', @generator.github_username
115
+ end
116
+
117
+ should "determine github repository name as the-perfect-gem" do
118
+ assert_equal 'the-perfect-gem', @generator.github_repo_name
119
+ end
120
+
121
+ should "determine github url as http://github.com/technicalpickles/the-perfect-gem" do
122
+ assert_equal 'http://github.com/technicalpickles/the-perfect-gem', @generator.github_url
123
+ end
124
+
125
+ should "determine target directory as the same as the github repository name" do
126
+ assert_equal @generator.github_repo_name, @generator.target_dir
127
+ end
128
+
129
+ should "determine lib directory as being inside the target directory" do
130
+ assert_equal File.join(@generator.target_dir, 'lib'), @generator.lib_dir
131
+ end
132
+
133
+ should "determine test directory as being inside the target directory" do
134
+ assert_equal File.join(@generator.target_dir, 'test'), @generator.test_dir
135
+ end
136
+
137
+ should "determine constant name as ThePerfectGem" do
138
+ assert_equal 'ThePerfectGem', @generator.constant_name
139
+ end
140
+
141
+ should "determine file name prefix as the_perfect_gem" do
142
+ assert_equal 'the_perfect_gem', @generator.file_name_prefix
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,35 @@
1
+ class Test::Unit::TestCase
2
+ class << self
3
+ def should_have_major_version(version)
4
+ should "have major version of #{version}" do
5
+ assert_equal version, @jeweler.major_version
6
+ end
7
+ end
8
+
9
+ def should_have_minor_version(version)
10
+ should "have minor version of #{version}" do
11
+ assert_equal version, @jeweler.minor_version
12
+ end
13
+ end
14
+
15
+ def should_have_patch_version(version)
16
+ should "have patch version of #{version}" do
17
+ assert_equal version, @jeweler.patch_version
18
+ end
19
+ end
20
+
21
+ def should_be_version(version)
22
+ should "be version #{version}" do
23
+ assert_equal version, @jeweler.version
24
+ end
25
+ end
26
+
27
+ def should_bump_version(major, minor, patch)
28
+ version = "#{major}.#{minor}.#{patch}"
29
+ should_have_major_version major
30
+ should_have_minor_version minor
31
+ should_have_patch_version patch
32
+ should_be_version version
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TestGemspec < Test::Unit::TestCase
4
+ context "A Jeweler::GemSpec, given a gemspec" do
5
+ setup do
6
+ @spec = build_spec
7
+ @helper = Jeweler::GemSpecHelper.new(@spec, File.dirname(__FILE__))
8
+ end
9
+
10
+ should 'have sane gemspec path' do
11
+ assert_equal "test/#{@spec.name}.gemspec", @helper.path
12
+ end
13
+ end
14
+
15
+ context "Jeweler::GemSpec#write" do
16
+ setup do
17
+ @spec = build_spec
18
+ @helper = Jeweler::GemSpecHelper.new(@spec)
19
+ FileUtils.rm_f(@helper.path)
20
+
21
+ @helper.write
22
+ end
23
+
24
+ should "create gemspec file" do
25
+ assert File.exists?(@helper.path)
26
+ end
27
+
28
+ should "make valid spec" do
29
+ assert @helper.valid?
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,269 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TestGenerator < Test::Unit::TestCase
4
+ def self.should_create_directory(directory)
5
+ should "create #{directory} directory" do
6
+ assert File.exists?(File.join(@tmp_dir, directory))
7
+ assert File.directory?(File.join(@tmp_dir, directory))
8
+ end
9
+ end
10
+
11
+ def self.should_create_files(*files)
12
+ should "create #{files.join ', '}" do
13
+ files.each do |file|
14
+ assert File.exists?(File.join(@tmp_dir, file))
15
+ assert File.file?(File.join(@tmp_dir, file))
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.should_be_checked_in(*files)
21
+ should "have #{files.join ', '} checked in" do
22
+ files.each do |file|
23
+ status = @repo.status[file]
24
+ assert_not_nil status, "wasn't able to get status for #{file}"
25
+ assert ! status.untracked, "#{file} was untracked"
26
+ assert_nil status.type, "#{file} had a type. it should have been nil"
27
+ end
28
+ end
29
+ end
30
+
31
+ def self.should_have_sane_license
32
+ context "LICENSE" do
33
+ setup do
34
+ @content = File.read((File.join(@tmp_dir, 'LICENSE')))
35
+ end
36
+
37
+ should "include copyright for this year with user's name" do
38
+ assert_match 'Copyright (c) 2008 foo', @content
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.should_have_sane_gitignore
44
+ context ".gitignore" do
45
+ setup do
46
+ @content = File.read((File.join(@tmp_dir, '.gitignore')))
47
+ end
48
+
49
+ should "include vim swap files" do
50
+ assert_match '*.sw?', @content
51
+ end
52
+
53
+ should "include coverage" do
54
+ assert_match 'coverage', @content
55
+ end
56
+
57
+ should "include .DS_Store" do
58
+ assert_match '.DS_Store', @content
59
+ end
60
+ end
61
+ end
62
+
63
+ def self.should_have_sane_rakefile(options)
64
+ context "Rakefile" do
65
+ setup do
66
+ @content = File.read((File.join(@tmp_dir, 'Rakefile')))
67
+ end
68
+
69
+ should "include repo's name as the gem's name" do
70
+ assert_match 's.name = "the-perfect-gem"', @content
71
+ end
72
+
73
+ should "include the user's email as the gem's email" do
74
+ assert_match 's.email = "bar@example.com"', @content
75
+ end
76
+
77
+ should "include the summary in the gem" do
78
+ assert_match %Q{s.summary = %Q{zomg, so good}}, @content
79
+ end
80
+
81
+ should "include the github repo's url as the gem's url" do
82
+ assert_match 's.homepage = "http://github.com/technicalpickles/the-perfect-gem"', @content
83
+ end
84
+
85
+ should "include #{options[:pattern]} in the TestTask" do
86
+ assert_match "t.pattern = '#{options[:pattern]}'", @content
87
+ end
88
+
89
+ should "include #{options[:pattern]} in the RcovTask" do
90
+ assert_match "t.test_files = FileList['#{options[:pattern]}']", @content
91
+ end
92
+
93
+ should "push #{options[:libs]} dir into RcovTask libs" do
94
+ assert_match "t.libs << '#{options[:libs]}'", @content
95
+ end
96
+ end
97
+ end
98
+
99
+ def self.should_have_sane_origin_remote
100
+ should "have git@github.com:technicalpickles/the-perfect-gem.git as origin remote" do
101
+ assert_equal 1, @repo.remotes.size
102
+ remote = @repo.remotes.first
103
+ assert_equal 'origin', remote.name
104
+ assert_equal 'git@github.com:technicalpickles/the-perfect-gem.git', remote.url
105
+ end
106
+ end
107
+
108
+ context "with valid git user configuration" do
109
+ setup do
110
+ Jeweler::Generator.any_instance.stubs(:read_git_config).
111
+ returns({'user.name' => 'foo', 'user.email' => 'bar@example.com', 'github.user' => 'technicalpickles', 'github.token' => 'zomgtoken'})
112
+ end
113
+
114
+ context "and cleaned out tmp directory" do
115
+ setup do
116
+ @tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
117
+ FileUtils.rm_rf(@tmp_dir)
118
+
119
+ assert ! File.exists?(@tmp_dir)
120
+ end
121
+
122
+ teardown do
123
+ FileUtils.rm_rf(@tmp_dir)
124
+ end
125
+
126
+ context "for generating technicalpickles's the-perfect-gem repo in 'tmp'" do
127
+ setup do
128
+ @generator = Jeweler::Generator.new('the-perfect-gem', :directory => @tmp_dir, :summary => 'zomg, so good')
129
+ end
130
+
131
+ should "use tmp for target directory" do
132
+ assert_equal @tmp_dir, @generator.target_dir
133
+ end
134
+
135
+ context "running with default test style" do
136
+ setup do
137
+ @output = catch_out { @generator.run }
138
+ end
139
+
140
+ should 'create target directory' do
141
+ assert File.exists?(@tmp_dir)
142
+ end
143
+
144
+ should_create_directory 'lib'
145
+ should_create_directory 'test'
146
+
147
+ should_create_files 'LICENSE', 'README', 'lib/the_perfect_gem.rb', 'test/test_helper.rb', 'test/the_perfect_gem_test.rb', '.gitignore'
148
+
149
+ should_have_sane_rakefile :libs => 'test', :pattern => 'test/**/*_test.rb'
150
+ should_have_sane_license
151
+ should_have_sane_gitignore
152
+
153
+
154
+ context "test/the_perfect_gem_test.rb" do
155
+ setup do
156
+ @content = File.read((File.join(@tmp_dir, 'test', 'the_perfect_gem_test.rb')))
157
+ end
158
+
159
+ should "have class of ThePerfectGemTest" do
160
+ assert_match 'class ThePerfectGemTest < Test::Unit::TestCase', @content
161
+ end
162
+ end
163
+
164
+
165
+ context "created git repo" do
166
+ setup do
167
+ @repo = Git.open(@tmp_dir)
168
+ end
169
+
170
+ should "have one commit log an initial commit message" do
171
+ assert_equal 1, @repo.log.size
172
+ # TODO message seems to include leading whitespace, could probably fix that in ruby-git
173
+ assert_match 'Initial commit to the-perfect-gem.', @repo.log.first.message
174
+ end
175
+
176
+ should_be_checked_in 'README', 'Rakefile', 'LICENSE', 'lib/the_perfect_gem.rb', 'test/test_helper.rb', 'test/the_perfect_gem_test.rb', '.gitignore'
177
+
178
+ should "have no untracked files" do
179
+ assert_equal 0, @repo.status.untracked.size
180
+ end
181
+
182
+ should "have no changed files" do
183
+ assert_equal 0, @repo.status.changed.size
184
+ end
185
+
186
+ should "have no added files" do
187
+ assert_equal 0, @repo.status.added.size
188
+ end
189
+
190
+ should "have no deleted files" do
191
+ assert_equal 0, @repo.status.deleted.size
192
+ end
193
+
194
+ should_have_sane_origin_remote
195
+ end
196
+ end
197
+
198
+ context "running with bacon test style" do
199
+ setup do
200
+ @generator.test_style = :bacon
201
+ @output = catch_out {
202
+ @generator.run
203
+ }
204
+ end
205
+
206
+ should 'create target directory' do
207
+ assert File.exists?(@tmp_dir)
208
+ end
209
+
210
+ should_create_directory 'lib'
211
+ should_create_directory 'spec'
212
+
213
+ should_create_files 'LICENSE', 'README', 'lib/the_perfect_gem.rb', 'spec/spec_helper.rb', 'spec/the_perfect_gem_spec.rb', '.gitignore'
214
+
215
+ should_have_sane_rakefile :libs => 'spec', :pattern => 'spec/**/*_spec.rb'
216
+ should_have_sane_license
217
+ should_have_sane_gitignore
218
+
219
+
220
+ context "spec/the_perfect_gem_spec.rb" do
221
+ setup do
222
+ @content = File.read((File.join(@tmp_dir, 'spec', 'the_perfect_gem_spec.rb')))
223
+ end
224
+
225
+ should "describe ThePerfectGem" do
226
+ assert_match 'describe "ThePerfectGem" do', @content
227
+ end
228
+ end
229
+
230
+
231
+ context "created git repo" do
232
+ setup do
233
+ @repo = Git.open(@tmp_dir)
234
+ end
235
+
236
+ should 'have one commit log' do
237
+ assert_equal 1, @repo.log.size
238
+ end
239
+
240
+ should "have one commit log an initial commit message" do
241
+ # TODO message seems to include leading whitespace, could probably fix that in ruby-git
242
+ assert_match 'Initial commit to the-perfect-gem.', @repo.log.first.message
243
+ end
244
+
245
+ should_be_checked_in 'README', 'Rakefile', 'LICENSE', 'lib/the_perfect_gem.rb', 'spec/spec_helper.rb', 'spec/the_perfect_gem_spec.rb', '.gitignore'
246
+
247
+ should "have no untracked files" do
248
+ assert_equal 0, @repo.status.untracked.size
249
+ end
250
+
251
+ should "have no changed files" do
252
+ assert_equal 0, @repo.status.changed.size
253
+ end
254
+
255
+ should "have no added files" do
256
+ assert_equal 0, @repo.status.added.size
257
+ end
258
+
259
+ should "have no deleted files" do
260
+ assert_equal 0, @repo.status.deleted.size
261
+ end
262
+
263
+ should_have_sane_origin_remote
264
+ end
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end