technicalpickles-jeweler 0.3.2 → 0.3.3
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.
- data/Rakefile +1 -0
- data/VERSION.yml +1 -1
- data/lib/jeweler/generator.rb +34 -11
- data/test/jeweler_generator_test.rb +185 -0
- metadata +13 -4
data/Rakefile
CHANGED
@@ -17,6 +17,7 @@ begin
|
|
17
17
|
s.authors = ["Josh Nichols", "Dan Croak"]
|
18
18
|
s.bindir = 'bin'
|
19
19
|
s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
|
20
|
+
s.add_dependency 'schacon-git'
|
20
21
|
end
|
21
22
|
rescue LoadError
|
22
23
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
data/lib/jeweler/generator.rb
CHANGED
@@ -2,13 +2,29 @@ require 'git'
|
|
2
2
|
require 'erb'
|
3
3
|
|
4
4
|
class Jeweler
|
5
|
+
class NoGitUserName < StandardError
|
6
|
+
end
|
7
|
+
class NoGitUserEmail < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
class FileInTheWay < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
class NoRemoteGiven < StandardError
|
14
|
+
end
|
15
|
+
|
5
16
|
class Generator
|
6
17
|
attr_accessor :target_dir, :user_name, :user_email, :github_repo_name, :github_remote, :github_url, :github_username, :lib_dir
|
7
18
|
|
8
19
|
def initialize(github_remote, dir = nil)
|
9
|
-
|
20
|
+
if github_remote.nil?
|
21
|
+
raise NoRemoteGiven
|
22
|
+
end
|
23
|
+
|
10
24
|
self.github_remote = github_remote
|
25
|
+
|
11
26
|
check_user_git_config()
|
27
|
+
|
12
28
|
determine_github_stuff()
|
13
29
|
|
14
30
|
self.target_dir = dir || self.github_repo_name
|
@@ -16,23 +32,22 @@ class Jeweler
|
|
16
32
|
end
|
17
33
|
|
18
34
|
def check_user_git_config
|
19
|
-
|
20
|
-
config = lib.parse_config '~/.gitconfig'
|
35
|
+
config = read_git_config
|
21
36
|
unless config.has_key? 'user.name'
|
22
|
-
|
23
|
-
exit 1
|
37
|
+
raise NoGitUserName, %Q{No user.name set in ~/.gitconfig. Set it with: git config --global user.name 'Your Name Here'}
|
24
38
|
end
|
25
39
|
unless config.has_key? 'user.email'
|
26
|
-
|
27
|
-
exit 1
|
40
|
+
raise NoGitUserEmail, %Q{No user.name set in ~/.gitconfig. Set it with: git config --global user.name 'Your Name Here'}
|
28
41
|
end
|
29
|
-
|
30
|
-
@
|
42
|
+
|
43
|
+
@user_name = config['user.name']
|
44
|
+
@user_email = config['user.email']
|
31
45
|
end
|
32
46
|
|
33
47
|
def determine_github_stuff
|
34
|
-
self.github_url = self.github_remote.gsub(/^git@github\.com:/, 'http://github.com/').gsub(/\.git$/, '
|
48
|
+
self.github_url = self.github_remote.gsub(/^git@github\.com:/, 'http://github.com/').gsub(/\.git$/, '')
|
35
49
|
self.github_repo_name = self.github_remote.match(/\/(.*)\.git$/)[1]
|
50
|
+
self.github_username = self.github_remote.match(%r{git@github\.com:(.*)/})[1]
|
36
51
|
end
|
37
52
|
|
38
53
|
def run
|
@@ -50,9 +65,11 @@ class Jeweler
|
|
50
65
|
|
51
66
|
license = template('LICENSE')
|
52
67
|
File.open(File.join(target_dir, 'LICENSE'), 'w') {|file| file.write(license.result(binding))}
|
68
|
+
|
69
|
+
readme = template('README')
|
70
|
+
File.open(File.join(target_dir, 'README'), 'w') {|file| file.write(readme.result(binding))}
|
53
71
|
|
54
72
|
FileUtils.touch File.join(lib_dir, "#{github_repo_name}.rb")
|
55
|
-
|
56
73
|
end
|
57
74
|
|
58
75
|
def template(file)
|
@@ -75,5 +92,11 @@ class Jeweler
|
|
75
92
|
end
|
76
93
|
Dir.chdir(saved_pwd)
|
77
94
|
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
def read_git_config
|
98
|
+
lib = Git::Lib.new(nil, nil)
|
99
|
+
config = lib.parse_config '~/.gitconfig'
|
100
|
+
end
|
78
101
|
end
|
79
102
|
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class JewelerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@github_remote = 'git@github.com:technicalpickles/the-perfect-gem.git'
|
7
|
+
end
|
8
|
+
|
9
|
+
context "given a nil github remote" do
|
10
|
+
setup do
|
11
|
+
@block = lambda { Jeweler::Generator.new(nil) }
|
12
|
+
end
|
13
|
+
|
14
|
+
should "raise an error" do
|
15
|
+
assert_raise Jeweler::NoRemoteGiven do
|
16
|
+
@block.call
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "without git user's name set" do
|
22
|
+
setup do
|
23
|
+
Jeweler::Generator.any_instance.stubs(:read_git_config).returns({'user.email' => 'bar@example.com'})
|
24
|
+
end
|
25
|
+
|
26
|
+
context "instantiating new generator" do
|
27
|
+
setup do
|
28
|
+
@block = lambda { Jeweler::Generator.new('git@github.com:technicalpickles/the-perfect-gem.git')}
|
29
|
+
end
|
30
|
+
|
31
|
+
should "raise no git user name exception" do
|
32
|
+
assert_raise Jeweler::NoGitUserName do
|
33
|
+
@block.call
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "without git user's email set" do
|
40
|
+
setup do
|
41
|
+
Jeweler::Generator.any_instance.stubs(:read_git_config).returns({'user.name' => 'foo'})
|
42
|
+
end
|
43
|
+
|
44
|
+
context "instantiating new generator" do
|
45
|
+
setup do
|
46
|
+
@block = lambda { Jeweler::Generator.new('git@github.com:technicalpickles/the-perfect-gem.git')}
|
47
|
+
end
|
48
|
+
|
49
|
+
should "raise no git user name exception" do
|
50
|
+
assert_raise Jeweler::NoGitUserEmail do
|
51
|
+
@block.call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with valid git user configuration" do
|
58
|
+
setup do
|
59
|
+
Jeweler::Generator.any_instance.stubs(:read_git_config).returns({'user.name' => 'foo', 'user.email' => 'bar@example.com'})
|
60
|
+
end
|
61
|
+
|
62
|
+
context "for a repository 'git@github.com:technicalpickles/the-perfect-gem.git'" do
|
63
|
+
setup do
|
64
|
+
@generator = Jeweler::Generator.new('git@github.com:technicalpickles/the-perfect-gem.git')
|
65
|
+
end
|
66
|
+
|
67
|
+
should "assign 'foo' to user's name" do
|
68
|
+
assert_equal 'foo', @generator.user_name
|
69
|
+
end
|
70
|
+
|
71
|
+
should "assign 'bar@example.com to user's email" do
|
72
|
+
assert_equal 'bar@example.com', @generator.user_email
|
73
|
+
end
|
74
|
+
|
75
|
+
should "assign github remote" do
|
76
|
+
assert_equal 'git@github.com:technicalpickles/the-perfect-gem.git', @generator.github_remote
|
77
|
+
end
|
78
|
+
|
79
|
+
should "determine github username as technicalpickles" do
|
80
|
+
assert_equal 'technicalpickles', @generator.github_username
|
81
|
+
end
|
82
|
+
|
83
|
+
should "determine github repository name as the-perfect-gem" do
|
84
|
+
assert_equal 'the-perfect-gem', @generator.github_repo_name
|
85
|
+
end
|
86
|
+
|
87
|
+
should "determine github url as http://github.com/technicalpickles/the-perfect-gem" do
|
88
|
+
assert_equal 'http://github.com/technicalpickles/the-perfect-gem', @generator.github_url
|
89
|
+
end
|
90
|
+
|
91
|
+
should "determine target directory as the same as the github repository name" do
|
92
|
+
assert_equal @generator.github_repo_name, @generator.target_dir
|
93
|
+
end
|
94
|
+
|
95
|
+
should "determine lib directory as being inside the target directory" do
|
96
|
+
assert_equal File.join(@generator.target_dir, 'lib'), @generator.lib_dir
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
context "and cleaned out tmp directory" do
|
102
|
+
setup do
|
103
|
+
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
104
|
+
FileUtils.rm_rf(@tmp_dir)
|
105
|
+
|
106
|
+
assert ! File.exists?(@tmp_dir)
|
107
|
+
end
|
108
|
+
|
109
|
+
teardown do
|
110
|
+
FileUtils.rm_rf(@tmp_dir)
|
111
|
+
end
|
112
|
+
|
113
|
+
context "for a repository 'git@github.com:technicalpickles/the-perfect-gem.git' and working directory 'tmp'" do
|
114
|
+
setup do
|
115
|
+
@generator = Jeweler::Generator.new('git@github.com:technicalpickles/the-perfect-gem.git', @tmp_dir)
|
116
|
+
end
|
117
|
+
|
118
|
+
should "use tmp for target directory" do
|
119
|
+
assert_equal @tmp_dir, @generator.target_dir
|
120
|
+
end
|
121
|
+
|
122
|
+
context "running" do
|
123
|
+
setup do
|
124
|
+
@generator.run
|
125
|
+
end
|
126
|
+
|
127
|
+
should 'create target directory' do
|
128
|
+
assert File.exists?(@tmp_dir)
|
129
|
+
end
|
130
|
+
|
131
|
+
should "create lib directory" do
|
132
|
+
assert File.exists?(File.join(@tmp_dir, 'lib'))
|
133
|
+
assert File.directory?(File.join(@tmp_dir, 'lib'))
|
134
|
+
end
|
135
|
+
|
136
|
+
should "create LICENSE" do
|
137
|
+
assert File.exists?(File.join(@tmp_dir, 'LICENSE'))
|
138
|
+
assert File.file?(File.join(@tmp_dir, 'LICENSE'))
|
139
|
+
end
|
140
|
+
|
141
|
+
should "create README" do
|
142
|
+
assert File.exists?(File.join(@tmp_dir, 'README'))
|
143
|
+
assert File.file?(File.join(@tmp_dir, 'README'))
|
144
|
+
end
|
145
|
+
|
146
|
+
should "create lib/the-perfect-gem.rb" do
|
147
|
+
assert File.exists?(File.join(@tmp_dir, 'lib', 'the-perfect-gem.rb'))
|
148
|
+
assert File.file?(File.join(@tmp_dir, 'lib', 'the-perfect-gem.rb'))
|
149
|
+
end
|
150
|
+
|
151
|
+
context "LICENSE" do
|
152
|
+
setup do
|
153
|
+
@content = File.read((File.join(@tmp_dir, 'LICENSE')))
|
154
|
+
end
|
155
|
+
|
156
|
+
should "include copyright for this year with user's name" do
|
157
|
+
assert_match 'Copyright (c) 2008 foo', @content
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "Rakefile" do
|
162
|
+
setup do
|
163
|
+
@content = File.read((File.join(@tmp_dir, 'Rakefile')))
|
164
|
+
end
|
165
|
+
|
166
|
+
should "include repo's name as the gem's name" do
|
167
|
+
assert_match 's.name = "the-perfect-gem"', @content
|
168
|
+
end
|
169
|
+
|
170
|
+
should "include the user's email as the gem's email" do
|
171
|
+
assert_match 's.email = "bar@example.com"', @content
|
172
|
+
end
|
173
|
+
|
174
|
+
should "include the github repo's url as the gem's url" do
|
175
|
+
assert_match 's.homepage = "http://github.com/technicalpickles/the-perfect-gem"', @content
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: technicalpickles-jeweler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Nichols
|
@@ -10,10 +10,18 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-10-
|
13
|
+
date: 2008-10-25 00:00:00 -07:00
|
14
14
|
default_executable: jeweler
|
15
|
-
dependencies:
|
16
|
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: schacon-git
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
17
25
|
description: Simple and opinionated helper for creating Rubygem projects on GitHub
|
18
26
|
email: josh@technicalpickles.com
|
19
27
|
executables:
|
@@ -44,6 +52,7 @@ files:
|
|
44
52
|
- test/fixtures
|
45
53
|
- test/fixtures/bar
|
46
54
|
- test/fixtures/bar/VERSION.yml
|
55
|
+
- test/jeweler_generator_test.rb
|
47
56
|
- test/jeweler_test.rb
|
48
57
|
- test/test_helper.rb
|
49
58
|
has_rdoc: false
|