bueller 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/ChangeLog.markdown +141 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +182 -0
  4. data/bin/bueller +5 -0
  5. data/lib/bueller/commands/build_gem.rb +50 -0
  6. data/lib/bueller/commands/git_tag_release.rb +63 -0
  7. data/lib/bueller/commands/install_gem.rb +36 -0
  8. data/lib/bueller/commands/release_to_github.rb +41 -0
  9. data/lib/bueller/commands/release_to_rubygems.rb +26 -0
  10. data/lib/bueller/commands/version/base.rb +36 -0
  11. data/lib/bueller/commands/version/bump_major.rb +11 -0
  12. data/lib/bueller/commands/version/bump_minor.rb +12 -0
  13. data/lib/bueller/commands/version/bump_patch.rb +14 -0
  14. data/lib/bueller/commands/version/write.rb +21 -0
  15. data/lib/bueller/commands/write_gemspec.rb +29 -0
  16. data/lib/bueller/commands.rb +18 -0
  17. data/lib/bueller/errors.rb +8 -0
  18. data/lib/bueller/gemspec_helper.rb +83 -0
  19. data/lib/bueller/generator/application.rb +51 -0
  20. data/lib/bueller/generator/bacon_mixin.rb +43 -0
  21. data/lib/bueller/generator/github_mixin.rb +29 -0
  22. data/lib/bueller/generator/micronaut_mixin.rb +41 -0
  23. data/lib/bueller/generator/minitest_mixin.rb +42 -0
  24. data/lib/bueller/generator/options.rb +154 -0
  25. data/lib/bueller/generator/rdoc_mixin.rb +9 -0
  26. data/lib/bueller/generator/riot_mixin.rb +42 -0
  27. data/lib/bueller/generator/rspec_mixin.rb +50 -0
  28. data/lib/bueller/generator/shindo_mixin.rb +44 -0
  29. data/lib/bueller/generator/shoulda_mixin.rb +42 -0
  30. data/lib/bueller/generator/testspec_mixin.rb +42 -0
  31. data/lib/bueller/generator/testunit_mixin.rb +39 -0
  32. data/lib/bueller/generator/yard_mixin.rb +14 -0
  33. data/lib/bueller/generator.rb +291 -0
  34. data/lib/bueller/rubyforge_tasks.rb +88 -0
  35. data/lib/bueller/tasks.rb +133 -0
  36. data/lib/bueller/templates/.document +11 -0
  37. data/lib/bueller/templates/.gitignore +40 -0
  38. data/lib/bueller/templates/Gemfile +1 -0
  39. data/lib/bueller/templates/LICENSE +20 -0
  40. data/lib/bueller/templates/README.rdoc +17 -0
  41. data/lib/bueller/templates/Rakefile +20 -0
  42. data/lib/bueller/templates/bacon/flunking.rb +7 -0
  43. data/lib/bueller/templates/bacon/helper.rb +8 -0
  44. data/lib/bueller/templates/bueller_tasks.erb +10 -0
  45. data/lib/bueller/templates/features/default.feature +9 -0
  46. data/lib/bueller/templates/features/support/env.rb +16 -0
  47. data/lib/bueller/templates/gemspec +27 -0
  48. data/lib/bueller/templates/micronaut/flunking.rb +7 -0
  49. data/lib/bueller/templates/micronaut/helper.rb +17 -0
  50. data/lib/bueller/templates/minitest/flunking.rb +7 -0
  51. data/lib/bueller/templates/minitest/helper.rb +11 -0
  52. data/lib/bueller/templates/other_tasks.erb +84 -0
  53. data/lib/bueller/templates/riot/flunking.rb +11 -0
  54. data/lib/bueller/templates/riot/helper.rb +3 -0
  55. data/lib/bueller/templates/rspec/.rspec +1 -0
  56. data/lib/bueller/templates/rspec/flunking.rb +7 -0
  57. data/lib/bueller/templates/rspec/helper.rb +19 -0
  58. data/lib/bueller/templates/shindo/flunking.rb +8 -0
  59. data/lib/bueller/templates/shindo/helper.rb +5 -0
  60. data/lib/bueller/templates/shoulda/flunking.rb +7 -0
  61. data/lib/bueller/templates/shoulda/helper.rb +10 -0
  62. data/lib/bueller/templates/testspec/flunking.rb +7 -0
  63. data/lib/bueller/templates/testspec/helper.rb +7 -0
  64. data/lib/bueller/templates/testunit/flunking.rb +7 -0
  65. data/lib/bueller/templates/testunit/helper.rb +9 -0
  66. data/lib/bueller/version_helper.rb +59 -0
  67. data/lib/bueller.rb +139 -0
  68. data/spec/bueller/commands/build_gem_spec.rb +38 -0
  69. data/spec/bueller/commands/git_tag_release_spec.rb +79 -0
  70. data/spec/bueller/commands/install_gem_spec.rb +11 -0
  71. data/spec/bueller/commands/release_to_github_spec.rb +54 -0
  72. data/spec/bueller/commands/release_to_rubygems_spec.rb +15 -0
  73. data/spec/bueller/commands/version/bump_major_spec.rb +12 -0
  74. data/spec/bueller/commands/version/bump_minor_spec.rb +12 -0
  75. data/spec/bueller/commands/version/bump_patch_spec.rb +12 -0
  76. data/spec/bueller/commands/write_gemspec_spec.rb +32 -0
  77. data/spec/bueller/gemspec_helper_spec.rb +55 -0
  78. data/spec/bueller/generator/application_spec.rb +67 -0
  79. data/spec/bueller/generator/options_spec.rb +206 -0
  80. data/spec/bueller/generator_mixins_spec.rb +23 -0
  81. data/spec/bueller/generator_spec.rb +274 -0
  82. data/spec/bueller/tasks_spec.rb +29 -0
  83. data/spec/bueller/version_helper_spec.rb +57 -0
  84. data/spec/bueller_spec.rb +94 -0
  85. data/spec/fixtures/bar/bar.gemspec +41 -0
  86. data/spec/fixtures/bar/bin/foo_the_ultimate_bin +1 -0
  87. data/spec/fixtures/bar/hey_include_me_in_gemspec +0 -0
  88. data/spec/fixtures/bar/lib/foo_the_ultimate_lib.rb +1 -0
  89. data/spec/fixtures/existing-project/LICENSE +20 -0
  90. data/spec/fixtures/existing-project/README.rdoc +7 -0
  91. data/spec/fixtures/existing-project/Rakefile +69 -0
  92. data/spec/fixtures/existing-project/existing-project.gemspec +20 -0
  93. data/spec/fixtures/existing-project/lib/existing_project_with_version.rb +0 -0
  94. data/spec/fixtures/existing-project/test/existing_project_with_version_test.rb +7 -0
  95. data/spec/fixtures/existing-project/test/test_helper.rb +10 -0
  96. data/spec/fixtures/existing-project-with-version-constant/LICENSE +20 -0
  97. data/spec/fixtures/existing-project-with-version-constant/README.rdoc +7 -0
  98. data/spec/fixtures/existing-project-with-version-constant/Rakefile +69 -0
  99. data/spec/fixtures/existing-project-with-version-constant/existing-project-with-version.gemspec +19 -0
  100. data/spec/fixtures/existing-project-with-version-constant/lib/existing_project_with_version.rb +0 -0
  101. data/spec/fixtures/existing-project-with-version-constant/test/existing_project_with_version_test.rb +7 -0
  102. data/spec/fixtures/existing-project-with-version-constant/test/test_helper.rb +10 -0
  103. data/spec/spec_helper.rb +11 -0
  104. data/spec/support/application.rb +28 -0
  105. data/spec/support/file_system.rb +24 -0
  106. data/spec/support/gemspec.rb +28 -0
  107. data/spec/support/git.rb +19 -0
  108. data/spec/support/have_version.rb +18 -0
  109. metadata +381 -0
@@ -0,0 +1,11 @@
1
+ require 'teststrap'
2
+
3
+ context "<%= require_name %>" do
4
+ setup do
5
+ false
6
+ end
7
+
8
+ asserts "i'm a failure :(" do
9
+ topic
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'riot'
3
+ require '<%= require_name %>'
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= constant_name %> do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ require 'rspec'
11
+ require '<%= require_name %>'
12
+
13
+ # Requires supporting files with custom matchers and macros, etc,
14
+ # in ./support/ and its subdirectories.
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ RSpec.configure do |config|
18
+
19
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/tests_helper')
2
+
3
+ Shindo.tests("<%= constant_name %>") do
4
+ test("fails") do
5
+ "hey buddy, you should probably rename this file and start specing for real"
6
+ false
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require '<%= require_name %>'
4
+ require 'rubygems'
5
+ require 'shindo'
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class Test<%= constant_name %> < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require '<%= require_name %>'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ describe "<%= constant_name %>" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+
2
+ require 'rubygems'
3
+ require 'test/spec'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require '<%= require_name %>'
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class Test<%= constant_name %> < Test::Unit::TestCase
4
+ def test_something_for_real
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require '<%= require_name %>'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,59 @@
1
+ require 'yaml'
2
+
3
+ class Bueller
4
+ class VersionHelper
5
+ class VersionMissing < StandardError; end
6
+ class MalformattedVersion < StandardError; end
7
+
8
+ attr_accessor :gemspec_helper
9
+ attr_reader :major, :minor, :patch, :build
10
+
11
+ def initialize(gemspec_helper)
12
+ self.gemspec_helper = gemspec_helper
13
+ parse_version
14
+ end
15
+
16
+ def parse_version
17
+ # http://rubular.com/regexes/10467 -> 3.5.4.a1
18
+ # http://rubular.com/regexes/10468 -> 3.5.4
19
+ raise VersionMissing unless gemspec_helper.has_version?
20
+ if gemspec_helper.version.to_s =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
21
+ @major = $1.to_i
22
+ @minor = $2.to_i
23
+ @patch = $3.to_i
24
+ @build = $4
25
+ else
26
+ raise MalformattedVersion, "Version doesn't match expected format: #{gemspec_helper.version}"
27
+ end
28
+ end
29
+
30
+ def bump_major
31
+ @major += 1
32
+ @minor = 0
33
+ @patch = 0
34
+ @build = nil
35
+ end
36
+
37
+ def bump_minor
38
+ @minor += 1
39
+ @patch = 0
40
+ @build = nil
41
+ end
42
+
43
+ def bump_patch
44
+ @patch += 1
45
+ @build = nil
46
+ end
47
+
48
+ def update_to(major, minor, patch, build=nil)
49
+ @major = major
50
+ @minor = minor
51
+ @patch = patch
52
+ @build = build
53
+ end
54
+
55
+ def to_s
56
+ [major, minor, patch, build].compact.join('.')
57
+ end
58
+ end
59
+ end
data/lib/bueller.rb ADDED
@@ -0,0 +1,139 @@
1
+ require 'date'
2
+
3
+ # Bueller helps you craft the perfect Rubygem. Give him a gemspec, and he takes care of the rest.
4
+ #
5
+ # See Bueller::Tasks for examples of how to get started. Additionally, resources are available on the wiki:
6
+ #
7
+ # * http://wiki.github.com/technicalpickles/bueller/create-a-new-project
8
+ # * http://wiki.github.com/technicalpickles/bueller/configure-an-existing-project
9
+ class Bueller
10
+ require 'bueller/errors'
11
+ require 'rubygems/user_interaction'
12
+
13
+ autoload :Generator, 'bueller/generator'
14
+
15
+ autoload :Commands, 'bueller/commands'
16
+
17
+ autoload :VersionHelper, 'bueller/version_helper'
18
+ autoload :GemSpecHelper, 'bueller/gemspec_helper'
19
+
20
+ autoload :Tasks, 'bueller/tasks'
21
+ autoload :RubyforgeTasks, 'bueller/rubyforge_tasks'
22
+
23
+ attr_accessor :base_dir, :output, :repo, :gemspec_helper, :version_helper, :commit
24
+
25
+ def initialize(base_dir = '.')
26
+ self.base_dir = base_dir
27
+ end
28
+
29
+ def gemspec_helper
30
+ @gemspec_helper ||= GemSpecHelper.new base_dir
31
+ end
32
+
33
+ def version_helper
34
+ @version_helper ||= Bueller::VersionHelper.new gemspec_helper
35
+ end
36
+
37
+ def repo
38
+ @repo ||= Git.open(git_base_dir) if in_git_repo?
39
+ end
40
+
41
+ def commit
42
+ @commit = @commit.nil? ? true : @commit
43
+ end
44
+
45
+ def output
46
+ @output ||= $stdout
47
+ end
48
+
49
+ # Major version, as defined by the gemspec's Version module.
50
+ # For 1.5.3, this would return 1.
51
+ def major_version
52
+ @version_helper.major
53
+ end
54
+
55
+ # Minor version, as defined by the gemspec's Version module.
56
+ # For 1.5.3, this would return 5.
57
+ def minor_version
58
+ @version_helper.minor
59
+ end
60
+
61
+ # Patch version, as defined by the gemspec's Version module.
62
+ # For 1.5.3, this would return 5.
63
+ def patch_version
64
+ @version_helper.patch
65
+ end
66
+
67
+ # Human readable version, which is used in the gemspec.
68
+ def version
69
+ gemspec_helper.version || @version_helper.to_s
70
+ end
71
+
72
+ # Writes out the gemspec
73
+ def write_gemspec
74
+ Bueller::Commands::WriteGemspec.run_for self
75
+ end
76
+
77
+ # Build a gem using the project's latest Gem::Specification
78
+ def build_gem
79
+ Bueller::Commands::BuildGem.run_for self
80
+ end
81
+
82
+ # Install a previously built gem
83
+ def install_gem
84
+ Bueller::Commands::InstallGem.run_for self
85
+ end
86
+
87
+ # Bumps the patch version.
88
+ #
89
+ # 1.5.1 -> 1.5.2
90
+ def bump_patch_version
91
+ Bueller::Commands::Version::BumpPatch.run_for self
92
+ end
93
+
94
+ # Bumps the minor version.
95
+ #
96
+ # 1.5.1 -> 1.6.0
97
+ def bump_minor_version
98
+ Bueller::Commands::Version::BumpMinor.run_for self
99
+ end
100
+
101
+ # Bumps the major version.
102
+ #
103
+ # 1.5.1 -> 2.0.0
104
+ def bump_major_version
105
+ Bueller::Commands::Version::BumpMajor.run_for self
106
+ end
107
+
108
+ # Bumps the version, to the specific major/minor/patch version, writing out the appropriate version.rb, and then reloads it.
109
+ def write_version(major, minor, patch, build)
110
+ Bueller::Commands::Version::Write.run_for self, major, minor, patch, build
111
+ end
112
+
113
+ def release_gem_to_github
114
+ Bueller::Commands::ReleaseToGithub.run_for self
115
+ end
116
+
117
+ def git_tag_release
118
+ Bueller::Commands::GitTagRelease.run_for self
119
+ end
120
+
121
+ def release_gem_to_rubygems
122
+ Bueller::Commands::ReleaseToRubygems.run_for self
123
+ end
124
+
125
+ def git_base_dir(base_dir = nil)
126
+ if base_dir
127
+ base_dir = File.dirname(base_dir)
128
+ else
129
+ base_dir = File.expand_path(self.base_dir || ".")
130
+ end
131
+ return nil if base_dir==File.dirname("/")
132
+ return base_dir if File.exists?(File.join(base_dir, '.git'))
133
+ git_base_dir(base_dir)
134
+ end
135
+
136
+ def in_git_repo?
137
+ !git_base_dir.nil?
138
+ end
139
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bueller::Commands::BuildGem do
4
+ let(:bueller) { Bueller.new }
5
+ let(:command) { Bueller::Commands::BuildGem.new bueller }
6
+
7
+ describe '#run' do
8
+ it 'should make the gem' do
9
+ command.should_receive :make_package_directory
10
+ command.run
11
+ end
12
+
13
+ it 'should move the gem into the package directory' do
14
+ command.should_receive :move_gem_file
15
+ command.run
16
+ end
17
+ end
18
+
19
+ describe '#base_dir' do
20
+ it "should delegate to bueller" do
21
+ command.base_dir.should == '.'
22
+ end
23
+ end
24
+
25
+ describe '#gemspec_helper' do
26
+ it "should delegate to bueller" do
27
+ command.gemspec_helper.should == bueller.gemspec_helper
28
+ end
29
+ end
30
+
31
+ describe '#make_package_directory' do
32
+ it 'should make a package directory' do
33
+ command = Bueller::Commands::BuildGem.new bueller
34
+ FileUtils.should_receive(:mkdir_p).with './pkg'
35
+ command.make_package_directory
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bueller::Commands::GitTagRelease do
4
+ let(:bueller) { Bueller.new }
5
+ let(:command) { Bueller::Commands::GitTagRelease.new bueller, :output => StringIO.new }
6
+
7
+ before :each do
8
+ status = mock(Object)
9
+ bueller.repo = mock(Git, :status => status)
10
+
11
+ command.repo.status.stub!(:added).and_return []
12
+ command.repo.status.stub!(:changed).and_return []
13
+ command.repo.status.stub!(:deleted).and_return []
14
+ end
15
+
16
+ describe '#run' do
17
+ before :each do
18
+ command.repo.stub! :checkout
19
+ command.repo.stub! :push
20
+ command.stub!(:release_tagged?).and_return true
21
+ end
22
+
23
+ it 'should raise an error if the staging area is unclean' do
24
+ command.stub!(:clean_staging_area?).and_return false
25
+ expect { command.run }.should raise_error(RuntimeError, /try committing/i)
26
+ end
27
+ it 'should check out master' do
28
+ command.repo.should_receive(:checkout).with 'master'
29
+ command.run
30
+ end
31
+ it 'should push' do
32
+ command.repo.should_receive :push
33
+ command.run
34
+ end
35
+
36
+ it 'should not push tags if the release is already tagged' do
37
+ command.repo.should_not_receive :add_tag
38
+ command.repo.should_receive(:push).once
39
+
40
+ command.run
41
+ end
42
+ it 'should push tags if the release is not tagged' do
43
+ command.stub!(:release_tagged?).and_return false
44
+ command.repo.should_receive :add_tag
45
+ command.repo.should_receive(:push).twice
46
+
47
+ command.run
48
+ end
49
+ end
50
+
51
+ describe "#release_tagged?" do
52
+ it 'should be true if a tag exists' do
53
+ command.repo.stub!(:tag).and_raise RuntimeError
54
+ command.release_tagged?.should be_true
55
+ end
56
+ it 'should be false if no tag exists' do
57
+ command.repo.stub!(:tag)
58
+ command.release_tagged?.should be_false
59
+ end
60
+ end
61
+
62
+ describe '#clean_staging_area?' do
63
+ it 'should return true if there are no added, changed, or deleted files' do
64
+ command.should be_clean_staging_area
65
+ end
66
+ it 'should return false if there are added files' do
67
+ command.repo.status.stub!(:added).and_return ['Gemfile.lock']
68
+ command.should_not be_clean_staging_area
69
+ end
70
+ it 'should return false if there are changed files' do
71
+ command.repo.status.stub!(:changed).and_return ['Gemfile.lock']
72
+ command.should_not be_clean_staging_area
73
+ end
74
+ it 'should return false if there are deleted files' do
75
+ command.repo.status.stub!(:deleted).and_return ['Gemfile.lock']
76
+ command.should_not be_clean_staging_area
77
+ end
78
+ end
79
+ end