zenslap 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +22 -0
- data/bin/zenslap +26 -0
- data/lib/zenslap/client.rb +19 -0
- data/lib/zenslap/commands.rb +93 -0
- data/lib/zenslap/console_error.rb +5 -0
- data/lib/zenslap/git_repo.rb +88 -0
- data/lib/zenslap.rb +4 -0
- data/spec/client_spec.rb +27 -0
- data/spec/commands_spec.rb +116 -0
- data/spec/git_repo_spec.rb +157 -0
- data/spec/spec_helper.rb +39 -0
- data/zenslap.gemspec +29 -0
- metadata +128 -0
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'ruby-debug'
|
9
|
+
gem 'shoulda'
|
10
|
+
gem 'mocha'
|
11
|
+
gem 'bourne'
|
12
|
+
gem 'webmock', '1.3.5'
|
13
|
+
gem 'method_lister'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :local do
|
17
|
+
gem 'autotest'
|
18
|
+
gem 'redgreen'
|
19
|
+
gem 'autotest-growl'
|
20
|
+
gem 'autotest-fsevent'
|
21
|
+
gem 'ruby-debug'
|
22
|
+
end
|
data/bin/zenslap
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/../lib/zenslap'
|
9
|
+
|
10
|
+
args = ARGV.dup
|
11
|
+
ARGV.clear
|
12
|
+
|
13
|
+
command = args.shift
|
14
|
+
if command && ["create", "destroy"].include?(command)
|
15
|
+
Zenslap::Command.new.run(command)
|
16
|
+
else
|
17
|
+
puts <<-eos
|
18
|
+
|
19
|
+
=== Zenslap commands
|
20
|
+
|
21
|
+
create # create zenslap environment for this project
|
22
|
+
destroy # destroy zenslap environment for this project
|
23
|
+
|
24
|
+
eos
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class ZenslapClient
|
4
|
+
|
5
|
+
def self.configure(uuid, repo_owner, repo_name, github_credentials, heroku_app)
|
6
|
+
#TODO need to make https
|
7
|
+
RestClient.post("http://zenslap.me/projects",
|
8
|
+
{
|
9
|
+
:project => github_credentials.merge({
|
10
|
+
:owner => repo_owner,
|
11
|
+
:name => repo_name,
|
12
|
+
:uuid => uuid,
|
13
|
+
:heroku_app => heroku_app
|
14
|
+
})
|
15
|
+
}
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'heroku'
|
2
|
+
require 'heroku/command'
|
3
|
+
|
4
|
+
module Zenslap
|
5
|
+
class Command
|
6
|
+
|
7
|
+
ZENSLAP_HEROKU_USER = "admin@zenslap.me"
|
8
|
+
ZENSLAP_ADDON = "zenslap2"
|
9
|
+
|
10
|
+
def run(command)
|
11
|
+
case command
|
12
|
+
when "create" then create
|
13
|
+
when "destroy" then destroy
|
14
|
+
else raise "#{command} command not found"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def display(message)
|
19
|
+
puts "---> #{message}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def display_error(message)
|
23
|
+
puts "---! #{message}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def display_numbered_bullets(items)
|
27
|
+
items.each_with_index do |item, index|
|
28
|
+
puts " #{index}) #{item}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def git_repo
|
33
|
+
@git_repo ||= GitRepo.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def heroku
|
37
|
+
Heroku::Command.run_internal('auth:client', [])
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_environment_name(name, owner)
|
41
|
+
"#{name}-zenslap-#{owner}".gsub(/[^a-zA-Z\d-]/, '-')
|
42
|
+
end
|
43
|
+
|
44
|
+
def create
|
45
|
+
begin
|
46
|
+
if git_repo.remote_exists? 'zenslap'
|
47
|
+
display_error "Zenslap has already been set up"
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
display "Checking for github details"
|
52
|
+
git_repo.github_owner
|
53
|
+
git_repo.github_name
|
54
|
+
git_repo.github_credentials
|
55
|
+
|
56
|
+
display "Creating test environment in heroku"
|
57
|
+
display "Using account: #{heroku.user}"
|
58
|
+
heroku_app = test_environment_name(git_repo.github_name, git_repo.github_owner)
|
59
|
+
display "Creating test environment: #{heroku_app}"
|
60
|
+
heroku.create heroku_app
|
61
|
+
heroku.add_collaborator(heroku_app, ZENSLAP_HEROKU_USER)
|
62
|
+
git_repo.add_zenslap_remote(heroku_app)
|
63
|
+
|
64
|
+
display "Installing zenslap addon"
|
65
|
+
heroku.install_addon heroku_app, ZENSLAP_ADDON
|
66
|
+
zenslap_id = heroku.config_vars(heroku_app)["ZENSLAP_ID"]
|
67
|
+
|
68
|
+
display "Configuring zenslap"
|
69
|
+
ZenslapClient.configure( zenslap_id, git_repo.github_owner, git_repo.github_name, git_repo.github_credentials, heroku_app )
|
70
|
+
|
71
|
+
display ""
|
72
|
+
display "Nearly there, you just need to do add a couple of things on github and you'll be ready to go"
|
73
|
+
display_numbered_bullets [
|
74
|
+
"Add 'zenslap' as a collaborator",
|
75
|
+
"Add 'http://zenslap.me/pushes' to the service hooks"
|
76
|
+
]
|
77
|
+
|
78
|
+
rescue ConsoleError => e
|
79
|
+
display_error e
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def destroy
|
84
|
+
display "Destroying zenslap project and test environment"
|
85
|
+
heroku.destroy git_repo.zenslap_app
|
86
|
+
display "Removing zenslap git remote"
|
87
|
+
git_repo.remove_zenslap_remote
|
88
|
+
display "All done. Thanks for using zenslap."
|
89
|
+
rescue ConsoleError => e
|
90
|
+
display_error e
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'git'
|
2
|
+
|
3
|
+
class GitRepo
|
4
|
+
GITHUB_REGEX = /github.com[:\/](\S+)\/(\S+?)(?:\.git)?$/
|
5
|
+
HEROKU_GIT_REGEX = /git@heroku\..*?:(.*)\.git/
|
6
|
+
|
7
|
+
def github_url
|
8
|
+
@github_url ||= find_url("---> Which github repository do you want to use?", GITHUB_REGEX, "No github remotes found. You need to add one to your git config before you can add zenslap.")
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_url(help, regex, message)
|
12
|
+
remotes = git.remotes.select{ |r| r.url =~ regex }
|
13
|
+
raise ConsoleError.new(message) if remotes.empty?
|
14
|
+
remotes.length == 1 ? remotes.first.url : choose_one( help, remotes ).url
|
15
|
+
end
|
16
|
+
|
17
|
+
def choose_one(help, remotes)
|
18
|
+
names = remotes.map &:name
|
19
|
+
begin
|
20
|
+
puts help
|
21
|
+
puts names
|
22
|
+
name = gets.chomp
|
23
|
+
end while not names.include? name
|
24
|
+
remotes.find{ |r| r.name == name }
|
25
|
+
end
|
26
|
+
|
27
|
+
def github_credentials
|
28
|
+
{ :login => retrieve_github('user'), :token => retrieve_github('token') }
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_zenslap_remote(name)
|
32
|
+
git.add_remote "zenslap", "git@heroku.com:#{name}.git"
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_zenslap_remote
|
36
|
+
git.remote("zenslap").remove
|
37
|
+
end
|
38
|
+
|
39
|
+
def zenslap_app
|
40
|
+
HEROKU_GIT_REGEX.match(git.remote("zenslap").url)[1]
|
41
|
+
end
|
42
|
+
|
43
|
+
def remote_exists?(name)
|
44
|
+
!!git.remotes.find{|r|r.name == name}
|
45
|
+
end
|
46
|
+
|
47
|
+
def retrieve_github(param)
|
48
|
+
value = exec("git config --get github.#{param}").strip
|
49
|
+
if value == ""
|
50
|
+
value = ask_for("your github #{param}")
|
51
|
+
exec("git config --add github.#{param} #{value}")
|
52
|
+
end
|
53
|
+
value
|
54
|
+
end
|
55
|
+
|
56
|
+
def ask_for(message)
|
57
|
+
value = ""
|
58
|
+
while value == ""
|
59
|
+
puts "---> Please enter #{message}"
|
60
|
+
value = gets.strip
|
61
|
+
end
|
62
|
+
value
|
63
|
+
end
|
64
|
+
|
65
|
+
def exec(command)
|
66
|
+
`#{command}`
|
67
|
+
end
|
68
|
+
|
69
|
+
def git
|
70
|
+
Git.open('.')
|
71
|
+
end
|
72
|
+
|
73
|
+
def github_owner
|
74
|
+
@owner ||= parse_github_url[0]
|
75
|
+
end
|
76
|
+
|
77
|
+
def github_name
|
78
|
+
@name ||= parse_github_url[1]
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def parse_github_url
|
84
|
+
search_result = /github.com[:\/](\S+)\/(\S+?)(?:\.git)?$/.match(github_url)
|
85
|
+
raise InvalidUrlError, github_url unless search_result
|
86
|
+
owner, name = search_result[1..2]
|
87
|
+
end
|
88
|
+
end
|
data/lib/zenslap.rb
ADDED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
describe ZenslapClient do
|
6
|
+
|
7
|
+
context "zenslap client" do
|
8
|
+
ZENSLAP_ID = 5
|
9
|
+
OWNER = "opsb"
|
10
|
+
NAME = "carbonpt"
|
11
|
+
GITHUB_CREDENTIALS = { :login => 'jimbo', :token => 'randomhash'}
|
12
|
+
HEROKU_EMAIL = "jim@bob.com"
|
13
|
+
HEROKU_PASSWORD = "password"
|
14
|
+
HEROKU_APP = "conference_hub_ci"
|
15
|
+
|
16
|
+
before do
|
17
|
+
RestClient.stubs(:post)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should configure the project" do
|
21
|
+
ZenslapClient.configure ZENSLAP_ID, OWNER, NAME, GITHUB_CREDENTIALS, HEROKU_APP
|
22
|
+
RestClient.should have_received(:post).with( "http://zenslap.me/projects", :project =>
|
23
|
+
GITHUB_CREDENTIALS.merge({ :owner => OWNER, :name => NAME, :uuid => ZENSLAP_ID, :heroku_app => HEROKU_APP } ))
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
require 'heroku'
|
3
|
+
|
4
|
+
module ZenslapSpec
|
5
|
+
|
6
|
+
describe Zenslap::Command do
|
7
|
+
ZENSLAP_ID = 1
|
8
|
+
GITHUB_URL = "git@github.com:opsb/conference_hub"
|
9
|
+
GITHUB_REPO_OWNER = "opsb"
|
10
|
+
GITHUB_REPO_NAME = "conference_hub"
|
11
|
+
GITHUB_LOGIN = "jimbo"
|
12
|
+
GITHUB_TOKEN = "df67sd6f67"
|
13
|
+
GITHUB_CREDENTIALS = { :login => GITHUB_LOGIN, :token => GITHUB_TOKEN }
|
14
|
+
HEROKU_EMAIL = "jim@bob.com"
|
15
|
+
HEROKU_PASSWORD = "password"
|
16
|
+
HEROKU_APP = "conference-hub-zenslap-opsb"
|
17
|
+
ADDON_NAME = "zenslap2"
|
18
|
+
|
19
|
+
def stub_git
|
20
|
+
@git_repo = stub do
|
21
|
+
stubs(:github_url).returns(GITHUB_URL)
|
22
|
+
stubs(:github_credentials).returns(GITHUB_CREDENTIALS)
|
23
|
+
stubs(:github_owner).returns(GITHUB_REPO_OWNER)
|
24
|
+
stubs(:github_name).returns(GITHUB_REPO_NAME)
|
25
|
+
stubs(:add_zenslap_remote)
|
26
|
+
stubs(:remove_zenslap_remote)
|
27
|
+
stubs(:zenslap_app).returns(HEROKU_APP)
|
28
|
+
end
|
29
|
+
GitRepo.stubs(:new).returns(@git_repo)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_zenslap
|
33
|
+
ZenslapClient.stubs(:configure)
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_heroku
|
37
|
+
@heroku = stub do
|
38
|
+
stubs(:user).returns(HEROKU_EMAIL)
|
39
|
+
stubs(:password).returns(HEROKU_PASSWORD)
|
40
|
+
stubs(:create).returns(HEROKU_APP)
|
41
|
+
stubs(:add_collaborator)
|
42
|
+
stubs(:install_addon)
|
43
|
+
stubs(:config_vars).returns({ "ZENSLAP_ID" => ZENSLAP_ID })
|
44
|
+
stubs(:destroy)
|
45
|
+
end
|
46
|
+
Heroku::Command.stubs(:run_internal).with('auth:client', []).returns(@heroku)
|
47
|
+
end
|
48
|
+
|
49
|
+
context "zenslap" do
|
50
|
+
before do
|
51
|
+
@command = Zenslap::Command.new
|
52
|
+
@command.stubs(:display_error)
|
53
|
+
@command.stubs(:display)
|
54
|
+
@command.stubs(:display_numbered_bullets)
|
55
|
+
stub_git
|
56
|
+
stub_zenslap
|
57
|
+
stub_heroku
|
58
|
+
end
|
59
|
+
|
60
|
+
context "#create" do
|
61
|
+
context "when zenslap has already been created" do
|
62
|
+
before do
|
63
|
+
@git_repo.stubs(:remote_exists?).with("zenslap").returns(true)
|
64
|
+
@command.create
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should display message saying zenslap has already been created" do
|
68
|
+
@command.should have_received(:display_error).with("Zenslap has already been set up")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "before zenslap has been created" do
|
73
|
+
before do
|
74
|
+
@git_repo.stubs(:remote_exists?).with("zenslap").returns(false)
|
75
|
+
@command.create
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create new heroku app to be used for running tests and billing" do
|
79
|
+
@heroku.should have_received(:create).with( HEROKU_APP )
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should add zenslap remote" do
|
83
|
+
assert_received @git_repo, :add_zenslap_remote, &with( HEROKU_APP )
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should add zenslap as a collaborator to heroku app" do
|
87
|
+
assert_received @heroku, :add_collaborator, &with( HEROKU_APP, "admin@zenslap.me" )
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should install addon" do
|
91
|
+
assert_received @heroku, :install_addon, &with( HEROKU_APP, ADDON_NAME )
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should configure zenslap with github and heroku details" do
|
95
|
+
assert_received ZenslapClient, :configure,
|
96
|
+
&with( ZENSLAP_ID, GITHUB_REPO_OWNER, GITHUB_REPO_NAME, GITHUB_CREDENTIALS, HEROKU_APP )
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "#destroy" do
|
102
|
+
before do
|
103
|
+
@command.destroy
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should destroy heroku app" do
|
107
|
+
assert_received @heroku, :destroy, &with(HEROKU_APP)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should remove zenslap remote" do
|
111
|
+
@git_repo.should have_received(:remove_zenslap_remote)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GitRepoSpec
|
4
|
+
HEROKU_URL= "git@heroku.com:conference_hub.git"
|
5
|
+
GITHUB_URL = "git@github.com:opsb/conference_hub"
|
6
|
+
ZENSLAP_URL = "git@heroku.com:conference_hub-zenslap.git"
|
7
|
+
GITHUB_USER = "jimbo"
|
8
|
+
GITHUB_TOKEN = "df67sd6f67"
|
9
|
+
HEROKU_APP = "conference_hub"
|
10
|
+
ZENSLAP_ID = "abc"
|
11
|
+
ZENSLAP_APP = "conference_hub_ci"
|
12
|
+
ZENSLAP_GIT_REPO = "git@heroku.com:#{ZENSLAP_APP}.git"
|
13
|
+
|
14
|
+
INVALID_GITHUB_URLS = [
|
15
|
+
"git@invalidhub.com:opsb/conference_hub.git",
|
16
|
+
"https://opsb@github.com/opsbconference_hub.git",
|
17
|
+
"http://github.com.git"
|
18
|
+
]
|
19
|
+
|
20
|
+
VALID_GITHUB_URLS = [
|
21
|
+
"git@github.com:opsb/conference_hub.git",
|
22
|
+
"https://opsb@github.com/opsb/conference_hub.git",
|
23
|
+
"http://github.com/bblim-ke/we-bmo-ck.git",
|
24
|
+
"http://github.com/bblim-ke/we.bmo.ck.git",
|
25
|
+
"git@github.com:opsb/heroku-zenslap"
|
26
|
+
]
|
27
|
+
|
28
|
+
describe GitRepo do
|
29
|
+
def stub_git
|
30
|
+
origin_remote = stub(:name => "origin", :url => GITHUB_URL)
|
31
|
+
@zenslap_remote = stub(:name => "zenslap", :url => ZENSLAP_URL, :remove => nil)
|
32
|
+
@git = stub do
|
33
|
+
stubs(:remotes).returns([origin_remote])
|
34
|
+
stubs(:add_remote)
|
35
|
+
stubs(:config)
|
36
|
+
end
|
37
|
+
@git.stubs(:remote).with("zenslap").returns(@zenslap_remote)
|
38
|
+
Git.stubs(:open).returns(@git)
|
39
|
+
end
|
40
|
+
|
41
|
+
context "repository" do
|
42
|
+
before do
|
43
|
+
stub_git
|
44
|
+
@git_repo = GitRepo.new
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have github owner" do
|
48
|
+
assert_equal @git_repo.github_owner, "opsb"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should have github name" do
|
52
|
+
assert_equal @git_repo.github_name, "conference_hub"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have github_url" do
|
56
|
+
assert_equal @git_repo.github_url, GITHUB_URL
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should know if a remote exists" do
|
60
|
+
@git_repo.remote_exists?('origin').should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should know if a remote does not exist" do
|
64
|
+
@git_repo.remote_exists?('non existent remote').should be_false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should add zenslap remote" do
|
68
|
+
@git_repo.add_zenslap_remote(HEROKU_APP)
|
69
|
+
@git.should have_received(:add_remote).with("zenslap", HEROKU_URL)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should remove zenslap remote" do
|
73
|
+
@git_repo.remove_zenslap_remote
|
74
|
+
@zenslap_remote.should have_received(:remove)
|
75
|
+
end
|
76
|
+
|
77
|
+
VALID_GITHUB_URLS.each do |url|
|
78
|
+
context "with remote: #{url}" do
|
79
|
+
before do
|
80
|
+
@git = stub(:remotes => [stub(:url => url)])
|
81
|
+
Git.stubs(:open).returns(@git)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have valid github url" do
|
85
|
+
@git_repo.github_url.should == url
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should have valid github owner" do
|
89
|
+
@git_repo.github_owner.should_not be_blank
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
INVALID_GITHUB_URLS.each do |url|
|
95
|
+
it "should not accept invalid github url #{url}" do
|
96
|
+
git_repo = stub(:remotes => [stub(:url => url)])
|
97
|
+
Git.stubs(:open).returns(git_repo)
|
98
|
+
lambda {
|
99
|
+
@git_repo.github_url
|
100
|
+
}.should raise_error(ConsoleError)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "with zenslap remote" do
|
105
|
+
it "should have zenslap app" do
|
106
|
+
@git.stubs(:remote).with("zenslap").returns(stub( :name => "zenslap", :url => ZENSLAP_GIT_REPO))
|
107
|
+
assert_equal @git_repo.zenslap_app, ZENSLAP_APP
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with stored github.user" do
|
112
|
+
before do
|
113
|
+
@git_repo.stubs(:exec).with("git config --get github.user").returns(GITHUB_USER + "\n")
|
114
|
+
@git_repo.stubs(:exec).with("git config --get github.token").returns(GITHUB_TOKEN + "\n")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should have github_credentials" do
|
118
|
+
assert_equal @git_repo.github_credentials, {:login => GITHUB_USER, :token => GITHUB_TOKEN}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "missing github credentials" do
|
123
|
+
before do
|
124
|
+
@git_repo.stubs(:exec).with("git config --get github.user").returns("")
|
125
|
+
@git_repo.stubs(:exec).with("git config --get github.token").returns("")
|
126
|
+
|
127
|
+
@git_repo.stubs(:ask_for).with("your github user").returns(GITHUB_USER)
|
128
|
+
@git_repo.stubs(:ask_for).with("your github token").returns(GITHUB_TOKEN)
|
129
|
+
|
130
|
+
@git_repo.stubs(:exec).with("git config --add github.user #{GITHUB_USER}")
|
131
|
+
@git_repo.stubs(:exec).with("git config --add github.token #{GITHUB_TOKEN}")
|
132
|
+
|
133
|
+
@git_repo.github_credentials
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should have asked for a github user" do
|
137
|
+
assert_received @git_repo, :ask_for, &with("your github user")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should have asked for a github token" do
|
141
|
+
assert_received @git_repo, :ask_for, &with("your github token")
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "missing github address" do
|
146
|
+
it "should show error" do
|
147
|
+
Git.stubs( :open ).returns( stub( :remotes => [] ) )
|
148
|
+
assert_raise ConsoleError do
|
149
|
+
@git_repo.github_url
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Bundler.require(:default, :test)
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'rspec'
|
5
|
+
require 'mocha'
|
6
|
+
require 'bourne'
|
7
|
+
require 'ruby-debug'
|
8
|
+
|
9
|
+
require File.dirname(__FILE__) + '/../lib/zenslap.rb'
|
10
|
+
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.mock_with :mocha
|
14
|
+
config.include Test::Unit::Assertions
|
15
|
+
end
|
16
|
+
|
17
|
+
def with(*args)
|
18
|
+
Proc.new do |expect|
|
19
|
+
expect.with *args
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#Uncomment if you wish to see the requests and responses
|
24
|
+
# WebMock.after_request do |request_signature, response|
|
25
|
+
# puts "Request #{request_signature} was made and #{response} was returned"
|
26
|
+
# end
|
27
|
+
|
28
|
+
def show_invocations
|
29
|
+
puts
|
30
|
+
puts "Invocations"
|
31
|
+
puts "==========="
|
32
|
+
puts
|
33
|
+
Mocha::Mockery.instance.invocations.each do |invocation|
|
34
|
+
puts("#{invocation.mock.inspect}.#{invocation.method_name}( %s )\n\n" % [
|
35
|
+
invocation.arguments.map(&:inspect).join(", ")
|
36
|
+
])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/zenslap.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{zenslap}
|
8
|
+
s.version = "0.1.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["opsb"]
|
12
|
+
s.date = %q{2010-11-10}
|
13
|
+
s.default_executable = %q{zenslap}
|
14
|
+
s.description = %q{Client for zenslap continuous integration}
|
15
|
+
s.email = %q{oliver@opsb.co.uk}
|
16
|
+
s.executables = ["zenslap"]
|
17
|
+
s.files = Dir.glob("{bin,lib}/**/*") + %w(Gemfile zenslap.gemspec)
|
18
|
+
|
19
|
+
s.homepage = %q{http://github.com/opsb/zenslap-client}
|
20
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
s.rubygems_version = %q{1.3.7}
|
23
|
+
s.summary = %q{Client for zenslap continuous integration}
|
24
|
+
s.test_files = Dir.glob("spec/**/*")
|
25
|
+
s.add_dependency('heroku', ["= 1.10.10"])
|
26
|
+
s.add_dependency('opsb-git', ["= 1.2.11"])
|
27
|
+
s.add_dependency('rest-client', ["= 1.6.1"])
|
28
|
+
end
|
29
|
+
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zenslap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- opsb
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-10 00:00:00 +00:00
|
19
|
+
default_executable: zenslap
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: heroku
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 43
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 10
|
33
|
+
- 10
|
34
|
+
version: 1.10.10
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: opsb-git
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 9
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 2
|
49
|
+
- 11
|
50
|
+
version: 1.2.11
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rest-client
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - "="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 13
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 6
|
65
|
+
- 1
|
66
|
+
version: 1.6.1
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
description: Client for zenslap continuous integration
|
70
|
+
email: oliver@opsb.co.uk
|
71
|
+
executables:
|
72
|
+
- zenslap
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files: []
|
76
|
+
|
77
|
+
files:
|
78
|
+
- bin/zenslap
|
79
|
+
- lib/zenslap/client.rb
|
80
|
+
- lib/zenslap/commands.rb
|
81
|
+
- lib/zenslap/console_error.rb
|
82
|
+
- lib/zenslap/git_repo.rb
|
83
|
+
- lib/zenslap.rb
|
84
|
+
- Gemfile
|
85
|
+
- zenslap.gemspec
|
86
|
+
- spec/client_spec.rb
|
87
|
+
- spec/commands_spec.rb
|
88
|
+
- spec/git_repo_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/opsb/zenslap-client
|
92
|
+
licenses: []
|
93
|
+
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options:
|
96
|
+
- --charset=UTF-8
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.3.7
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Client for zenslap continuous integration
|
124
|
+
test_files:
|
125
|
+
- spec/client_spec.rb
|
126
|
+
- spec/commands_spec.rb
|
127
|
+
- spec/git_repo_spec.rb
|
128
|
+
- spec/spec_helper.rb
|