gem-this 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -41
- data/Rakefile.erb +10 -6
- data/lib/gem_this.rb +3 -3
- data/test/gem_this_test.rb +95 -0
- data/test/test_helper.rb +107 -0
- metadata +17 -4
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# Change these as appropriate
|
22
22
|
s.name = "gem-this"
|
23
|
-
s.version = "0.3.
|
23
|
+
s.version = "0.3.4"
|
24
24
|
s.summary = "Make existing code into a gem, without any fuss."
|
25
25
|
s.author = "James Adam"
|
26
26
|
s.email = "james@lazyatom.com"
|
@@ -31,7 +31,7 @@ spec = Gem::Specification.new do |s|
|
|
31
31
|
# s.rdoc_options = %w(--main Readme.markdown)
|
32
32
|
|
33
33
|
# Add any extra files to include in the gem
|
34
|
-
s.files = %w(Rakefile Readme.markdown Rakefile.erb) + Dir.glob("{bin,lib}/**/*")
|
34
|
+
s.files = %w(Rakefile Readme.markdown Rakefile.erb) + Dir.glob("{bin,lib,test}/**/*")
|
35
35
|
s.executables = FileList["bin/**"].map { |f| File.basename(f) }
|
36
36
|
s.require_paths = ["bin", "lib"]
|
37
37
|
|
@@ -79,45 +79,18 @@ task :clean => [:clobber_rdoc, :clobber_package] do
|
|
79
79
|
rm "#{spec.name}.gemspec"
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
#
|
87
|
-
begin
|
88
|
-
require "rake/contrib/sshpublisher"
|
89
|
-
namespace :rubyforge do
|
90
|
-
|
91
|
-
desc "Release gem and RDoc documentation to RubyForge"
|
92
|
-
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
93
|
-
|
94
|
-
namespace :release do
|
95
|
-
desc "Release a new version of this gem"
|
96
|
-
task :gem => [:package] do
|
97
|
-
require 'rubyforge'
|
98
|
-
rubyforge = RubyForge.new
|
99
|
-
rubyforge.configure
|
100
|
-
rubyforge.login
|
101
|
-
rubyforge.userconfig['release_notes'] = spec.summary
|
102
|
-
path_to_gem = File.join(File.dirname(__FILE__), "pkg", "#{spec.name}-#{spec.version}.gem")
|
103
|
-
puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..."
|
104
|
-
rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem)
|
105
|
-
end
|
106
|
-
|
107
|
-
desc "Publish RDoc to RubyForge."
|
108
|
-
task :docs => [:rdoc] do
|
109
|
-
config = YAML.load(
|
110
|
-
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
111
|
-
)
|
112
|
-
|
113
|
-
host = "#{config['username']}@rubyforge.org"
|
114
|
-
remote_dir = "/var/www/gforge-projects/gem-this/" # Should be the same as the rubyforge project name
|
115
|
-
local_dir = 'rdoc'
|
116
|
-
|
117
|
-
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
118
|
-
end
|
82
|
+
desc 'Tag the repository in git with gem version number'
|
83
|
+
task :tag => [:gemspec, :package] do
|
84
|
+
if `git diff --cached`.empty?
|
85
|
+
if `git tag`.split("\n").include?("v#{spec.version}")
|
86
|
+
raise "Version #{spec.version} has already been released"
|
119
87
|
end
|
88
|
+
`git add #{File.expand_path("../#{spec.name}.gemspec", __FILE__)}`
|
89
|
+
`git commit -m "Released version #{spec.version}"`
|
90
|
+
`git tag v#{spec.version}`
|
91
|
+
`git push --tags`
|
92
|
+
`git push`
|
93
|
+
else
|
94
|
+
raise "Unstaged changes still waiting to be committed"
|
120
95
|
end
|
121
|
-
rescue LoadError
|
122
|
-
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
123
96
|
end
|
data/Rakefile.erb
CHANGED
@@ -3,11 +3,10 @@ require "rake/gempackagetask"
|
|
3
3
|
require "rake/rdoctask"
|
4
4
|
|
5
5
|
<% if using_rspec? %>
|
6
|
-
require "
|
7
|
-
require "
|
8
|
-
|
9
|
-
t.
|
10
|
-
t.libs = ["spec"]
|
6
|
+
require "rspec"
|
7
|
+
require "rspec/core/rake_task"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.rspec_opts = %w(--format specdoc --colour)
|
11
10
|
end
|
12
11
|
<% elsif using_test_unit? %>
|
13
12
|
require "rake/testtask"
|
@@ -63,7 +62,7 @@ spec = Gem::Specification.new do |s|
|
|
63
62
|
|
64
63
|
# Add any extra files to include in the gem (like your README)
|
65
64
|
<% end %>
|
66
|
-
s.files = %w(<%= files_in_root %>) + Dir.glob(
|
65
|
+
s.files = %w(<%= files_in_root %>) + Dir.glob(<%= dirs_to_include_glob.inspect %>)
|
67
66
|
<% if has_executables? %>
|
68
67
|
s.executables = FileList["bin/**"].map { |f| File.basename(f) }
|
69
68
|
<% end %>
|
@@ -111,6 +110,11 @@ task :gemspec do
|
|
111
110
|
File.open(file, "w") {|f| f << spec.to_ruby }
|
112
111
|
end
|
113
112
|
|
113
|
+
# If you don't want to generate the .gemspec file, just remove this line. Reasons
|
114
|
+
# why you might want to generate a gemspec:
|
115
|
+
# - using bundler with a git source
|
116
|
+
# - building the gem without rake (i.e. gem build blah.gemspec)
|
117
|
+
# - maybe others?
|
114
118
|
task :package => :gemspec
|
115
119
|
|
116
120
|
# Generate documentation
|
data/lib/gem_this.rb
CHANGED
@@ -84,11 +84,11 @@ class GemThis
|
|
84
84
|
|
85
85
|
def dirs_to_include_glob
|
86
86
|
dirs = %w(bin test spec lib).select { |d| File.directory?(d) }
|
87
|
+
glob_parts = ["**", "*"]
|
87
88
|
if dirs.any?
|
88
|
-
dirs.join(",")
|
89
|
-
else
|
90
|
-
"**/*"
|
89
|
+
glob_parts.unshift("{"+dirs.join(",")+"}")
|
91
90
|
end
|
91
|
+
File.join(*glob_parts)
|
92
92
|
end
|
93
93
|
|
94
94
|
def readme
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class GemThisTest < Test::Unit::TestCase
|
4
|
+
context "When building a gem" do
|
5
|
+
setup do
|
6
|
+
build_gem do
|
7
|
+
touch "README"
|
8
|
+
touch "lib/thing.rb"
|
9
|
+
touch "lib/thing/some/aspect/many/levels/deep.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
should "contain lib files" do
|
14
|
+
assert_gem_contains "lib/thing.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
should "contain deeply nested files" do
|
18
|
+
assert_gem_contains "lib/thing/some/aspect/many/levels/deep.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
should "include the README" do
|
22
|
+
assert_gem_contains "README"
|
23
|
+
end
|
24
|
+
|
25
|
+
should "put lib in require path" do
|
26
|
+
assert_gem_spec :require_paths, ["lib"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "When building a gem with tests" do
|
31
|
+
setup do
|
32
|
+
build_gem do
|
33
|
+
touch "lib/thing.rb"
|
34
|
+
touch "test/thing_test.rb"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should "contain test files" do
|
39
|
+
assert_gem_contains "test/thing_test.rb"
|
40
|
+
end
|
41
|
+
|
42
|
+
should "create a rake task for running tests" do
|
43
|
+
assert_rake_task :test
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context "When building a gem with specs" do
|
49
|
+
setup do
|
50
|
+
build_gem do
|
51
|
+
touch "lib/thing.rb"
|
52
|
+
touch "spec/my_spec.rb"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
should "contain spec files" do
|
57
|
+
assert_gem_contains "spec/my_spec.rb"
|
58
|
+
end
|
59
|
+
|
60
|
+
should "create a rake task for running specs" do
|
61
|
+
assert_rake_task :spec
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "When building a gem with features" do
|
66
|
+
setup do
|
67
|
+
build_gem do
|
68
|
+
touch "lib/thing.rb"
|
69
|
+
touch "features/gem-this.feature"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
should "create a rake task for running features" do
|
74
|
+
assert_rake_task :features
|
75
|
+
end
|
76
|
+
|
77
|
+
should "add a features task to the default rake task dependencies" do
|
78
|
+
assert_default_rake_task_dependencies_contains :features
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "When building a gem without a lib directory" do
|
83
|
+
setup do
|
84
|
+
create_gem do
|
85
|
+
touch "code/my_code_is_in_here_for_some_reason.rb"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
should "not build the gem" do
|
90
|
+
assert_doesnt_hang do
|
91
|
+
assert !@gem.build # the real test is whether or not this returns at all.
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'shoulda'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'yaml'
|
6
|
+
require 'timeout'
|
7
|
+
require 'rake'
|
8
|
+
|
9
|
+
class GemBuilder
|
10
|
+
attr_reader :gem_path
|
11
|
+
|
12
|
+
def initialize(name, &block)
|
13
|
+
@name = name
|
14
|
+
@gem_path = temporary_gem_name
|
15
|
+
FileUtils.mkdir_p(@gem_path)
|
16
|
+
FileUtils.cd(@gem_path) do
|
17
|
+
instance_eval &block
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def touch(name)
|
22
|
+
FileUtils.mkdir_p(File.dirname(name))
|
23
|
+
FileUtils.touch(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def path_to_gem
|
27
|
+
File.join(@gem_path, "pkg", @name + "-0.1.0.gem")
|
28
|
+
end
|
29
|
+
|
30
|
+
def build
|
31
|
+
result = nil
|
32
|
+
FileUtils.cd(@gem_path) do
|
33
|
+
result = GemThis.new(@name, :debug => false, :silent => true).create_rakefile
|
34
|
+
`rake package 2>&1`
|
35
|
+
end
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def temporary_gem_name
|
42
|
+
t = Tempfile.new('gem-this')
|
43
|
+
gem_name = t.path
|
44
|
+
t.unlink
|
45
|
+
File.join(gem_name, @name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Test::Unit::TestCase
|
50
|
+
def assert_gem_contains(*paths)
|
51
|
+
paths.each do |path|
|
52
|
+
assert gem_spec.files.include?(path), "gem should include #{path}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def assert_gem_spec(part, value, message = nil)
|
57
|
+
assert_equal value, gem_spec.send(part), message
|
58
|
+
end
|
59
|
+
|
60
|
+
def assert_rake_task(task)
|
61
|
+
tasks = in_gem { `rake -T`.split("\n").map { |line| line.split[1] } }
|
62
|
+
assert tasks.include?(task.to_s), tasks.inspect
|
63
|
+
end
|
64
|
+
|
65
|
+
def assert_default_rake_task_dependencies_contains(task)
|
66
|
+
in_gem {
|
67
|
+
assert prerequisites_for('default').include?(task.to_s), prerequisites_for('default').inspect
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def assert_doesnt_hang(duration=5, message=nil, &block)
|
72
|
+
assert_nothing_raised("should return within #{duration} seconds") do
|
73
|
+
Timeout::timeout(duration, &block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def in_gem(&block)
|
78
|
+
result = nil
|
79
|
+
FileUtils.cd(@gem.gem_path) do
|
80
|
+
load 'RakeFile'
|
81
|
+
result = block.call
|
82
|
+
end
|
83
|
+
result
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_gem(name="test_gem", &block)
|
87
|
+
@gem = GemBuilder.new(name, &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_gem(name="test_gem", &block)
|
91
|
+
create_gem(name, &block).build
|
92
|
+
end
|
93
|
+
|
94
|
+
def gem_spec
|
95
|
+
in_gem { YAML.load(`gem specification #{@gem.path_to_gem}`) }
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
def find_task(task_name)
|
100
|
+
@tasks ||= Rake.application.tasks
|
101
|
+
@tasks.find {|task| task.name == task_name}
|
102
|
+
end
|
103
|
+
|
104
|
+
def prerequisites_for(task_name)
|
105
|
+
find_task(task_name).prerequisites
|
106
|
+
end
|
107
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-this
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- James Adam
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-11-19 00:00:00 +00:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: shoulda
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -33,9 +36,11 @@ dependencies:
|
|
33
36
|
name: rspec
|
34
37
|
prerelease: false
|
35
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
36
40
|
requirements:
|
37
41
|
- - ">="
|
38
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
39
44
|
segments:
|
40
45
|
- 0
|
41
46
|
version: "0"
|
@@ -45,9 +50,11 @@ dependencies:
|
|
45
50
|
name: cucumber
|
46
51
|
prerelease: false
|
47
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
48
54
|
requirements:
|
49
55
|
- - ">="
|
50
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
51
58
|
segments:
|
52
59
|
- 0
|
53
60
|
version: "0"
|
@@ -68,6 +75,8 @@ files:
|
|
68
75
|
- bin/gem-this
|
69
76
|
- lib/gem_this.rb
|
70
77
|
- lib/rubygems_plugin.rb
|
78
|
+
- test/gem_this_test.rb
|
79
|
+
- test/test_helper.rb
|
71
80
|
has_rdoc: true
|
72
81
|
homepage: http://github.com/lazyatom/gem-this
|
73
82
|
licenses: []
|
@@ -79,16 +88,20 @@ require_paths:
|
|
79
88
|
- bin
|
80
89
|
- lib
|
81
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
82
92
|
requirements:
|
83
93
|
- - ">="
|
84
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
85
96
|
segments:
|
86
97
|
- 0
|
87
98
|
version: "0"
|
88
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
89
101
|
requirements:
|
90
102
|
- - ">="
|
91
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 9
|
92
105
|
segments:
|
93
106
|
- 1
|
94
107
|
- 3
|
@@ -96,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
109
|
requirements: []
|
97
110
|
|
98
111
|
rubyforge_project: gem-this
|
99
|
-
rubygems_version: 1.3.
|
112
|
+
rubygems_version: 1.3.7
|
100
113
|
signing_key:
|
101
114
|
specification_version: 3
|
102
115
|
summary: Make existing code into a gem, without any fuss.
|