rmm5t-yarg 0.1.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.markdown +53 -0
- data/Rakefile +56 -0
- data/bin/yarg +36 -0
- data/lib/yarg/file_actions.rb +64 -0
- data/lib/yarg/rails.rb +86 -0
- data/lib/yarg/scm/git.rb +21 -0
- data/lib/yarg/scm.rb +48 -0
- data/lib/yarg.rb +9 -0
- data/test/file_actions_test.rb +88 -0
- data/test/rails_test.rb +143 -0
- data/test/scm_test.rb +64 -0
- data/test/test_helper.rb +72 -0
- metadata +69 -0
data/README.markdown
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# yarg: Yet Another Ruby Generator
|
2
|
+
|
3
|
+
Yarg is Yet Another Ruby Generator. It allows you to customize existing project
|
4
|
+
generators to fit your personality or common scaffolding.
|
5
|
+
|
6
|
+
**Yarg is still in its infancy. It currently works for rails generation, but use it at your own risk.**
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Install:
|
11
|
+
|
12
|
+
gem install rmm5t-yarg --source http://gems.github.com
|
13
|
+
|
14
|
+
Configure by placing a <tt>~/.yarg</tt> file in your home directory. Here's a simple example
|
15
|
+
|
16
|
+
Yarg::Rails.new do |rg|
|
17
|
+
rg.scm :git
|
18
|
+
rg.delete "public/index.html"
|
19
|
+
rg.delete "public/dispatch.*"
|
20
|
+
rg.plugin "git://github.com/thoughtbot/shoulda.git"
|
21
|
+
rg.plugin "git://github.com/nex3/haml.git"
|
22
|
+
rg.freeze
|
23
|
+
end
|
24
|
+
|
25
|
+
Here's another example:
|
26
|
+
|
27
|
+
Yarg::Rails.new do |rg|
|
28
|
+
rg.scm :git, :using => :submodules
|
29
|
+
rg.delete "public/index.html"
|
30
|
+
rg.delete "public/dispatch.*"
|
31
|
+
rg.plugin "git://github.com/thoughtbot/shoulda.git"
|
32
|
+
rg.plugin "git://github.com/nex3/haml.git"
|
33
|
+
rg.plugin "git://github.com/rmm5t/strip_attributes.git"
|
34
|
+
rg.plugin "git://github.com/github/hubahuba.git"
|
35
|
+
rg.freeze :version => :edge
|
36
|
+
end
|
37
|
+
|
38
|
+
## TODO
|
39
|
+
|
40
|
+
* Add better option parsing support in script
|
41
|
+
* Add template directory support
|
42
|
+
* Add rails gem freezing support
|
43
|
+
* Add newgem support
|
44
|
+
* Add merb support
|
45
|
+
* Add webby support
|
46
|
+
* Add staticmatic support
|
47
|
+
* Add svn support (?)
|
48
|
+
|
49
|
+
## Other
|
50
|
+
|
51
|
+
[MIT License](http://www.opensource.org/licenses/mit-license.php)
|
52
|
+
|
53
|
+
Copyright (c) 2008, Ryan McGeary (ryanonruby -[at]- mcgeary [*dot*] org)
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'lib/yarg'
|
6
|
+
|
7
|
+
desc 'Default: run unit tests.'
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
desc 'Test the yarg gem.'
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.libs << 'lib' << 'test'
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generate documentation for the yarg gem.'
|
18
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = 'Yarg'
|
21
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
22
|
+
rdoc.rdoc_files.include('README.markdown')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
spec = Gem::Specification.new do |s|
|
27
|
+
s.name = "yarg"
|
28
|
+
s.version = Yarg::VERSION
|
29
|
+
s.summary = "Yet Another Ruby Generator"
|
30
|
+
s.homepage = "http://github.com/rmm5t/yarg"
|
31
|
+
# s.rubyforge_project = "yarg"
|
32
|
+
|
33
|
+
s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
|
34
|
+
s.executables = s.files.grep(/^bin/) { |f| File.basename(f) }
|
35
|
+
|
36
|
+
s.has_rdoc = true
|
37
|
+
s.extra_rdoc_files = ["README.markdown"]
|
38
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.markdown"]
|
39
|
+
|
40
|
+
s.authors = ["Ryan McGeary"]
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::GemPackageTask.new spec do |pkg|
|
44
|
+
pkg.need_tar = true
|
45
|
+
pkg.need_zip = true
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Clean files generated by rake tasks"
|
49
|
+
task :clobber => [:clobber_rdoc, :clobber_package]
|
50
|
+
|
51
|
+
desc "Generate a gemspec file for GitHub"
|
52
|
+
task :gemspec do
|
53
|
+
File.open("#{spec.name}.gemspec", 'w') do |f|
|
54
|
+
f.write spec.to_ruby
|
55
|
+
end
|
56
|
+
end
|
data/bin/yarg
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'yarg'
|
5
|
+
require 'yarg/rails'
|
6
|
+
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} /path/to/your/project"
|
9
|
+
|
10
|
+
opts.on("-h", "--help", "Show this help info and quit") do
|
11
|
+
puts opts
|
12
|
+
exit 0
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-v", "--version", "Show the Yarg version number and quit") do
|
16
|
+
puts "Yarg #{Yarg::VERSION}"
|
17
|
+
exit 0
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
opts.parse!(ARGV)
|
22
|
+
rescue OptionParser::ParseError => e
|
23
|
+
warn e.message
|
24
|
+
puts opts
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#TODO test if file exists
|
30
|
+
load "~/.yarg"
|
31
|
+
|
32
|
+
#TODO check ARGV size
|
33
|
+
ENV["PROJECT_NAME"] = ARGV[0]
|
34
|
+
|
35
|
+
#TODO allow for default or for named task
|
36
|
+
Rake::Task[:rails].invoke
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'yarg/scm'
|
2
|
+
|
3
|
+
module Yarg
|
4
|
+
module FileActions
|
5
|
+
# List of paths to delete. (default is NONE)
|
6
|
+
attr_accessor :deletions
|
7
|
+
|
8
|
+
# List of source template paths to overwrite files in the destination
|
9
|
+
# project. (default is NONE)
|
10
|
+
attr_accessor :templates
|
11
|
+
|
12
|
+
# Source control management module to use (default is NONE)
|
13
|
+
attr_accessor :scm_module
|
14
|
+
|
15
|
+
def initialize_file_actions
|
16
|
+
self.deletions = []
|
17
|
+
self.templates = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(relative_path)
|
21
|
+
self.deletions << relative_path
|
22
|
+
end
|
23
|
+
|
24
|
+
def template(absolute_path)
|
25
|
+
self.templates << absolute_path
|
26
|
+
end
|
27
|
+
|
28
|
+
def scm(scm, options = {})
|
29
|
+
self.scm_module = Scm.new(scm, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def apply_file_actions
|
35
|
+
apply_deletions
|
36
|
+
apply_templates
|
37
|
+
apply_scm_init
|
38
|
+
end
|
39
|
+
|
40
|
+
def apply_deletions
|
41
|
+
self.deletions.each do |path|
|
42
|
+
File.delete(*Dir.glob(path))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def apply_templates
|
47
|
+
# TODO
|
48
|
+
end
|
49
|
+
|
50
|
+
def apply_scm_init
|
51
|
+
exec_commands(self.scm_module.init_commands) if self.scm_module
|
52
|
+
end
|
53
|
+
|
54
|
+
def apply_scm_commit
|
55
|
+
exec_commands(self.scm_module.commit_commands) if self.scm_module
|
56
|
+
end
|
57
|
+
|
58
|
+
def exec_commands(commands)
|
59
|
+
commands.each do |command|
|
60
|
+
sh(command)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/yarg/rails.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'yarg'
|
2
|
+
require 'yarg/file_actions'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
|
5
|
+
module Yarg
|
6
|
+
# Create a task that customizes a Rails project generation bootstrap.
|
7
|
+
#
|
8
|
+
# Example (<tt>~/.yarg</tt>):
|
9
|
+
#
|
10
|
+
# Yarg::Rails.new do |rg|
|
11
|
+
# rg.template "~/.yarg.d/default"
|
12
|
+
# rg.delete "public/index.html"
|
13
|
+
# rg.delete "public/dispatch.*"
|
14
|
+
# rg.plugin "git://github.com/thoughtbot/shoulda.git"
|
15
|
+
# rg.plugin "git://github.com/nex3/haml.git"
|
16
|
+
# rg.freeze :version => :edge
|
17
|
+
# end
|
18
|
+
class Rails < Rake::TaskLib
|
19
|
+
include Yarg::FileActions
|
20
|
+
|
21
|
+
# Name of rails generator task. (default is :rails)
|
22
|
+
attr_accessor :name
|
23
|
+
|
24
|
+
# List of plugins to install. (default is NONE)
|
25
|
+
attr_accessor :plugins
|
26
|
+
|
27
|
+
# True if freezing rails under vendor/rails is desired. (default is false)
|
28
|
+
attr_accessor :frozen
|
29
|
+
|
30
|
+
# Version to freeze rails if frozen is true. (default is :gems)
|
31
|
+
attr_accessor :freeze_version
|
32
|
+
|
33
|
+
def initialize(name = :rails)
|
34
|
+
self.name = name
|
35
|
+
self.plugins = []
|
36
|
+
self.frozen = false
|
37
|
+
initialize_file_actions
|
38
|
+
yield self if block_given?
|
39
|
+
define
|
40
|
+
end
|
41
|
+
|
42
|
+
def plugin(repository)
|
43
|
+
self.plugins << repository
|
44
|
+
end
|
45
|
+
|
46
|
+
def freeze(options = {})
|
47
|
+
self.frozen = true
|
48
|
+
self.freeze_version = options[:version] || :gems
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def define
|
54
|
+
task self.name do
|
55
|
+
app_name = ENV["PROJECT_NAME"]
|
56
|
+
sh("rails #{app_name}")
|
57
|
+
Dir.chdir(app_name)
|
58
|
+
apply_file_actions
|
59
|
+
apply_plugins
|
60
|
+
apply_freeze
|
61
|
+
apply_scm_commit
|
62
|
+
end
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
def apply_plugins
|
67
|
+
plugins.each do |plugin|
|
68
|
+
if scm_module && scm_module.using
|
69
|
+
plugin_name = File.basename(plugin, ".*")
|
70
|
+
exec_commands(scm_module.install_commands(plugin, "vendor/plugins/#{plugin_name}"))
|
71
|
+
else
|
72
|
+
sh("./script/plugin install #{plugin}")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def apply_freeze
|
78
|
+
return unless frozen
|
79
|
+
if scm_module && scm_module.using
|
80
|
+
exec_commands(scm_module.install_commands("git://github.com/rails/rails.git", "vendor/rails"))
|
81
|
+
elsif [:gems, :edge].include?(freeze_version.to_sym)
|
82
|
+
sh("rake rails:freeze:#{freeze_version}")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/yarg/scm/git.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Yarg
|
2
|
+
module Scm
|
3
|
+
class Git < Base
|
4
|
+
def initialize(options = {})
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def init_commands
|
9
|
+
["git init"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def commit_commands
|
13
|
+
["git add .", "git commit -m 'Initial commit. Yarg!'"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def install_commands(repository, destination)
|
17
|
+
["git submodule add #{repository} #{destination}"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/yarg/scm.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Yarg
|
2
|
+
module Scm
|
3
|
+
class Base
|
4
|
+
attr_accessor :using
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
self.using = options[:using]
|
8
|
+
end
|
9
|
+
|
10
|
+
def init_commands
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
|
14
|
+
def commit_commands
|
15
|
+
[]
|
16
|
+
end
|
17
|
+
|
18
|
+
def install(repository, destination)
|
19
|
+
raise NotImplementedError, "install is not implemented by #{self.class.name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.new(scm, options = {})
|
24
|
+
scm_const = scm.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
|
25
|
+
load_scm(scm) unless const_defined?(scm_const)
|
26
|
+
initialize_scm(scm_const, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.load_scm(scm)
|
32
|
+
scm_path = "yarg/scm/#{scm}"
|
33
|
+
begin
|
34
|
+
require(scm_path)
|
35
|
+
rescue LoadError
|
36
|
+
raise Yarg::Error, "could not find an SCM at #{scm_path}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.initialize_scm(scm_const, options)
|
41
|
+
if const_defined?(scm_const)
|
42
|
+
const_get(scm_const).new(options)
|
43
|
+
else
|
44
|
+
raise Yarg::Error, "could not find #{name}::#{scm_const}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/yarg.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'yarg/file_actions'
|
3
|
+
require 'yarg/scm/git'
|
4
|
+
|
5
|
+
class FakeGen < Rake::TaskLib
|
6
|
+
include Yarg::FileActions
|
7
|
+
|
8
|
+
def initialize(name = :fake)
|
9
|
+
@name = name
|
10
|
+
initialize_file_actions
|
11
|
+
yield self if block_given?
|
12
|
+
define
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def define
|
18
|
+
task @name do
|
19
|
+
project_name = ENV["PROJECT_NAME"]
|
20
|
+
Dir.mkdir(project_name)
|
21
|
+
Dir.chdir(project_name)
|
22
|
+
apply_file_actions
|
23
|
+
apply_scm_commit
|
24
|
+
end
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class FileActionsTest < Test::Unit::TestCase
|
30
|
+
def setup
|
31
|
+
Rake::Task.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
context "An empty Fake generator" do
|
35
|
+
setup do
|
36
|
+
@generator = FakeGen.new do |rg| end
|
37
|
+
stub_fake_system_calls("my_app")
|
38
|
+
end
|
39
|
+
|
40
|
+
should_define_task :fake
|
41
|
+
should_have_generator_attribute_of :scm_module, nil
|
42
|
+
|
43
|
+
context "once invoked" do
|
44
|
+
setup do
|
45
|
+
Rake::Task[:fake].invoke
|
46
|
+
end
|
47
|
+
|
48
|
+
should_cd_into "my_app"
|
49
|
+
should_not_delete_any_files
|
50
|
+
should_not_invoke %r{^git}
|
51
|
+
should_not_invoke %r{^svn}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "An Fake generator using GIT" do
|
56
|
+
setup do
|
57
|
+
@generator = FakeGen.new do |rg|
|
58
|
+
rg.scm :git
|
59
|
+
end
|
60
|
+
stub_fake_system_calls("my_app")
|
61
|
+
end
|
62
|
+
|
63
|
+
should_define_task :fake
|
64
|
+
should_have_generator_attribute_of :scm_module, Yarg::Scm::Git
|
65
|
+
|
66
|
+
context "once invoked" do
|
67
|
+
setup do
|
68
|
+
Rake::Task[:fake].invoke
|
69
|
+
end
|
70
|
+
|
71
|
+
should_cd_into "my_app"
|
72
|
+
should_not_delete_any_files
|
73
|
+
should_invoke %r{^git init}
|
74
|
+
should_invoke %r{^git add}
|
75
|
+
should_invoke %r{^git commit}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def stub_fake_system_calls(project_name)
|
82
|
+
ENV["PROJECT_NAME"] = project_name
|
83
|
+
@generator.stubs(:sh)
|
84
|
+
Dir.stubs(:mkdir)
|
85
|
+
Dir.stubs(:chdir)
|
86
|
+
File.stubs(:delete)
|
87
|
+
end
|
88
|
+
end
|
data/test/rails_test.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'yarg/rails'
|
3
|
+
|
4
|
+
class RailsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Rake::Task.clear
|
7
|
+
end
|
8
|
+
|
9
|
+
context "A missing Rails generator" do
|
10
|
+
should_not_define_task :rails
|
11
|
+
end
|
12
|
+
|
13
|
+
context "An empty default Rails generator" do
|
14
|
+
setup do
|
15
|
+
@generator = Yarg::Rails.new do |rg| end
|
16
|
+
stub_rails_system_calls("my_app")
|
17
|
+
end
|
18
|
+
|
19
|
+
should_define_task :rails
|
20
|
+
should_have_generator_attribute_of :name, :rails
|
21
|
+
should_have_generator_attribute_of :deletions, []
|
22
|
+
should_have_generator_attribute_of :plugins, []
|
23
|
+
should_have_generator_attribute_of :templates, []
|
24
|
+
should_have_generator_attribute_of :frozen, false
|
25
|
+
should_have_generator_attribute_of :freeze_version, nil
|
26
|
+
|
27
|
+
context "once invoked" do
|
28
|
+
setup do
|
29
|
+
Rake::Task[:rails].invoke
|
30
|
+
end
|
31
|
+
|
32
|
+
should_run_rails_command_for_app "my_app"
|
33
|
+
should_cd_into "my_app"
|
34
|
+
should_not_delete_any_files
|
35
|
+
should_not_invoke %r{^\./script/plugin install}
|
36
|
+
should_not_invoke %r{^rake rails:freeze}
|
37
|
+
should_eventually "not overwrite with any templates"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "A Rails generator with multiple options set" do
|
42
|
+
setup do
|
43
|
+
@generator = Yarg::Rails.new(:template) do |rg|
|
44
|
+
rg.scm :git, :using => :submodules
|
45
|
+
rg.delete "public/index.html"
|
46
|
+
rg.delete "public/dispatch.*"
|
47
|
+
rg.plugin "git://github.com/thoughtbot/shoulda.git"
|
48
|
+
rg.plugin "git://github.com/nex3/haml.git"
|
49
|
+
rg.template "~/.yarg.d/rails"
|
50
|
+
rg.freeze :version => :edge
|
51
|
+
end
|
52
|
+
stub_rails_system_calls("my_rails_project")
|
53
|
+
end
|
54
|
+
|
55
|
+
should_define_task :template
|
56
|
+
should_have_generator_attribute_of :name, :template
|
57
|
+
should_have_generator_attribute_of :scm_module, Yarg::Scm::Git
|
58
|
+
should_have_generator_attribute_of :deletions, %w(public/index.html public/dispatch.*)
|
59
|
+
should_have_generator_attribute_of :plugins, %w(git://github.com/thoughtbot/shoulda.git git://github.com/nex3/haml.git)
|
60
|
+
should_have_generator_attribute_of :templates, %w(~/.yarg.d/rails)
|
61
|
+
should_have_generator_attribute_of :frozen, true
|
62
|
+
should_have_generator_attribute_of :freeze_version, :edge
|
63
|
+
|
64
|
+
context "once invoked" do
|
65
|
+
setup do
|
66
|
+
Rake::Task[:template].invoke
|
67
|
+
end
|
68
|
+
|
69
|
+
should_run_rails_command_for_app "my_rails_project"
|
70
|
+
should_cd_into "my_rails_project"
|
71
|
+
should_delete "public/index.html"
|
72
|
+
should_delete "public/dispatch.cgi", "public/dispatch.fcgi", "public/dispatch.rb"
|
73
|
+
should_invoke "git submodule add git://github.com/thoughtbot/shoulda.git vendor/plugins/shoulda"
|
74
|
+
should_invoke "git submodule add git://github.com/nex3/haml.git vendor/plugins/haml"
|
75
|
+
should_invoke "git submodule add git://github.com/rails/rails.git vendor/rails"
|
76
|
+
should_invoke %r{^git init}
|
77
|
+
should_invoke %r{^git add}
|
78
|
+
should_invoke %r{^git commit}
|
79
|
+
should_eventually "overwrite with the template"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "A Rails generator with a default freeze" do
|
84
|
+
setup do
|
85
|
+
@generator = Yarg::Rails.new do |rg|
|
86
|
+
rg.freeze
|
87
|
+
end
|
88
|
+
stub_rails_system_calls("my_app")
|
89
|
+
end
|
90
|
+
|
91
|
+
should_have_generator_attribute_of :frozen, true
|
92
|
+
should_have_generator_attribute_of :freeze_version, :gems
|
93
|
+
|
94
|
+
context "once invoked" do
|
95
|
+
setup do
|
96
|
+
Rake::Task[:rails].invoke
|
97
|
+
end
|
98
|
+
|
99
|
+
should_run_rails_command_for_app "my_app"
|
100
|
+
should_cd_into "my_app"
|
101
|
+
should_not_invoke %r{^\./script/plugin install}
|
102
|
+
should_invoke "rake rails:freeze:gems"
|
103
|
+
should_eventually "not overwrite with any templates"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "A Rails generator with a default scm" do
|
108
|
+
setup do
|
109
|
+
@generator = Yarg::Rails.new do |rg|
|
110
|
+
rg.scm :git
|
111
|
+
rg.plugin "git://github.com/nex3/haml.git"
|
112
|
+
rg.freeze :version => :edge
|
113
|
+
end
|
114
|
+
stub_rails_system_calls("my_app")
|
115
|
+
end
|
116
|
+
|
117
|
+
should_have_generator_attribute_of :scm_module, Yarg::Scm::Git
|
118
|
+
|
119
|
+
context "once invoked" do
|
120
|
+
setup do
|
121
|
+
Rake::Task[:rails].invoke
|
122
|
+
end
|
123
|
+
|
124
|
+
should_invoke "./script/plugin install git://github.com/nex3/haml.git"
|
125
|
+
should_invoke "rake rails:freeze:edge"
|
126
|
+
should_invoke %r{^git init}
|
127
|
+
should_invoke %r{^git add}
|
128
|
+
should_invoke %r{^git commit}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def stub_rails_system_calls(app_name)
|
135
|
+
ENV["PROJECT_NAME"] = app_name
|
136
|
+
@generator.stubs(:sh)
|
137
|
+
Dir.stubs(:chdir)
|
138
|
+
Dir.stubs(:glob)
|
139
|
+
Dir.stubs(:glob).with("public/index.html").returns(%w(public/index.html))
|
140
|
+
Dir.stubs(:glob).with("public/dispatch.*").returns(%w(public/dispatch.cgi public/dispatch.fcgi public/dispatch.rb))
|
141
|
+
File.stubs(:delete)
|
142
|
+
end
|
143
|
+
end
|
data/test/scm_test.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'yarg/scm'
|
3
|
+
require 'yarg/scm/git'
|
4
|
+
|
5
|
+
class Yarg::Scm::Custom < Yarg::Scm::Base
|
6
|
+
def initialize(options = {})
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ScmTest < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
Rake::Task.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Creating a new git SCM" do
|
16
|
+
setup do
|
17
|
+
@scm = Yarg::Scm.new(:git)
|
18
|
+
end
|
19
|
+
|
20
|
+
should_change "@scm", :to => Yarg::Scm::Git
|
21
|
+
|
22
|
+
should "return git init commands" do
|
23
|
+
assert_equal ["git init"], @scm.init_commands
|
24
|
+
end
|
25
|
+
|
26
|
+
should "return git commit commands" do
|
27
|
+
assert_equal ["git add .", "git commit -m 'Initial commit. Yarg!'"], @scm.commit_commands
|
28
|
+
end
|
29
|
+
|
30
|
+
should "return git install commands" do
|
31
|
+
assert_equal ["git submodule add git://example.com/foo.git vendor/plugins/foo"], @scm.install_commands("git://example.com/foo.git", "vendor/plugins/foo")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "Creating a new custom SCM" do
|
36
|
+
setup do
|
37
|
+
@scm = Yarg::Scm.new(:custom)
|
38
|
+
end
|
39
|
+
|
40
|
+
should_change "@scm", :to => Yarg::Scm::Custom
|
41
|
+
|
42
|
+
should "return empty init commands" do
|
43
|
+
assert @scm.init_commands.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
should "return empty commit commands" do
|
47
|
+
assert @scm.commit_commands.empty?
|
48
|
+
end
|
49
|
+
|
50
|
+
should "raise error on install request" do
|
51
|
+
assert_raise NotImplementedError do
|
52
|
+
@scm.install(:a, :b)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "Creating a new unknown SCM" do
|
58
|
+
should "fail" do
|
59
|
+
assert_raise Yarg::Error do
|
60
|
+
@scm = Yarg::Scm.new(:unknown)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
begin require 'redgreen' if ENV['TM_FILENAME'].nil?; rescue LoadError; end
|
6
|
+
require 'yarg'
|
7
|
+
|
8
|
+
module ShouldaHelper
|
9
|
+
module Macros
|
10
|
+
def should_define_task(task)
|
11
|
+
should "define the task #{task.inspect}" do
|
12
|
+
assert Rake::Task.task_defined?(task)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def should_not_define_task(task)
|
17
|
+
should "not define the task #{task.inspect}" do
|
18
|
+
assert !Rake::Task.task_defined?(task)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def should_cd_into(directory)
|
23
|
+
before_should "chdir into #{directory}" do
|
24
|
+
Dir.expects(:chdir).with(directory)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def should_have_generator_attribute_of(attribute, expected)
|
29
|
+
should "have attribute of #{attribute.inspect} matching #{expected.inspect}" do
|
30
|
+
assert_operator expected, :===, @generator.send(attribute)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def should_run_rails_command_for_app(app_name)
|
35
|
+
before_should "execute rails system call for #{app_name}" do
|
36
|
+
@generator.expects(:sh).with("rails #{app_name}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def should_delete(*files)
|
41
|
+
before_should "delete #{files.inspect}" do
|
42
|
+
File.expects(:delete).with(*files)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def should_not_delete_any_files
|
47
|
+
before_should "not delete any files" do
|
48
|
+
File.expects(:delete).never
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def should_invoke(matching_command)
|
53
|
+
before_should "invoke #{matching_command.inspect}" do
|
54
|
+
@generator.expects(:sh).with { |value|
|
55
|
+
matching_command === value
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def should_not_invoke(matching_command)
|
61
|
+
before_should "not invoke #{matching_command.inspect}" do
|
62
|
+
@generator.expects(:sh).with { |value|
|
63
|
+
matching_command === value
|
64
|
+
}.never
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Test::Unit::TestCase
|
71
|
+
extend ShouldaHelper::Macros
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rmm5t-yarg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan McGeary
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-12 00:00:00 -08:00
|
13
|
+
default_executable: yarg
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables:
|
19
|
+
- yarg
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- README.markdown
|
27
|
+
- bin/yarg
|
28
|
+
- lib/yarg
|
29
|
+
- lib/yarg/file_actions.rb
|
30
|
+
- lib/yarg/rails.rb
|
31
|
+
- lib/yarg/scm
|
32
|
+
- lib/yarg/scm/git.rb
|
33
|
+
- lib/yarg/scm.rb
|
34
|
+
- lib/yarg.rb
|
35
|
+
- test/file_actions_test.rb
|
36
|
+
- test/rails_test.rb
|
37
|
+
- test/scm_test.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/rmm5t/yarg
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --line-numbers
|
44
|
+
- --inline-source
|
45
|
+
- --main
|
46
|
+
- README.markdown
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.2.0
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: Yet Another Ruby Generator
|
68
|
+
test_files: []
|
69
|
+
|