vigetlabs-provisional 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,6 +6,7 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "provisional"
8
8
  gem.summary = "Automation for new Rails Projects"
9
+ gem.description = "Provisional creates a new Rails project, using a standard Rails 2.3 application template, and checks it into a new SCM repository."
9
10
  gem.email = "mark@viget.com"
10
11
  gem.homepage = "http://github.com/vigetlabs/provisional"
11
12
  gem.authors = ["Mark Cornick"]
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 1
4
- :patch: 2
4
+ :patch: 3
@@ -0,0 +1,13 @@
1
+ require 'rails/version'
2
+ require 'rails_generator'
3
+ require 'rails_generator/scripts/generate'
4
+
5
+ module Provisional
6
+ class RailsApplication
7
+ def initialize(path, template_path)
8
+ Dir.chdir(path)
9
+ Rails::Generator::Base.use_application_sources!
10
+ Rails::Generator::Scripts::Generate.new.run(['.', '-m', template_path], :generator => 'app')
11
+ end
12
+ end
13
+ end
@@ -1,8 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'git'
3
- require 'rails/version'
4
- require 'rails_generator'
5
- require 'rails_generator/scripts/generate'
3
+ require 'provisional/rails_application'
6
4
 
7
5
  module Provisional
8
6
  module SCM
@@ -11,14 +9,6 @@ module Provisional
11
9
  @options = options
12
10
  end
13
11
 
14
- def rescuing_exceptions(&block)
15
- begin
16
- yield
17
- rescue
18
- raise RuntimeError, "Repository not created due to exception: #{$!}"
19
- end
20
- end
21
-
22
12
  def gitignore
23
13
  Provisional::IGNORE_FILES.join("\n")
24
14
  end
@@ -34,10 +24,7 @@ module Provisional
34
24
 
35
25
  def generate_rails
36
26
  rescuing_exceptions do
37
- generator_options = ['.', '-m', @options['template_path']]
38
- Dir.chdir @options['path']
39
- Rails::Generator::Base.use_application_sources!
40
- Rails::Generator::Scripts::Generate.new.run generator_options, :generator => 'app'
27
+ Provisional::RailsApplication.new(@options['path'], @options['template_path'])
41
28
  end
42
29
  end
43
30
 
@@ -1,7 +1,5 @@
1
1
  require 'fileutils'
2
- require 'rails/version'
3
- require 'rails_generator'
4
- require 'rails_generator/scripts/generate'
2
+ require 'provisional/rails_application'
5
3
 
6
4
  module Provisional
7
5
  module SCM
@@ -10,12 +8,9 @@ module Provisional
10
8
  @options = options
11
9
  end
12
10
 
13
- def rescuing_exceptions(&block)
14
- begin
15
- yield
16
- rescue
17
- raise RuntimeError, "Repository not created due to exception: #{$!}"
18
- end
11
+ def gitignore
12
+ # FIXME: implement it
13
+ raise NotImplementedError
19
14
  end
20
15
 
21
16
  def init
@@ -31,10 +26,7 @@ module Provisional
31
26
  system("svn add branches tags trunk")
32
27
  system("svn commit -m 'Structure by Provisional'")
33
28
  end
34
- Dir.chdir 'trunk'
35
- generator_options = ['.', '-m', @options['template_path']]
36
- Rails::Generator::Base.use_application_sources!
37
- Rails::Generator::Scripts::Generate.new.run generator_options, :generator => 'app'
29
+ Provisional::RailsApplication.new('trunk', @options['template_path'])
38
30
  end
39
31
  end
40
32
 
@@ -1,44 +1,18 @@
1
1
  require 'provisional/scm/git'
2
- require 'net/http'
3
- require 'builder'
2
+ require 'provisional/unfuddle_common'
4
3
 
5
4
  module Provisional
6
5
  module SCM
7
6
  class Unfuddle < Provisional::SCM::Git
8
7
  def initialize(options)
9
- %w(username password domain id).each do |opt|
10
- raise ArgumentError, "#{opt} must be specified" unless options[opt]
11
- end
8
+ ensure_required_options(options)
12
9
  super
13
10
  end
14
11
 
15
12
  def checkin
16
- begin
17
- repo = super
18
-
19
- xml = Builder::XmlMarkup.new
20
- xml.repository do
21
- xml.abbreviation @options['name']
22
- xml.title @options['name']
23
- xml.system 'git'
24
- xml.projects do
25
- xml.project(:id => @options['id'])
26
- end
27
- end
28
-
29
- http = Net::HTTP.new("#{@options['domain']}.unfuddle.com", 80)
30
- request = Net::HTTP::Post.new('/api/v1/repositories.xml', 'Content-Type' => 'application/xml')
31
- request.basic_auth(@options['username'], @options['password'])
32
- request.body = xml.target!
33
- response, data = http.request(request)
34
- unless response.code == "201"
35
- raise RuntimeError, "Repository created locally, but not created on Unfuddle due to HTTP error: #{response.code}"
36
- end
37
-
38
- repo.add_remote('origin', "git@#{@options['domain']}.unfuddle.com:#{@options['domain']}/#{@options['name']}.git")
39
- rescue
40
- raise RuntimeError, "Repository created locally, but not pushed to Unfuddle due to exception: #{$!}"
41
- end
13
+ repo = super
14
+ create_repository(@options)
15
+ repo.add_remote('origin', "git@#{@options['domain']}.unfuddle.com:#{@options['domain']}/#{@options['name']}.git")
42
16
  end
43
17
  end
44
18
  end
@@ -1,42 +1,17 @@
1
1
  require 'provisional/scm/svn'
2
- require 'net/http'
3
- require 'builder'
2
+ require 'provisional/unfuddle_common'
4
3
 
5
4
  module Provisional
6
5
  module SCM
7
6
  class UnfuddleSvn < Provisional::SCM::Svn
8
7
  def initialize(options)
9
- %w(username password domain id).each do |opt|
10
- raise ArgumentError, "#{opt} must be specified" unless options[opt]
11
- end
8
+ ensure_required_options(options)
12
9
  super
13
10
  end
14
11
 
15
12
  def init
16
- begin
17
- xml = Builder::XmlMarkup.new
18
- xml.repository do
19
- xml.abbreviation @options['name']
20
- xml.title @options['name']
21
- xml.system 'svn'
22
- xml.projects do
23
- xml.project(:id => @options['id'])
24
- end
25
- end
26
-
27
- http = Net::HTTP.new("#{@options['domain']}.unfuddle.com", 80)
28
- request = Net::HTTP::Post.new('/api/v1/repositories.xml', 'Content-Type' => 'application/xml')
29
- request.basic_auth(@options['username'], @options['password'])
30
- request.body = xml.target!
31
- response, data = http.request(request)
32
- unless response.code == "201"
33
- raise RuntimeError, "Repository not created on Unfuddle due to HTTP error: #{response.code}"
34
- end
35
-
36
- @options['url'] = "http://#{@options['domain']}.unfuddle.com/svn/#{@options['domain']}_#{@options['name']}/"
37
- rescue
38
- raise RuntimeError, "Repository not created on Unfuddle due to exception: #{$!}"
39
- end
13
+ create_repository(@options)
14
+ @options['url'] = "http://#{@options['domain']}.unfuddle.com/svn/#{@options['domain']}_#{@options['name']}/"
40
15
  end
41
16
  end
42
17
  end
@@ -0,0 +1,36 @@
1
+ require 'net/http'
2
+ require 'builder'
3
+
4
+ def ensure_required_options(options)
5
+ %w(username password domain id).each do |opt|
6
+ raise ArgumentError, "#{opt} must be specified" unless options[opt]
7
+ end
8
+ end
9
+
10
+ def xml_payload(options)
11
+ xml = Builder::XmlMarkup.new
12
+ xml.repository do
13
+ xml.abbreviation options['name']
14
+ xml.title options['name']
15
+ xml.system options['scm']
16
+ xml.projects do
17
+ xml.project(:id => options['id'])
18
+ end
19
+ end
20
+ return xml.target!
21
+ end
22
+
23
+ def create_repository(options)
24
+ begin
25
+ http = Net::HTTP.new("#{options['domain']}.unfuddle.com", 80)
26
+ request = Net::HTTP::Post.new('/api/v1/repositories.xml', 'Content-Type' => 'application/xml')
27
+ request.basic_auth(options['username'], options['password'])
28
+ request.body = xml_payload(options)
29
+ response, data = http.request(request)
30
+ unless response.code == "201"
31
+ raise RuntimeError, "Repository not created on Unfuddle due to HTTP error: #{response.code}"
32
+ end
33
+ rescue
34
+ raise RuntimeError, "Repository not created on Unfuddle due to exception: #{$!}"
35
+ end
36
+ end
data/lib/provisional.rb CHANGED
@@ -2,6 +2,14 @@ $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'provisional/project'
4
4
 
5
+ def rescuing_exceptions(&block)
6
+ begin
7
+ yield
8
+ rescue
9
+ raise RuntimeError, "Repository not created due to exception: #{$!}"
10
+ end
11
+ end
12
+
5
13
  module Provisional
6
14
  IGNORE_FILES = [
7
15
  ['coverage'],
data/test/test_helper.rb CHANGED
@@ -4,4 +4,25 @@ $:.reject! { |e| e.include? 'TextMate' }
4
4
  require 'rubygems'
5
5
  require 'test/unit'
6
6
  require 'mocha'
7
- require File.dirname(__FILE__) + '/../lib/provisional'
7
+ require File.dirname(__FILE__) + '/../lib/provisional'
8
+
9
+ class Test::Unit::TestCase
10
+ def new_scm(klass, options = {})
11
+ klass.new({ 'name' => 'name', 'template_path' => 'template_path', 'domain' => 'domain', 'id' => 1,
12
+ 'username' => 'username', 'password' => 'password' }.merge(options))
13
+ end
14
+
15
+ def stub_git_checkin(&block)
16
+ repo_stub = stub()
17
+ repo_stub.expects(:add).with('.')
18
+ repo_stub.expects(:commit).with('Initial commit by Provisional')
19
+ if block
20
+ yield repo_stub
21
+ end
22
+ Git.expects(:open).returns(repo_stub)
23
+ Dir.expects(:chdir)
24
+ gitignore_file = stub()
25
+ gitignore_file.expects(:puts).with(@scm.gitignore)
26
+ File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
27
+ end
28
+ end
@@ -4,12 +4,7 @@ require File.dirname(__FILE__) + '/../../lib/provisional/scm/git'
4
4
  class GitTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @scm = Provisional::SCM::Git.new(
8
- {
9
- 'name' => 'name',
10
- 'template_path' => 'template_path'
11
- }
12
- )
7
+ @scm = new_scm(Provisional::SCM::Git)
13
8
  end
14
9
 
15
10
  def test_gitignore
@@ -31,30 +26,19 @@ class GitTest < Test::Unit::TestCase
31
26
  end
32
27
 
33
28
  def test_generate_rails
34
- Dir.expects(:chdir)
35
- Rails::Generator::Base.expects(:use_application_sources!)
36
- generator_stub = stub()
37
- generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
38
- Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
29
+ Provisional::RailsApplication.expects(:new)
39
30
  @scm.generate_rails
40
31
  end
41
32
 
42
33
  def test_generate_rails_should_raise_RuntimeError_if_any_step_raises_any_exception
43
- Dir.expects(:chdir).raises(Errno::ENOENT)
34
+ Provisional::RailsApplication.expects(:new).raises(RuntimeError)
44
35
  assert_raise RuntimeError do
45
36
  @scm.generate_rails
46
37
  end
47
38
  end
48
39
 
49
40
  def test_checkin
50
- repo_stub = stub()
51
- repo_stub.expects(:add).with('.')
52
- repo_stub.expects(:commit).with('Initial commit by Provisional')
53
- Git.expects(:open).returns(repo_stub)
54
- Dir.expects(:chdir)
55
- gitignore_file = stub()
56
- gitignore_file.expects(:puts).with(@scm.gitignore)
57
- File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
41
+ stub_git_checkin
58
42
  @scm.checkin
59
43
  end
60
44
 
@@ -3,67 +3,28 @@ require File.dirname(__FILE__) + '/../../lib/provisional/scm/github'
3
3
 
4
4
  class GithubTest < Test::Unit::TestCase
5
5
  def setup
6
- @scm = Provisional::SCM::Github.new(
7
- {
8
- 'name' => 'name',
9
- 'template_path' => 'template_path'
10
- }
11
- )
12
- end
13
-
14
- def test_gitignore
15
- assert_equal Provisional::IGNORE_FILES.join("\n"), @scm.gitignore
16
- end
17
-
18
- def test_init
19
- FileUtils.expects(:mkdir_p).with('name')
20
- Dir.expects(:chdir).with('name')
21
- Git.expects(:init)
22
- @scm.init
23
- end
24
-
25
- def test_generate_rails
26
- Dir.expects(:chdir)
27
- Rails::Generator::Base.expects(:use_application_sources!)
28
- generator_stub = stub()
29
- generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
30
- Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
31
- @scm.generate_rails
6
+ @scm = new_scm(Provisional::SCM::Github)
32
7
  end
33
8
 
34
9
  def test_checkin
35
- repo_stub = stub()
36
- repo_stub.expects(:add).with('.')
37
- repo_stub.expects(:commit).with('Initial commit by Provisional')
38
- repo_stub.expects(:config).with('github.user').returns('user')
39
- repo_stub.expects(:config).with('github.token').returns('token')
40
- repo_stub.expects(:add_remote)
41
- repo_stub.expects(:push)
42
-
43
- Git.expects(:open).returns(repo_stub)
44
- Dir.expects(:chdir)
45
- gitignore_file = stub()
46
- gitignore_file.expects(:puts).with(@scm.gitignore)
47
- File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
10
+ stub_git_checkin do |stub|
11
+ stub.expects(:config).with('github.user').returns('user')
12
+ stub.expects(:config).with('github.token').returns('token')
13
+ stub.expects(:add_remote)
14
+ stub.expects(:push)
15
+ end
48
16
 
49
17
  URI.expects(:parse).with('https://github.com/api/v2/yaml/repos/create')
50
18
  Net::HTTP.expects(:post_form).with(nil, { 'login' => 'user', 'token' => 'token', 'name' => 'name' })
51
19
 
52
20
  @scm.checkin
53
21
  end
54
-
55
- def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
56
- repo_stub = stub()
57
- repo_stub.expects(:add).with('.')
58
- repo_stub.expects(:commit).with('Initial commit by Provisional')
59
- repo_stub.expects(:config).with('github.user').returns('user')
60
- repo_stub.expects(:config).with('github.token').returns('token')
61
22
 
62
- Git.expects(:open).returns(repo_stub)
63
- Dir.expects(:chdir)
64
- gitignore_file = stub()
65
- gitignore_file.expects(:puts).with(@scm.gitignore)
66
- File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
23
+ def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
24
+ stub_git_checkin do |stub|
25
+ stub.expects(:config).with('github.user').returns('user')
26
+ stub.expects(:config).with('github.token').returns('token')
27
+ end
67
28
 
68
29
  URI.expects(:parse).with('https://github.com/api/v2/yaml/repos/create')
69
30
  Net::HTTP.expects(:post_form).with(nil, { 'login' => 'user', 'token' => 'token', 'name' => 'name' }).raises(Net::HTTPUnauthorized)
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../../lib/provisional/rails_application'
3
+
4
+ class RailsApplicationTest < Test::Unit::TestCase
5
+ def test_initialize
6
+ Dir.expects(:chdir).with('path')
7
+ Rails::Generator::Base.expects(:use_application_sources!)
8
+ generator_stub = stub()
9
+ generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
10
+ Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
11
+ Provisional::RailsApplication.new('path', 'template_path')
12
+ end
13
+ end
@@ -4,15 +4,14 @@ require File.dirname(__FILE__) + '/../../lib/provisional/scm/svn'
4
4
  class SvnTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @scm = Provisional::SCM::Svn.new(
8
- {
9
- 'name' => 'name',
10
- 'template_path' => 'template_path',
11
- 'url' => 'url',
12
- 'username' => 'username',
13
- 'password' => 'password'
14
- }
15
- )
7
+ @scm = new_scm(Provisional::SCM::Svn, { 'url' => 'url' })
8
+ end
9
+
10
+ # FIXME: implement this
11
+ def test_gitignore
12
+ assert_raise NotImplementedError do
13
+ @scm.gitignore
14
+ end
16
15
  end
17
16
 
18
17
  def test_init
@@ -27,22 +26,14 @@ class SvnTest < Test::Unit::TestCase
27
26
  %w(branches tags trunk).each {|d| Dir.expects(:mkdir).with(d)}
28
27
  @scm.expects(:system).with("svn add branches tags trunk")
29
28
  @scm.expects(:system).with("svn commit -m 'Structure by Provisional'")
30
- Dir.expects(:chdir).with('trunk')
31
- Rails::Generator::Base.expects(:use_application_sources!)
32
- generator_stub = stub()
33
- generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
34
- Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
29
+ Provisional::RailsApplication.expects(:new)
35
30
  @scm.generate_rails
36
31
  end
37
32
 
38
33
  def test_generate_rails_can_optionally_skip_svn_structure_creation
39
34
  @scm.expects(:system).with("svn co --username=username --password=password url name")
40
35
  Dir.expects(:chdir).with('name')
41
- Dir.expects(:chdir).with('trunk')
42
- Rails::Generator::Base.expects(:use_application_sources!)
43
- generator_stub = stub()
44
- generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
45
- Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
36
+ Provisional::RailsApplication.expects(:new)
46
37
  @scm.generate_rails(false)
47
38
  end
48
39
 
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../../lib/provisional/unfuddle_common'
3
+
4
+ class UnfuddleCommonTest < Test::Unit::TestCase
5
+ def test_ensure_required_options_should_pass_if_all_options_present
6
+ options = {'username' => 'username', 'password' => 'password', 'domain' => 'domain', 'id' => 1}
7
+ assert ensure_required_options(options)
8
+ end
9
+
10
+ def test_ensure_required_options_should_raise_if_any_option_missing
11
+ options = {'username' => 'username', 'password' => 'password', 'domain' => 'domain'}
12
+ assert_raise ArgumentError do
13
+ ensure_required_options(options)
14
+ end
15
+ end
16
+
17
+ def test_xml_payload
18
+ options = {'name' => 'name', 'scm' => 'git', 'id' => 1}
19
+ expected = '<repository><abbreviation>name</abbreviation><title>name</title><system>git</system>'
20
+ expected += '<projects><project id="1"/></projects></repository>'
21
+ assert_equal expected, xml_payload(options)
22
+ end
23
+
24
+ def test_checkin
25
+ options = {'username' => 'username', 'password' => 'password', 'domain' => 'domain'}
26
+ request_stub = stub()
27
+ request_stub.expects(:basic_auth).with('username', 'password')
28
+ request_stub.expects(:body=)
29
+ response_stub = stub(:code => '201')
30
+ http_stub = stub()
31
+ http_stub.expects(:request).with(request_stub).returns(response_stub, nil)
32
+
33
+ self.expects(:xml_payload).returns("")
34
+
35
+ Net::HTTP::Post.expects(:new).with('/api/v1/repositories.xml', 'Content-Type' => 'application/xml').returns(request_stub)
36
+ Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).returns(http_stub)
37
+
38
+ create_repository(options)
39
+ end
40
+
41
+ def test_checkin_should_raise_RuntimeError_if_unfuddle_api_call_fails
42
+ options = {'username' => 'username', 'password' => 'password', 'domain' => 'domain'}
43
+ request_stub = stub()
44
+ request_stub.expects(:basic_auth).with('username', 'password')
45
+ request_stub.expects(:body=)
46
+ response_stub = stub(:code => '500')
47
+ http_stub = stub()
48
+ http_stub.expects(:request).with(request_stub).returns(response_stub, nil)
49
+
50
+ self.expects(:xml_payload).returns("")
51
+
52
+ Net::HTTP::Post.expects(:new).with('/api/v1/repositories.xml', 'Content-Type' => 'application/xml').returns(request_stub)
53
+ Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).returns(http_stub)
54
+
55
+ assert_raise RuntimeError do
56
+ create_repository(options)
57
+ end
58
+ end
59
+
60
+ def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
61
+ options = {'domain' => 'domain'}
62
+ Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).raises(Net::HTTPNotFound)
63
+
64
+ assert_raise RuntimeError do
65
+ create_repository(options)
66
+ end
67
+ end
68
+ end
@@ -3,53 +3,11 @@ require File.dirname(__FILE__) + '/../../lib/provisional/scm/unfuddle_svn'
3
3
 
4
4
  class UnfuddleSvnTest < Test::Unit::TestCase
5
5
  def setup
6
- @scm = Provisional::SCM::UnfuddleSvn.new(
7
- {
8
- 'name' => 'name',
9
- 'template_path' => 'template_path',
10
- 'domain' => 'domain',
11
- 'id' => 1,
12
- 'username' => 'username',
13
- 'password' => 'password'
14
- }
15
- )
6
+ @scm = new_scm(Provisional::SCM::UnfuddleSvn)
16
7
  end
17
8
 
18
9
  def test_init
19
- request_stub = stub()
20
- request_stub.expects(:basic_auth).with('username', 'password')
21
- request_stub.expects(:body=)
22
- response_stub = stub(:code => '201')
23
- http_stub = stub()
24
- http_stub.expects(:request).with(request_stub).returns(response_stub, nil)
25
-
26
- Net::HTTP::Post.expects(:new).with('/api/v1/repositories.xml', 'Content-Type' => 'application/xml').returns(request_stub)
27
- Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).returns(http_stub)
28
-
10
+ @scm.expects(:create_repository)
29
11
  @scm.init
30
12
  end
31
-
32
- def test_init_should_raise_RuntimeError_if_unfuddle_api_call_fails
33
- request_stub = stub()
34
- request_stub.expects(:basic_auth).with('username', 'password')
35
- request_stub.expects(:body=)
36
- response_stub = stub(:code => '500')
37
- http_stub = stub()
38
- http_stub.expects(:request).with(request_stub).returns(response_stub, nil)
39
-
40
- Net::HTTP::Post.expects(:new).with('/api/v1/repositories.xml', 'Content-Type' => 'application/xml').returns(request_stub)
41
- Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).returns(http_stub)
42
-
43
- assert_raise RuntimeError do
44
- @scm.init
45
- end
46
- end
47
-
48
- def test_init_should_raise_RuntimeError_if_any_step_raises_any_exception
49
- Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).raises(Net::HTTPNotFound)
50
-
51
- assert_raise RuntimeError do
52
- @scm.init
53
- end
54
- end
55
13
  end
@@ -3,104 +3,14 @@ require File.dirname(__FILE__) + '/../../lib/provisional/scm/unfuddle'
3
3
 
4
4
  class UnfuddleTest < Test::Unit::TestCase
5
5
  def setup
6
- @scm = Provisional::SCM::Unfuddle.new(
7
- {
8
- 'name' => 'name',
9
- 'template_path' => 'template_path',
10
- 'domain' => 'domain',
11
- 'id' => 1,
12
- 'username' => 'username',
13
- 'password' => 'password'
14
- }
15
- )
16
- end
17
-
18
- def test_gitignore
19
- assert_equal Provisional::IGNORE_FILES.join("\n"), @scm.gitignore
20
- end
21
-
22
- def test_init
23
- FileUtils.expects(:mkdir_p).with('name')
24
- Dir.expects(:chdir).with('name')
25
- Git.expects(:init)
26
- @scm.init
27
- end
28
-
29
- def test_generate_rails
30
- Dir.expects(:chdir)
31
- Rails::Generator::Base.expects(:use_application_sources!)
32
- generator_stub = stub()
33
- generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
34
- Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
35
- @scm.generate_rails
6
+ @scm = new_scm(Provisional::SCM::Unfuddle)
36
7
  end
37
8
 
38
9
  def test_checkin
39
- repo_stub = stub()
40
- repo_stub.expects(:add).with('.')
41
- repo_stub.expects(:commit).with('Initial commit by Provisional')
42
- repo_stub.expects(:add_remote)
43
-
44
- Git.expects(:open).returns(repo_stub)
45
- Dir.expects(:chdir)
46
- gitignore_file = stub()
47
- gitignore_file.expects(:puts).with(@scm.gitignore)
48
- File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
49
-
50
- request_stub = stub()
51
- request_stub.expects(:basic_auth).with('username', 'password')
52
- request_stub.expects(:body=)
53
- response_stub = stub(:code => '201')
54
- http_stub = stub()
55
- http_stub.expects(:request).with(request_stub).returns(response_stub, nil)
56
-
57
- Net::HTTP::Post.expects(:new).with('/api/v1/repositories.xml', 'Content-Type' => 'application/xml').returns(request_stub)
58
- Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).returns(http_stub)
59
-
60
- @scm.checkin
61
- end
62
-
63
- def test_checkin_should_raise_RuntimeError_if_unfuddle_api_call_fails
64
- repo_stub = stub()
65
- repo_stub.expects(:add).with('.')
66
- repo_stub.expects(:commit).with('Initial commit by Provisional')
67
-
68
- Git.expects(:open).returns(repo_stub)
69
- Dir.expects(:chdir)
70
- gitignore_file = stub()
71
- gitignore_file.expects(:puts).with(@scm.gitignore)
72
- File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
73
-
74
- request_stub = stub()
75
- request_stub.expects(:basic_auth).with('username', 'password')
76
- request_stub.expects(:body=)
77
- response_stub = stub(:code => '500')
78
- http_stub = stub()
79
- http_stub.expects(:request).with(request_stub).returns(response_stub, nil)
80
-
81
- Net::HTTP::Post.expects(:new).with('/api/v1/repositories.xml', 'Content-Type' => 'application/xml').returns(request_stub)
82
- Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).returns(http_stub)
83
-
84
- assert_raise RuntimeError do
85
- @scm.checkin
86
- end
87
- end
88
-
89
- def test_checkin_should_raise_RuntimeError_if_any_step_raises_any_exception
90
- repo_stub = stub()
91
- repo_stub.expects(:add).with('.')
92
- repo_stub.expects(:commit).with('Initial commit by Provisional')
93
-
94
- Git.expects(:open).returns(repo_stub)
95
- Dir.expects(:chdir)
96
- gitignore_file = stub()
97
- gitignore_file.expects(:puts).with(@scm.gitignore)
98
- File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
99
-
100
- Net::HTTP.expects(:new).with("domain.unfuddle.com", 80).raises(Net::HTTPNotFound)
101
-
102
- assert_raise RuntimeError do
103
- @scm.checkin
10
+ stub_git_checkin do |stub|
11
+ stub.expects(:add_remote)
104
12
  end
13
+ @scm.expects(:create_repository)
14
+ @scm.checkin
105
15
  end
106
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vigetlabs-provisional
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cornick
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-04 00:00:00 -07:00
12
+ date: 2009-05-08 00:00:00 -07:00
13
13
  default_executable: provisional
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,7 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 2.1.2
54
54
  version:
55
- description:
55
+ description: Provisional creates a new Rails project, using a standard Rails 2.3 application template, and checks it into a new SCM repository.
56
56
  email: mark@viget.com
57
57
  executables:
58
58
  - provisional
@@ -67,17 +67,21 @@ files:
67
67
  - bin/provisional
68
68
  - lib/provisional.rb
69
69
  - lib/provisional/project.rb
70
+ - lib/provisional/rails_application.rb
70
71
  - lib/provisional/scm/git.rb
71
72
  - lib/provisional/scm/github.rb
72
73
  - lib/provisional/scm/svn.rb
73
74
  - lib/provisional/scm/unfuddle.rb
74
75
  - lib/provisional/scm/unfuddle_svn.rb
75
76
  - lib/provisional/templates/viget.rb
77
+ - lib/provisional/unfuddle_common.rb
76
78
  - test/test_helper.rb
77
79
  - test/unit/git_test.rb
78
80
  - test/unit/github_test.rb
79
81
  - test/unit/project_test.rb
82
+ - test/unit/rails_application_test.rb
80
83
  - test/unit/svn_test.rb
84
+ - test/unit/unfuddle_common_test.rb
81
85
  - test/unit/unfuddle_svn_test.rb
82
86
  - test/unit/unfuddle_test.rb
83
87
  has_rdoc: true
@@ -111,6 +115,8 @@ test_files:
111
115
  - test/unit/git_test.rb
112
116
  - test/unit/github_test.rb
113
117
  - test/unit/project_test.rb
118
+ - test/unit/rails_application_test.rb
114
119
  - test/unit/svn_test.rb
120
+ - test/unit/unfuddle_common_test.rb
115
121
  - test/unit/unfuddle_svn_test.rb
116
122
  - test/unit/unfuddle_test.rb