jeweler 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/ChangeLog.markdown +64 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +164 -0
  4. data/Rakefile +89 -0
  5. data/TODO +11 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/jeweler +8 -0
  8. data/lib/jeweler.rb +154 -0
  9. data/lib/jeweler/commands.rb +12 -0
  10. data/lib/jeweler/commands/build_gem.rb +31 -0
  11. data/lib/jeweler/commands/install_gem.rb +26 -0
  12. data/lib/jeweler/commands/release.rb +59 -0
  13. data/lib/jeweler/commands/release_to_rubyforge.rb +51 -0
  14. data/lib/jeweler/commands/setup_rubyforge.rb +38 -0
  15. data/lib/jeweler/commands/validate_gemspec.rb +30 -0
  16. data/lib/jeweler/commands/version/base.rb +41 -0
  17. data/lib/jeweler/commands/version/bump_major.rb +13 -0
  18. data/lib/jeweler/commands/version/bump_minor.rb +12 -0
  19. data/lib/jeweler/commands/version/bump_patch.rb +14 -0
  20. data/lib/jeweler/commands/version/write.rb +12 -0
  21. data/lib/jeweler/commands/write_gemspec.rb +39 -0
  22. data/lib/jeweler/errors.rb +20 -0
  23. data/lib/jeweler/gemspec_helper.rb +51 -0
  24. data/lib/jeweler/generator.rb +347 -0
  25. data/lib/jeweler/generator/application.rb +45 -0
  26. data/lib/jeweler/generator/options.rb +68 -0
  27. data/lib/jeweler/tasks.rb +119 -0
  28. data/lib/jeweler/templates/.document +5 -0
  29. data/lib/jeweler/templates/.gitignore +5 -0
  30. data/lib/jeweler/templates/LICENSE +20 -0
  31. data/lib/jeweler/templates/README.rdoc +7 -0
  32. data/lib/jeweler/templates/Rakefile +125 -0
  33. data/lib/jeweler/templates/bacon/flunking.rb +7 -0
  34. data/lib/jeweler/templates/bacon/helper.rb +8 -0
  35. data/lib/jeweler/templates/features/default.feature +9 -0
  36. data/lib/jeweler/templates/features/support/env.rb +11 -0
  37. data/lib/jeweler/templates/micronaut/flunking.rb +7 -0
  38. data/lib/jeweler/templates/micronaut/helper.rb +17 -0
  39. data/lib/jeweler/templates/minitest/flunking.rb +7 -0
  40. data/lib/jeweler/templates/minitest/helper.rb +11 -0
  41. data/lib/jeweler/templates/rspec/flunking.rb +7 -0
  42. data/lib/jeweler/templates/rspec/helper.rb +9 -0
  43. data/lib/jeweler/templates/shoulda/flunking.rb +7 -0
  44. data/lib/jeweler/templates/shoulda/helper.rb +10 -0
  45. data/lib/jeweler/templates/testunit/flunking.rb +7 -0
  46. data/lib/jeweler/templates/testunit/helper.rb +9 -0
  47. data/lib/jeweler/version_helper.rb +83 -0
  48. data/test/fixtures/bar/VERSION.yml +4 -0
  49. data/test/fixtures/existing-project-with-version/LICENSE +20 -0
  50. data/test/fixtures/existing-project-with-version/README.rdoc +7 -0
  51. data/test/fixtures/existing-project-with-version/Rakefile +82 -0
  52. data/test/fixtures/existing-project-with-version/VERSION.yml +4 -0
  53. data/test/fixtures/existing-project-with-version/existing-project-with-version.gemspec +29 -0
  54. data/test/fixtures/existing-project-with-version/lib/existing_project_with_version.rb +0 -0
  55. data/test/fixtures/existing-project-with-version/test/existing_project_with_version_test.rb +7 -0
  56. data/test/fixtures/existing-project-with-version/test/test_helper.rb +10 -0
  57. data/test/geminstaller.yml +12 -0
  58. data/test/generators/initialization_test.rb +146 -0
  59. data/test/jeweler/commands/test_build_gem.rb +72 -0
  60. data/test/jeweler/commands/test_install_gem.rb +21 -0
  61. data/test/jeweler/commands/test_release.rb +180 -0
  62. data/test/jeweler/commands/test_release_to_rubyforge.rb +157 -0
  63. data/test/jeweler/commands/test_setup_rubyforge.rb +88 -0
  64. data/test/jeweler/commands/test_validate_gemspec.rb +27 -0
  65. data/test/jeweler/commands/test_write_gemspec.rb +92 -0
  66. data/test/jeweler/commands/version/test_base.rb +32 -0
  67. data/test/jeweler/commands/version/test_bump_major.rb +22 -0
  68. data/test/jeweler/commands/version/test_bump_minor.rb +19 -0
  69. data/test/jeweler/commands/version/test_bump_patch.rb +20 -0
  70. data/test/jeweler/commands/version/test_write.rb +23 -0
  71. data/test/shoulda_macros/jeweler_macros.rb +35 -0
  72. data/test/test_application.rb +113 -0
  73. data/test/test_gemspec_helper.rb +36 -0
  74. data/test/test_generator.rb +183 -0
  75. data/test/test_helper.rb +118 -0
  76. data/test/test_jeweler.rb +177 -0
  77. data/test/test_options.rb +96 -0
  78. data/test/test_tasks.rb +41 -0
  79. data/test/test_version_helper.rb +115 -0
  80. data/test/version_tmp/VERSION.yml +4 -0
  81. metadata +171 -0
@@ -0,0 +1,118 @@
1
+ require 'test/unit'
2
+
3
+ require 'rubygems'
4
+ require 'shoulda'
5
+ begin
6
+ require 'ruby-debug'
7
+ rescue LoadError
8
+ end
9
+ require 'rr'
10
+ require 'time'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
13
+ require 'jeweler'
14
+
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ require 'shoulda_macros/jeweler_macros'
17
+
18
+ # Use vendored gem because of limited gem availability on runcoderun
19
+ # This is loosely based on 'vendor everything'.
20
+ Dir[File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', '**')].each do |dir|
21
+ lib = "#{dir}/lib"
22
+ $LOAD_PATH.unshift(lib) if File.directory?(lib)
23
+ end
24
+
25
+ class RubyForgeStub
26
+ attr_accessor :userconfig, :autoconfig
27
+
28
+ def initialize
29
+ @userconfig = {}
30
+ @autoconfig = {}
31
+ end
32
+ end
33
+
34
+ class Test::Unit::TestCase
35
+ include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
36
+
37
+ def fixture_dir
38
+ File.join(File.dirname(__FILE__), 'fixtures', 'bar')
39
+ end
40
+
41
+ def tmp_dir
42
+ File.join(File.dirname(__FILE__), 'tmp')
43
+ end
44
+
45
+ def build_spec(*files)
46
+ Gem::Specification.new do |s|
47
+ s.name = "bar"
48
+ s.summary = "Simple and opinionated helper for creating Rubygem projects on GitHub"
49
+ s.email = "josh@technicalpickles.com"
50
+ s.homepage = "http://github.com/technicalpickles/jeweler"
51
+ s.description = "Simple and opinionated helper for creating Rubygem projects on GitHub"
52
+ s.authors = ["Josh Nichols"]
53
+ s.files = FileList[*files] unless files.empty?
54
+ end
55
+ end
56
+
57
+ def self.rubyforge_command_context(description, &block)
58
+ context description do
59
+ setup do
60
+ @command = eval(self.class.name.gsub(/::Test/, '::')).new
61
+
62
+ if @command.respond_to? :gemspec=
63
+ @gemspec = Object.new
64
+ @command.gemspec = @gemspec
65
+ end
66
+
67
+ if @command.respond_to? :gemspec_helper=
68
+ @gemspec_helper = Object.new
69
+ @command.gemspec_helper = @gemspec_helper
70
+ end
71
+
72
+ if @command.respond_to? :rubyforge=
73
+ @rubyforge = RubyForgeStub.new
74
+ @command.rubyforge = @rubyforge
75
+ end
76
+
77
+ if @command.respond_to? :output
78
+ @output = StringIO.new
79
+ @command.output = @output
80
+ end
81
+ end
82
+
83
+ context "", &block
84
+ end
85
+ end
86
+
87
+ def self.build_command_context(description, &block)
88
+ context description do
89
+ setup do
90
+
91
+ @repo = Object.new
92
+ @version_helper = Object.new
93
+ @gemspec = Object.new
94
+ @commit = Object.new
95
+ @version = Object.new
96
+ @output = Object.new
97
+ @base_dir = Object.new
98
+ @gemspec_helper = Object.new
99
+ @rubyforge = Object.new
100
+
101
+ @jeweler = Object.new
102
+
103
+ stub(@jeweler).repo { @repo }
104
+ stub(@jeweler).version_helper { @version_helper }
105
+ stub(@jeweler).gemspec { @gemspec }
106
+ stub(@jeweler).commit { @commit }
107
+ stub(@jeweler).version { @version }
108
+ stub(@jeweler).output { @output }
109
+ stub(@jeweler).gemspec_helper { @gemspec_helper }
110
+ stub(@jeweler).base_dir { @base_dir }
111
+ stub(@jeweler).rubyforge { @rubyforge }
112
+ end
113
+
114
+ context "", &block
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,177 @@
1
+ require 'test_helper'
2
+
3
+ class TestJeweler < Test::Unit::TestCase
4
+
5
+ def build_jeweler(base_dir = nil)
6
+ base_dir ||= non_git_dir_path
7
+
8
+ Jeweler.new(build_spec, base_dir)
9
+ end
10
+
11
+ def git_dir_path
12
+ File.join(tmp_dir, 'git')
13
+ end
14
+
15
+ def non_git_dir_path
16
+ File.join(tmp_dir, 'nongit')
17
+ end
18
+
19
+ def build_git_dir
20
+ return_to = Dir.pwd
21
+
22
+ FileUtils.mkdir_p git_dir_path
23
+ begin
24
+ Dir.chdir git_dir_path
25
+ Git.init
26
+ ensure
27
+ Dir.chdir return_to
28
+ end
29
+ end
30
+
31
+ def build_non_git_dir
32
+ FileUtils.mkdir_p non_git_dir_path
33
+ end
34
+
35
+ should "raise an error if a nil gemspec is given" do
36
+ assert_raises Jeweler::GemspecError do
37
+ Jeweler.new(nil)
38
+ end
39
+ end
40
+
41
+ should "know if it is in a git repo" do
42
+ build_git_dir
43
+
44
+ assert build_jeweler(git_dir_path).in_git_repo?
45
+ end
46
+
47
+ should "know if it is not in a git repo" do
48
+ build_non_git_dir
49
+
50
+ jeweler = build_jeweler(non_git_dir_path)
51
+ assert ! jeweler.in_git_repo?, "jeweler doesn't know that #{jeweler.base_dir} is not a git repository"
52
+ end
53
+
54
+ should "build and run write gemspec command when writing gemspec" do
55
+ jeweler = build_jeweler
56
+
57
+ command = Object.new
58
+ mock(command).run
59
+
60
+ mock(Jeweler::Commands::WriteGemspec).build_for(jeweler) { command }
61
+
62
+ jeweler.write_gemspec
63
+ end
64
+
65
+ should "build and run validate gemspec command when validating gemspec" do
66
+ jeweler = build_jeweler
67
+
68
+ command = Object.new
69
+ mock(command).run
70
+
71
+ mock(Jeweler::Commands::ValidateGemspec).build_for(jeweler) { command }
72
+
73
+ jeweler.validate_gemspec
74
+ end
75
+
76
+ should "build and run build gem command when building gem" do
77
+ jeweler = build_jeweler
78
+
79
+ command = Object.new
80
+ mock(command).run
81
+
82
+ mock(Jeweler::Commands::BuildGem).build_for(jeweler) { command }
83
+
84
+ jeweler.build_gem
85
+ end
86
+
87
+ should "build and run build gem command when installing gem" do
88
+ jeweler = build_jeweler
89
+
90
+ command = Object.new
91
+ mock(command).run
92
+
93
+ mock(Jeweler::Commands::InstallGem).build_for(jeweler) { command }
94
+
95
+ jeweler.install_gem
96
+ end
97
+
98
+ should "build and run bump major version command when bumping major version" do
99
+ jeweler = build_jeweler
100
+
101
+ command = Object.new
102
+ mock(command).run
103
+
104
+ mock(Jeweler::Commands::Version::BumpMajor).build_for(jeweler) { command }
105
+
106
+ jeweler.bump_major_version
107
+ end
108
+
109
+ should "build and run bump minor version command when bumping minor version" do
110
+ jeweler = build_jeweler
111
+
112
+ command = Object.new
113
+ mock(command).run
114
+
115
+ mock(Jeweler::Commands::Version::BumpMinor).build_for(jeweler) { command }
116
+
117
+ jeweler.bump_minor_version
118
+ end
119
+
120
+ should "build and run write version command when writing version" do
121
+ jeweler = build_jeweler
122
+
123
+ command = Object.new
124
+ mock(command).run
125
+ mock(command).major=(1)
126
+ mock(command).minor=(5)
127
+ mock(command).patch=(2)
128
+
129
+ mock(Jeweler::Commands::Version::Write).build_for(jeweler) { command }
130
+
131
+ jeweler.write_version(1, 5, 2)
132
+ end
133
+
134
+ should "build and run release command when running release" do
135
+ jeweler = build_jeweler
136
+
137
+ command = Object.new
138
+ mock(command).run
139
+
140
+ mock(Jeweler::Commands::Release).build_for(jeweler) { command }
141
+
142
+ jeweler.release
143
+ end
144
+
145
+ should "build and run release to rubyforge command when running release to rubyforge" do
146
+ jeweler = build_jeweler
147
+
148
+ command = Object.new
149
+ mock(command).run
150
+
151
+ mock(Jeweler::Commands::ReleaseToRubyforge).build_for(jeweler) { command }
152
+
153
+ jeweler.release_gem_to_rubyforge
154
+ end
155
+
156
+
157
+ should "respond to gemspec_helper" do
158
+ assert_respond_to build_jeweler, :gemspec_helper
159
+ end
160
+
161
+ should "respond to version_helper" do
162
+ assert_respond_to build_jeweler, :version_helper
163
+ end
164
+
165
+ should "respond to repo" do
166
+ assert_respond_to build_jeweler, :repo
167
+ end
168
+
169
+ should "respond to commit" do
170
+ assert_respond_to build_jeweler, :commit
171
+ end
172
+
173
+ should "respond to rubyforge" do
174
+ assert_respond_to build_jeweler, :rubyforge
175
+ end
176
+
177
+ end
@@ -0,0 +1,96 @@
1
+ require 'test_helper'
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+
5
+ def self.should_have_testing_framework(testing_framework)
6
+ should "use #{testing_framework} for testing" do
7
+ assert_equal testing_framework.to_sym, @options[:testing_framework]
8
+ end
9
+ end
10
+
11
+ def setup_options(*arguments)
12
+ @options = Jeweler::Generator::Options.new(arguments)
13
+ end
14
+
15
+ def self.for_options(*options)
16
+ context options.join(' ') do
17
+ setup { setup_options *options }
18
+ yield
19
+ end
20
+ end
21
+
22
+ context "default options" do
23
+ setup { setup_options }
24
+ should_have_testing_framework :shoulda
25
+ should 'not create repository' do
26
+ assert ! @options[:create_repo]
27
+ end
28
+ end
29
+
30
+ for_options '--shoulda' do
31
+ should_have_testing_framework :shoulda
32
+ end
33
+
34
+ for_options "--bacon" do
35
+ should_have_testing_framework :bacon
36
+ end
37
+
38
+ for_options "--testunit" do
39
+ should_have_testing_framework :testunit
40
+ end
41
+
42
+ for_options '--minitest' do
43
+ should_have_testing_framework :minitest
44
+ end
45
+
46
+ for_options '--rspec' do
47
+ should_have_testing_framework :rspec
48
+ end
49
+
50
+ for_options '--micronaut' do
51
+ should_have_testing_framework :micronaut
52
+ end
53
+
54
+ for_options '--cucumber' do
55
+ should 'enable cucumber' do
56
+ assert_equal true, @options[:use_cucumber]
57
+ end
58
+ end
59
+
60
+ for_options '--create-repo' do
61
+ should 'create repository' do
62
+ assert @options[:create_repo]
63
+ end
64
+ end
65
+
66
+ for_options '--rubyforge' do
67
+ should 'enable rubyforge' do
68
+ assert @options[:rubyforge]
69
+ end
70
+ end
71
+
72
+ for_options '--summary', 'zomg so awesome' do
73
+ should 'have summary zomg so awesome' do
74
+ assert_equal 'zomg so awesome', @options[:summary]
75
+ end
76
+ end
77
+
78
+ for_options '--directory', 'foo' do
79
+ should 'have directory foo' do
80
+ assert_equal 'foo', @options[:directory]
81
+ end
82
+ end
83
+
84
+ for_options '--help' do
85
+ should 'show help' do
86
+ assert @options[:show_help]
87
+ end
88
+ end
89
+
90
+ for_options '-h' do
91
+ should 'show help' do
92
+ assert @options[:show_help]
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ require 'rake'
4
+ class TestTasks < Test::Unit::TestCase
5
+ include Rake
6
+
7
+ context 'instantiating Jeweler::Tasks' do
8
+ setup do
9
+ Task.clear
10
+
11
+ @jt = Jeweler::Tasks.new do |s|
12
+ end
13
+ end
14
+
15
+ should 'assign @gemspec' do
16
+ assert_not_nil @jt.gemspec
17
+ end
18
+
19
+ should 'assign @jeweler' do
20
+ assert_not_nil @jt.jeweler
21
+ end
22
+
23
+ should 'define tasks' do
24
+ assert Task.task_defined?(:build)
25
+ assert Task.task_defined?(:install)
26
+ assert Task.task_defined?(:gemspec)
27
+ assert Task.task_defined?(:build)
28
+ assert Task.task_defined?(:install)
29
+ assert Task.task_defined?(:'gemspec:validate')
30
+ assert Task.task_defined?(:'gemspec:generate')
31
+ assert Task.task_defined?(:version)
32
+ assert Task.task_defined?(:'version:write')
33
+ assert Task.task_defined?(:'version:bump:major')
34
+ assert Task.task_defined?(:'version:bump:minor')
35
+ assert Task.task_defined?(:'version:bump:patch')
36
+ assert Task.task_defined?(:'release')
37
+ assert Task.task_defined?(:'rubyforge:release:gem')
38
+ assert Task.task_defined?(:'rubyforge:setup')
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,115 @@
1
+ require 'test_helper'
2
+
3
+ class TestVersionHelper < Test::Unit::TestCase
4
+
5
+ VERSION_TMP_DIR = File.dirname(__FILE__) + '/version_tmp'
6
+
7
+ def self.should_have_version(major, minor, patch)
8
+ should "have major version #{major}" do
9
+ assert_equal major, @version_helper.major
10
+ end
11
+
12
+ should "have minor version #{minor}" do
13
+ assert_equal minor, @version_helper.minor
14
+ end
15
+
16
+ should "have patch version #{patch}" do
17
+ assert_equal patch, @version_helper.patch
18
+ end
19
+
20
+ version_s = "#{major}.#{minor}.#{patch}"
21
+ should "render string as #{version_s.inspect}" do
22
+ assert_equal version_s, @version_helper.to_s
23
+ end
24
+
25
+ version_hash = {:major => major, :minor => minor, :patch => patch}
26
+ should "render hash as #{version_hash.inspect}" do
27
+ assert_equal version_hash, @version_helper.to_hash
28
+ end
29
+
30
+ end
31
+
32
+ context "VERSION.yml with 3.5.4" do
33
+ setup do
34
+ FileUtils.rm_rf VERSION_TMP_DIR
35
+ FileUtils.mkdir_p VERSION_TMP_DIR
36
+
37
+ build_version_yml VERSION_TMP_DIR, 3, 5, 4
38
+
39
+ @version_helper = Jeweler::VersionHelper.new VERSION_TMP_DIR
40
+ end
41
+
42
+ should_have_version 3, 5, 4
43
+
44
+ context "bumping major version" do
45
+ setup { @version_helper.bump_major }
46
+ should_have_version 4, 0, 0
47
+ end
48
+
49
+ context "bumping the minor version" do
50
+ setup { @version_helper.bump_minor }
51
+ should_have_version 3, 6, 0
52
+ end
53
+
54
+ context "bumping the patch version" do
55
+ setup { @version_helper.bump_patch }
56
+ should_have_version 3, 5, 5
57
+ end
58
+ end
59
+
60
+ context "Non-existant VERSION.yml" do
61
+ setup do
62
+ FileUtils.rm_rf VERSION_TMP_DIR
63
+ FileUtils.mkdir_p VERSION_TMP_DIR
64
+ end
65
+
66
+ should "not raise error if the VERSION.yml doesn't exist" do
67
+ assert_nothing_raised Jeweler::VersionYmlError do
68
+ Jeweler::VersionHelper.new(VERSION_TMP_DIR)
69
+ end
70
+ end
71
+
72
+ context "setting an initial version" do
73
+ setup do
74
+ @version_helper = Jeweler::VersionHelper.new(VERSION_TMP_DIR)
75
+ @version_helper.update_to 0, 0, 1
76
+ end
77
+
78
+ should_have_version 0, 0, 1
79
+ should "not create VERSION.yml" do
80
+ assert ! File.exists?(File.join(VERSION_TMP_DIR, 'VERSION.yml'))
81
+ end
82
+
83
+ context "outputting" do
84
+ setup do
85
+ @version_helper.write
86
+ end
87
+
88
+ should "create VERSION.yml" do
89
+ assert File.exists?(File.join(VERSION_TMP_DIR, 'VERSION.yml'))
90
+ end
91
+
92
+ context "re-reading VERSION.yml" do
93
+ setup do
94
+ @version_helper = Jeweler::VersionHelper.new(VERSION_TMP_DIR)
95
+ end
96
+
97
+ should_have_version 0, 0, 1
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ def build_version_yml(base_dir, major, minor, patch)
104
+ version_yaml_path = File.join(base_dir, 'VERSION.yml')
105
+
106
+ File.open(version_yaml_path, 'w+') do |f|
107
+ version_hash = {
108
+ 'major' => major.to_i,
109
+ 'minor' => minor.to_i,
110
+ 'patch' => patch.to_i
111
+ }
112
+ YAML.dump(version_hash, f)
113
+ end
114
+ end
115
+ end