gemma 1.0.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.
- data/README.rdoc +73 -94
- data/bin/gemma +1 -1
- data/lib/gemma.rb +4 -2
- data/lib/gemma/conventions.rb +21 -26
- data/lib/gemma/gem_from_template.rb +4 -10
- data/lib/gemma/options.rb +8 -4
- data/lib/gemma/rake_tasks.rb +11 -10
- data/lib/gemma/rake_tasks/gem_tasks.rb +38 -0
- data/lib/gemma/rake_tasks/{test_unit_tasks.rb → minitest_tasks.rb} +11 -7
- data/lib/gemma/rake_tasks/plugin.rb +2 -0
- data/lib/gemma/rake_tasks/rdoc_tasks.rb +4 -26
- data/lib/gemma/rake_tasks/run_tasks.rb +7 -16
- data/lib/gemma/rake_tasks/yard_tasks.rb +2 -1
- data/lib/gemma/version.rb +4 -1
- data/template/base/Gemfile +3 -0
- data/template/base/Rakefile.rb.erb +4 -7
- data/template/base/gem_name.gemspec.erb +5 -6
- data/template/base/lib/gem_name/version.rb.erb +4 -1
- data/template/executable/bin/gem_name.erb +1 -1
- data/template/{test_unit/test/test_gem_name.rb.erb → minitest/test/gem_name/gem_name_test.rb.erb} +2 -2
- data/test/gemma/gem_from_template_test.rb +64 -0
- data/test/gemma/gemma_new_test.rb +121 -0
- data/test/{test_gemma.rb → gemma/gemma_test.rb} +10 -23
- data/test/{test_options.rb → gemma/options_test.rb} +2 -4
- metadata +131 -80
- data/lib/gemma/rake_tasks/rcov_tasks.rb +0 -85
@@ -1,14 +1,18 @@
|
|
1
1
|
module Gemma
|
2
2
|
class RakeTasks
|
3
3
|
#
|
4
|
-
# Create tasks to run
|
5
|
-
#
|
4
|
+
# Create tasks to run minitest tests. By default, the +require_paths+ from
|
5
|
+
# the gemspec and the gem's +test+ directory are placed on the load path,
|
6
|
+
# and the +test_files+ given in the gemspec are executed as tests.
|
7
|
+
#
|
8
|
+
# Minitest works on both 1.8 and 1.9, and it's mostly compatible with
|
9
|
+
# <tt>Test::Unit</tt> tests.
|
6
10
|
#
|
7
11
|
# This plugin is based on the `Rake::TestTask` that comes bundled with rake.
|
8
12
|
# If you need an option that isn't exposed by the plugin, you can modify the
|
9
13
|
# `TestTask` object directly in a block passed to {#with_test_task}.
|
10
14
|
#
|
11
|
-
class
|
15
|
+
class MinitestTasks < Plugin
|
12
16
|
#
|
13
17
|
# @param [Gem::Specification] gemspec
|
14
18
|
#
|
@@ -61,16 +65,16 @@ module Gemma
|
|
61
65
|
unless self.files.empty?
|
62
66
|
require 'rake/testtask'
|
63
67
|
Rake::TestTask.new(self.task_name) do |tt|
|
64
|
-
tt.libs = gemspec.require_paths
|
68
|
+
tt.libs = gemspec.require_paths.dup
|
69
|
+
tt.libs << 'test'
|
65
70
|
tt.test_files = self.files
|
66
|
-
tt.
|
71
|
+
tt.ruby_opts << '-rubygems' << '-rbundler/setup'
|
67
72
|
@with_test_task.call(tt) if @with_test_task
|
68
73
|
end
|
69
74
|
end
|
70
75
|
nil
|
71
|
-
rescue LoadError
|
72
|
-
# Assume the test task is not installed.
|
73
76
|
end
|
74
77
|
end
|
75
78
|
end
|
76
79
|
end
|
80
|
+
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rdoc/task'
|
2
|
+
|
1
3
|
module Gemma
|
2
4
|
class RakeTasks
|
3
5
|
#
|
@@ -7,11 +9,8 @@ module Gemma
|
|
7
9
|
# The default settings are based on the +require_paths+, +rdoc_options+ and
|
8
10
|
# +extra_rdoc_files+ data in the gemspec.
|
9
11
|
#
|
10
|
-
# If an rdoc gem is installed, it will be used; otherwise, the built-in
|
11
|
-
# rdoc will be used (see {#use_gem_if_available}).
|
12
|
-
#
|
13
12
|
# This plugin is based on the <tt>Rake::RDocTask</tt> that comes bundled
|
14
|
-
# with
|
13
|
+
# with rdoc. If you need an option that isn't exposed by the plugin, you
|
15
14
|
# can modify the +RDocTask+ object directly in a block passed to
|
16
15
|
# {#with_rdoc_task}.
|
17
16
|
#
|
@@ -23,7 +22,6 @@ module Gemma
|
|
23
22
|
super(gemspec)
|
24
23
|
|
25
24
|
# Defaults.
|
26
|
-
@use_gem_if_available = true
|
27
25
|
@task_name = :rdoc
|
28
26
|
@with_rdoc_task = nil
|
29
27
|
|
@@ -80,17 +78,6 @@ module Gemma
|
|
80
78
|
#
|
81
79
|
attr_accessor :template
|
82
80
|
|
83
|
-
#
|
84
|
-
# If an rdoc gem is installed, use it instead of the rdoc from the
|
85
|
-
# standard library (default true).
|
86
|
-
#
|
87
|
-
# While rdoc is part of the ruby standard library, newer versions are
|
88
|
-
# available as gems.
|
89
|
-
#
|
90
|
-
# @return [Boolean]
|
91
|
-
#
|
92
|
-
attr_accessor :use_gem_if_available
|
93
|
-
|
94
81
|
#
|
95
82
|
# Files and directories to be processed by rdoc; extracted from gemspec;
|
96
83
|
# by default, these are the gem's +require_paths+ and +extra_rdoc_files+.
|
@@ -131,15 +118,6 @@ module Gemma
|
|
131
118
|
# @private
|
132
119
|
#
|
133
120
|
def create_rake_tasks
|
134
|
-
if use_gem_if_available
|
135
|
-
begin
|
136
|
-
gem('rdoc')
|
137
|
-
rescue LoadError
|
138
|
-
# ignore -- just use the standard library one
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
require 'rake/rdoctask'
|
143
121
|
Rake::RDocTask.new(self.task_name) do |rd|
|
144
122
|
rd.rdoc_dir = self.output
|
145
123
|
rd.rdoc_files = self.files
|
@@ -147,9 +125,9 @@ module Gemma
|
|
147
125
|
rd.main = self.main
|
148
126
|
rd.template = self.template
|
149
127
|
rd.options = self.options
|
150
|
-
rd.inline_source = false # doesn't seem to work on 1.8.7
|
151
128
|
@with_rdoc_task.call(rd) if @with_rdoc_task
|
152
129
|
end
|
130
|
+
CLOBBER.include(self.output)
|
153
131
|
|
154
132
|
nil
|
155
133
|
end
|
@@ -3,13 +3,13 @@ module Gemma
|
|
3
3
|
#
|
4
4
|
# Run an executable script in the bin folder.
|
5
5
|
#
|
6
|
-
# There is one task per entry in the gemspec's +executables+ list.
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# There is one task per entry in the gemspec's +executables+ list. The
|
7
|
+
# executable is run with <tt>Kernel.exec</tt>. The result is equivalent to
|
8
|
+
# running <tt>bundler exec ...</tt>.
|
9
9
|
#
|
10
10
|
# To pass arguments to the script, you have to pass them as arguments to
|
11
11
|
# the rake task. The syntax for quoting the arguments will depend on your
|
12
|
-
# shell, but on bash
|
12
|
+
# shell, but on bash looks like:
|
13
13
|
#
|
14
14
|
# rake my_prog['foo --bar=baz --bat=hi']
|
15
15
|
#
|
@@ -23,7 +23,6 @@ module Gemma
|
|
23
23
|
# Defaults.
|
24
24
|
@task_prefix = ''
|
25
25
|
@program_names = gemspec.executables.dup
|
26
|
-
@ruby_args = ['-w', "-I#{gemspec.require_paths.join(':')}", '-rubygems']
|
27
26
|
end
|
28
27
|
|
29
28
|
#
|
@@ -42,14 +41,6 @@ module Gemma
|
|
42
41
|
#
|
43
42
|
attr_accessor :program_names
|
44
43
|
|
45
|
-
#
|
46
|
-
# Arguments to be passed to ruby; by default, warnings are enabled (-w)
|
47
|
-
# and the gemspec's +require_paths+ are on the load path (-I).
|
48
|
-
#
|
49
|
-
# @return [Array<String>]
|
50
|
-
#
|
51
|
-
attr_accessor :ruby_args
|
52
|
-
|
53
44
|
#
|
54
45
|
# Internal method; see {Plugin#create_rake_tasks}.
|
55
46
|
#
|
@@ -58,11 +49,11 @@ module Gemma
|
|
58
49
|
# @private
|
59
50
|
#
|
60
51
|
def create_rake_tasks
|
61
|
-
|
52
|
+
program_names.each do |program_name|
|
62
53
|
desc "run #{program_name}"
|
63
54
|
task((task_prefix + program_name), :args) do |t, args|
|
64
|
-
|
65
|
-
|
55
|
+
program_args = Shellwords.shellsplit(args[:args] || '')
|
56
|
+
Kernel.exec(program_name, *program_args)
|
66
57
|
end
|
67
58
|
end
|
68
59
|
nil
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yard'
|
2
|
+
|
1
3
|
module Gemma
|
2
4
|
class RakeTasks
|
3
5
|
#
|
@@ -128,7 +130,6 @@ module Gemma
|
|
128
130
|
# @private
|
129
131
|
#
|
130
132
|
def create_rake_tasks
|
131
|
-
require 'yard'
|
132
133
|
YARD::Rake::YardocTask.new do |yd|
|
133
134
|
yd.name = self.task_name
|
134
135
|
yd.options = complete_options
|
data/lib/gemma/version.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'gemma'
|
4
4
|
|
5
|
-
|
6
|
-
rescue LoadError
|
7
|
-
puts 'Install gemma (sudo gem install gemma) for more rake tasks.'
|
8
|
-
end
|
5
|
+
Gemma::RakeTasks.with_gemspec_file '<%= gem_name %>.gemspec'
|
9
6
|
|
10
7
|
task :default => :test
|
@@ -11,17 +11,16 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.authors = ['TODO write your name']
|
12
12
|
s.email = ['TODO write your e-mail address']
|
13
13
|
s.homepage = 'TODO homepage'
|
14
|
-
s.summary = %q{TODO write gem summary}
|
15
|
-
s.description = %q{TODO write gem description}
|
14
|
+
s.summary = %q{TODO write short gem summary}
|
15
|
+
s.description = %q{TODO write longer gem description}
|
16
16
|
|
17
17
|
s.rubyforge_project = '<%= gem_name %>'
|
18
18
|
|
19
|
-
#s.add_runtime_dependency '...'
|
20
|
-
s.add_development_dependency 'gemma', '
|
21
|
-
gemma_version_requirement %>'
|
19
|
+
#s.add_runtime_dependency '...', '~> x.y.z'
|
20
|
+
s.add_development_dependency 'gemma', '~> <%= Gemma::VERSION %>'
|
22
21
|
|
23
22
|
s.files = Dir.glob('{lib,bin}/**/*.rb') + %w(README.rdoc)
|
24
|
-
s.test_files = Dir.glob('test
|
23
|
+
s.test_files = Dir.glob('test/<%= gem_name %>/*_test.rb')
|
25
24
|
s.executables = Dir.glob('bin/*').map{|f| File.basename(f)}
|
26
25
|
|
27
26
|
s.rdoc_options = [
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'gemma/test_helper'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
class Gemma::GemFromTemplateTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@tmp = Dir.mktmpdir('gemma')
|
7
|
+
@old_pwd = Dir.pwd
|
8
|
+
Dir.chdir(@tmp)
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
Dir.chdir(@old_pwd)
|
13
|
+
FileUtils.remove_entry_secure @tmp
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
#
|
18
|
+
# basic create-from-template tests
|
19
|
+
#
|
20
|
+
gt = Gemma::GemFromTemplate.new
|
21
|
+
gt.gem_name = "my_new_gem"
|
22
|
+
assert gt.good_gem_name?
|
23
|
+
|
24
|
+
assert_equal "MyNewGem", gt.module_name
|
25
|
+
gt.module_name = "Foo" # override default
|
26
|
+
assert_equal "Foo", gt.module_name
|
27
|
+
gt.module_name = nil # revert back to default
|
28
|
+
assert_equal "MyNewGem", gt.module_name
|
29
|
+
|
30
|
+
assert_equal "my_new_gem", gt.dir_name
|
31
|
+
gt.dir_name = "bar" # override default
|
32
|
+
assert_equal "bar", gt.dir_name
|
33
|
+
gt.dir_name = nil # revert back to default
|
34
|
+
assert_equal "my_new_gem", gt.dir_name
|
35
|
+
|
36
|
+
template_paths = Gemma::GemFromTemplate::BUILTIN_TEMPLATES.map{|path|
|
37
|
+
File.join(Gemma::GemFromTemplate::TEMPLATE_ROOT,path)}
|
38
|
+
assert_equal 'base', File.basename(template_paths.first)
|
39
|
+
|
40
|
+
gt.dir_name = "my_new_gem_base"
|
41
|
+
gt.create_gem template_paths[0..0] # just base
|
42
|
+
|
43
|
+
gt.dir_name = "my_new_gem_full"
|
44
|
+
gt.create_gem template_paths # expand all templates
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_todos
|
48
|
+
#
|
49
|
+
# we should be able to find the to-do markers in a newly created gem
|
50
|
+
#
|
51
|
+
gt = Gemma::GemFromTemplate.new
|
52
|
+
gt.gem_name = "test_gem"
|
53
|
+
|
54
|
+
template_paths = Gemma::GemFromTemplate::BUILTIN_TEMPLATES.map{|path|
|
55
|
+
File.join(Gemma::GemFromTemplate::TEMPLATE_ROOT,path)}
|
56
|
+
gt.create_gem template_paths
|
57
|
+
|
58
|
+
# look for some to-do markers
|
59
|
+
io = StringIO.new
|
60
|
+
Gemma::Utility.rgrep(/TODO/, gt.destination_path, io)
|
61
|
+
assert io.string =~ /README\.rdoc/
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'gemma/test_helper'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'open4'
|
4
|
+
|
5
|
+
#
|
6
|
+
# Run the 'gemma new' command and then run some basic commands to make sure that
|
7
|
+
# things worked out.
|
8
|
+
#
|
9
|
+
class Gemma::GemmaNewTest < Test::Unit::TestCase
|
10
|
+
#
|
11
|
+
# Run a command in a bundler-free environment and capture both stdout and
|
12
|
+
# stderror output.
|
13
|
+
#
|
14
|
+
# We don't want to let our (gemma) bundler environment interfere with the
|
15
|
+
# bundler environment that we want to set up for the test gem, so we use
|
16
|
+
# bundler's +with_clean_env+ (which doesn't quite work yet in bundler 1.0, so
|
17
|
+
# we have to hack things a bit more than should be necessary)
|
18
|
+
#
|
19
|
+
# We also don't want to generate lots of confusing test output, so we capture
|
20
|
+
# stdout and stderr using Open4. (On 1.9.2, we can use <tt>Open3.popen2e</tt>,
|
21
|
+
# which is nicer, but Open3 on ruby 1.8.7 doesn't let us get exitstatus.)
|
22
|
+
#
|
23
|
+
def run_cmd *args
|
24
|
+
Bundler.with_clean_env {
|
25
|
+
# FIXME in bundler 1.1, this should not be necessary; see
|
26
|
+
# https://github.com/carlhuda/bundler/issues/1133
|
27
|
+
ENV.delete_if { |k,_| k[0,7] == 'BUNDLE_' }
|
28
|
+
|
29
|
+
# We also have to clear RUBYOPT, because Bundler::ORIGINAL_ENV in the test
|
30
|
+
# runner's process still contains some bundler stuff from rake's process.
|
31
|
+
# This suggests that we might have to stop using rake's built-in TestTask,
|
32
|
+
# and instead use one that runs the tests in a Bundler.with_clean_env
|
33
|
+
# block. However, it usually doesn't seem to make a difference, unless
|
34
|
+
# you're doing strange things like we are here.
|
35
|
+
ENV.delete('RUBYOPT')
|
36
|
+
|
37
|
+
output = nil
|
38
|
+
status = Open4.popen4(*args) {|pid,i,o,e|
|
39
|
+
i.close
|
40
|
+
output = o.read + e.read
|
41
|
+
}
|
42
|
+
[status, output]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def setup
|
47
|
+
# work in a temporary directory
|
48
|
+
@tmp = Dir.mktmpdir('gemma')
|
49
|
+
@old_pwd = Dir.pwd
|
50
|
+
Dir.chdir(@tmp)
|
51
|
+
|
52
|
+
# create a test gem; note that here we DO want the gemma bundler
|
53
|
+
# environment, because it puts our gemma executable on the bin path
|
54
|
+
output = `gemma new --name="test_gem"`
|
55
|
+
raise "gemma new failed:\n#{output}" unless $?.exitstatus
|
56
|
+
|
57
|
+
# we should get some TODOs from the template in the output
|
58
|
+
assert_match /TODO write your name/, output
|
59
|
+
|
60
|
+
Dir.chdir('test_gem')
|
61
|
+
|
62
|
+
# edit the test gem's Gemfile to point to this gemma
|
63
|
+
raise "no Gemfile in test gem" unless File.exists?('Gemfile')
|
64
|
+
File.open('Gemfile', 'a') do |f|
|
65
|
+
f.puts "gem 'gemma', :path => #{@old_pwd.dump}"
|
66
|
+
end
|
67
|
+
|
68
|
+
# run bundler on the test gem; it should find the same gems that we're using
|
69
|
+
# in the gemma bundle
|
70
|
+
status, output = run_cmd('bundle', 'install', '--local')
|
71
|
+
raise "bundle failed:\n#{output}" unless status.exitstatus == 0
|
72
|
+
|
73
|
+
# it should say that it has loaded two things from source: gemma and the
|
74
|
+
# test_gem itself; if it doesn't it indicates that something strange
|
75
|
+
# happened with bundler's environment (or it may just break on future
|
76
|
+
# versions of bundler)
|
77
|
+
raise "did not load from source" unless output =~ /from source at/
|
78
|
+
|
79
|
+
# bundler should produce a lock file
|
80
|
+
raise "no Gemfile.lock in test gem" unless File.exists?('Gemfile.lock')
|
81
|
+
end
|
82
|
+
|
83
|
+
def teardown
|
84
|
+
Dir.chdir(@old_pwd)
|
85
|
+
FileUtils.remove_entry_secure @tmp
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_rake
|
89
|
+
# list the rake tasks; this ensures that gemma loaded
|
90
|
+
status, output = run_cmd('rake -T')
|
91
|
+
assert_equal 0, status.exitstatus
|
92
|
+
assert_match /rake test/, output
|
93
|
+
assert_match /rake test_gem/, output
|
94
|
+
assert_match /rake rdoc/, output
|
95
|
+
assert_match /rake yard/, output
|
96
|
+
|
97
|
+
# run the tests; they should fail initially
|
98
|
+
status, output = run_cmd('rake')
|
99
|
+
assert_not_equal 0, status.exitstatus
|
100
|
+
assert_match /TODO write tests/, output
|
101
|
+
|
102
|
+
# run the executable; it should also fail
|
103
|
+
status, output = run_cmd('rake test_gem')
|
104
|
+
assert_not_equal 0, status.exitstatus
|
105
|
+
assert_match /TODO write program code/, output
|
106
|
+
|
107
|
+
# generate rdoc output
|
108
|
+
status, output = run_cmd('rake rdoc')
|
109
|
+
assert_equal 0, status.exitstatus
|
110
|
+
|
111
|
+
# generate yard output
|
112
|
+
status, output = run_cmd('rake yard')
|
113
|
+
assert_equal 0, status.exitstatus
|
114
|
+
|
115
|
+
# build the gem; this should fail, because we have invalid authors, etc.
|
116
|
+
status, output = run_cmd('rake build')
|
117
|
+
assert_match /TODO/, output # "... is not a valid author"
|
118
|
+
assert_equal 1, status.exitstatus
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|