From 2531cb89e014b217726a205f939325987da3074e Mon Sep 17 00:00:00 2001 From: opsb Date: Sun, 7 Nov 2010 19:17:27 +0000 Subject: [PATCH] Specs are now in modules so that constants aren't shared. Added heroku_zenslap which is responsible for loading all code for plugin and autotest --- init.rb | 10 +- lib/heroku_zenslap.rb | 8 + test/heroku/commands/zenslap_test.rb | 145 ++++++++-------- test/spec_helper.rb | 7 +- test/zenslap/git_repo_test.rb | 248 ++++++++++++++------------- 5 files changed, 211 insertions(+), 207 deletions(-) create mode 100644 lib/heroku_zenslap.rb diff --git a/init.rb b/init.rb index 8eeaa32..bfbfa3f 100644 --- a/init.rb +++ b/init.rb @@ -1,11 +1,3 @@ require 'rubygems' -require File.dirname(__FILE__) + '/lib/zenslap/console_error.rb' -require File.dirname(__FILE__) + '/lib/zenslap/zenslap_client.rb' -require File.dirname(__FILE__) + '/lib/zenslap/github_client.rb' -require File.dirname(__FILE__) + '/lib/zenslap/repo.rb' -require File.dirname(__FILE__) + '/lib/heroku/commands/zenslap' - -Heroku::Command::Help.group('zenslap') do |group| - group.command 'add', 'adds continuous integration to your project' -end \ No newline at end of file +require 'lib/heroku_zenslap' \ No newline at end of file diff --git a/lib/heroku_zenslap.rb b/lib/heroku_zenslap.rb new file mode 100644 index 0000000..2b6c5f5 --- /dev/null +++ b/lib/heroku_zenslap.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/zenslap/console_error' +require File.dirname(__FILE__) + '/zenslap/zenslap_client' +require File.dirname(__FILE__) + '/zenslap/git_repo' +require File.dirname(__FILE__) + '/heroku/commands/zenslap' + +Heroku::Command::Help.group('zenslap') do |group| + group.command 'add', 'adds continuous integration to your project' +end \ No newline at end of file diff --git a/test/heroku/commands/zenslap_test.rb b/test/heroku/commands/zenslap_test.rb index 67246fe..a1d93a7 100644 --- a/test/heroku/commands/zenslap_test.rb +++ b/test/heroku/commands/zenslap_test.rb @@ -1,93 +1,96 @@ require 'spec_helper.rb' require 'heroku' -describe Heroku::Command::Zenslap do - ZENSLAP_ID = 1 - GITHUB_URL = "git@github.com:opsb/conference_hub" - GITHUB_REPO_OWNER = "opsb" - GITHUB_REPO_NAME = "conference_hub" - GITHUB_LOGIN = "jimbo" - GITHUB_TOKEN = "df67sd6f67" - GITHUB_CREDENTIALS = { :login => GITHUB_LOGIN, :token => GITHUB_TOKEN } - HEROKU_EMAIL = "jim@bob.com" - HEROKU_PASSWORD = "password" - HEROKU_APP = "conference_hub" - ADDON_NAME = "zenslap2" - - def stub_git - @git_repo = stub do - stubs(:github_url).returns(GITHUB_URL) - stubs(:github_credentials).returns(GITHUB_CREDENTIALS) - stubs(:github_owner).returns(GITHUB_REPO_OWNER) - stubs(:github_name).returns(GITHUB_REPO_NAME) - stubs(:add_zenslap_remote) - stubs(:zenslap_app).returns(HEROKU_APP) - end - GitRepo.stubs(:new).returns(@git_repo) - end +module ZenslapSpec - def stub_zenslap - ZenslapClient.stubs(:configure) - end + describe Heroku::Command::Zenslap do + ZENSLAP_ID = 1 + GITHUB_URL = "git@github.com:opsb/conference_hub" + GITHUB_REPO_OWNER = "opsb" + GITHUB_REPO_NAME = "conference_hub" + GITHUB_LOGIN = "jimbo" + GITHUB_TOKEN = "df67sd6f67" + GITHUB_CREDENTIALS = { :login => GITHUB_LOGIN, :token => GITHUB_TOKEN } + HEROKU_EMAIL = "jim@bob.com" + HEROKU_PASSWORD = "password" + HEROKU_APP = "conference_hub" + ADDON_NAME = "zenslap2" - def stub_heroku - @heroku = stub do - stubs(:user).returns(HEROKU_EMAIL) - stubs(:password).returns(HEROKU_PASSWORD) - stubs(:create).returns(HEROKU_APP) - stubs(:add_collaborator) - stubs(:install_addon) - stubs(:config_vars).returns({ "ZENSLAP_ID" => ZENSLAP_ID }) - stubs(:destroy) + def stub_git + @git_repo = stub do + stubs(:github_url).returns(GITHUB_URL) + stubs(:github_credentials).returns(GITHUB_CREDENTIALS) + stubs(:github_owner).returns(GITHUB_REPO_OWNER) + stubs(:github_name).returns(GITHUB_REPO_NAME) + stubs(:add_zenslap_remote) + stubs(:zenslap_app).returns(HEROKU_APP) + end + GitRepo.stubs(:new).returns(@git_repo) end - @command.stubs(:heroku).returns(@heroku) - end - context "zenslap" do - before do - @command = Heroku::Command::Zenslap.new nil - stub_git - stub_zenslap - stub_heroku + def stub_zenslap + ZenslapClient.stubs(:configure) end - context "#create" do + def stub_heroku + @heroku = stub do + stubs(:user).returns(HEROKU_EMAIL) + stubs(:password).returns(HEROKU_PASSWORD) + stubs(:create).returns(HEROKU_APP) + stubs(:add_collaborator) + stubs(:install_addon) + stubs(:config_vars).returns({ "ZENSLAP_ID" => ZENSLAP_ID }) + stubs(:destroy) + end + @command.stubs(:heroku).returns(@heroku) + end + context "zenslap" do before do - @command.create + @command = Heroku::Command::Zenslap.new nil + stub_git + stub_zenslap + stub_heroku end - it "should create new heroku app to be used for running tests and billing" do - assert_received @heroku, :create - end + context "#create" do - it "should add zenslap remote" do - assert_received @git_repo, :add_zenslap_remote, &with( HEROKU_APP ) - end + before do + @command.create + end - it "should add zenslap as a collaborator to heroku app" do - assert_received @heroku, :add_collaborator, &with( HEROKU_APP, "admin@zenslap.me" ) - end + it "should create new heroku app to be used for running tests and billing" do + assert_received @heroku, :create + end - it "should install addon" do - assert_received @heroku, :install_addon, &with( "conference_hub", ADDON_NAME ) - end + it "should add zenslap remote" do + assert_received @git_repo, :add_zenslap_remote, &with( HEROKU_APP ) + end - it "should configure zenslap with github and heroku details" do - assert_received ZenslapClient, :configure, - &with( ZENSLAP_ID, GITHUB_REPO_OWNER, GITHUB_REPO_NAME, GITHUB_CREDENTIALS, HEROKU_APP ) - end + it "should add zenslap as a collaborator to heroku app" do + assert_received @heroku, :add_collaborator, &with( HEROKU_APP, "admin@zenslap.me" ) + end - end + it "should install addon" do + assert_received @heroku, :install_addon, &with( "conference_hub", ADDON_NAME ) + end + + it "should configure zenslap with github and heroku details" do + assert_received ZenslapClient, :configure, + &with( ZENSLAP_ID, GITHUB_REPO_OWNER, GITHUB_REPO_NAME, GITHUB_CREDENTIALS, HEROKU_APP ) + end - context "#destroy" do - before do - @command.destroy end - it "should destroy heroku app" do - assert_received @heroku, :destroy, &with(HEROKU_APP) + context "#destroy" do + before do + @command.destroy + end + + it "should destroy heroku app" do + assert_received @heroku, :destroy, &with(HEROKU_APP) + end end - end - end -end + end + end +end \ No newline at end of file diff --git a/test/spec_helper.rb b/test/spec_helper.rb index bdf070f..52f23cd 100644 --- a/test/spec_helper.rb +++ b/test/spec_helper.rb @@ -7,11 +7,8 @@ require 'bourne' require 'ruby-debug' -require 'lib/zenslap/console_error.rb' -require 'lib/zenslap/zenslap_client.rb' -require 'lib/zenslap/git_repo.rb' -require 'lib/heroku/commands/zenslap' -require 'lib/heroku/commands/zenslap.rb' +require File.dirname(__FILE__) + '/../lib/heroku_zenslap.rb' + RSpec.configure do |config| config.mock_with :mocha diff --git a/test/zenslap/git_repo_test.rb b/test/zenslap/git_repo_test.rb index 6f1a36d..2d2bc21 100644 --- a/test/zenslap/git_repo_test.rb +++ b/test/zenslap/git_repo_test.rb @@ -1,130 +1,134 @@ require 'spec_helper' -describe GitRepo do - def stub_git - @git = stub( +module GitRepoSpec + + describe GitRepo do + def stub_git + @git = stub( :remotes => [ stub( :name => "origin", :url => GITHUB_URL) - ], - :add_remote => nil, - :config => nil - ) - - Git.stubs(:open).returns(@git) - end - - context "repository" do - HEROKU_URL= "git@heroku.com:conference_hub.git" - GITHUB_URL = "git@github.com:opsb/conference_hub" - GITHUB_USER = "jimbo" - GITHUB_TOKEN = "df67sd6f67" - HEROKU_APP = "conference_hub" - ZENSLAP_ID = "abc" - ZENSLAP_APP = "conference_hub_ci" - ZENSLAP_GIT_REPO = "git@heroku.com:#{ZENSLAP_APP}.git" - - INVALID_GITHUB_URLS = [ - "git@invalidhub.com:opsb/conference_hub.git", - "https://opsb@github.com/opsbconference_hub.git", - "http://github.com.git" - ] - - VALID_GITHUB_URLS = [ - "git@github.com:opsb/conference_hub.git", - "https://opsb@github.com/opsb/conference_hub.git", - "http://github.com/bblim-ke/we-bmo-ck.git", - "http://github.com/bblim-ke/we.bmo.ck.git" - ] - - before do - stub_git - @git_repo = GitRepo.new - end - - it "should have github owner" do - assert_equal @git_repo.github_owner, "opsb" - end - - it "should have github name" do - assert_equal @git_repo.github_name, "conference_hub" - end - - it "should have github_url" do - assert_equal @git_repo.github_url, GITHUB_URL - end - - it "should add zenslap remote" do - @git_repo.add_zenslap_remote(HEROKU_APP) - @git.should have_received(:add_remote).with(HEROKU_APP, HEROKU_URL) - end - - VALID_GITHUB_URLS.each do |url| - it "should accept valid github url #{url}" do - git_repo = stub(:remotes => [stub(:url => url)]) - Git.stubs(:open).returns(git_repo) - assert_equal @git_repo.github_url, url - end - end - - INVALID_GITHUB_URLS.each do |url| - it "should not accept invalid github url #{url}" do - git_repo = stub(:remotes => [stub(:url => url)]) - Git.stubs(:open).returns(git_repo) - lambda { - @git_repo.github_url - }.should raise_error(ConsoleError) - end - end - - context "with zenslap remote" do - it "should have zenslap app" do - @git.stubs(:remote).with("zenslap").returns(stub( :name => "zenslap", :url => ZENSLAP_GIT_REPO)) - assert_equal @git_repo.zenslap_app, ZENSLAP_APP - end - end + ], + :add_remote => nil, + :config => nil + ) + + Git.stubs(:open).returns(@git) + end + + context "repository" do + HEROKU_URL= "git@heroku.com:conference_hub.git" + GITHUB_URL = "git@github.com:opsb/conference_hub" + GITHUB_USER = "jimbo" + GITHUB_TOKEN = "df67sd6f67" + HEROKU_APP = "conference_hub" + ZENSLAP_ID = "abc" + ZENSLAP_APP = "conference_hub_ci" + ZENSLAP_GIT_REPO = "git@heroku.com:#{ZENSLAP_APP}.git" + + INVALID_GITHUB_URLS = [ + "git@invalidhub.com:opsb/conference_hub.git", + "https://opsb@github.com/opsbconference_hub.git", + "http://github.com.git" + ] + + VALID_GITHUB_URLS = [ + "git@github.com:opsb/conference_hub.git", + "https://opsb@github.com/opsb/conference_hub.git", + "http://github.com/bblim-ke/we-bmo-ck.git", + "http://github.com/bblim-ke/we.bmo.ck.git" + ] + + before do + stub_git + @git_repo = GitRepo.new + end + + it "should have github owner" do + assert_equal @git_repo.github_owner, "opsb" + end + + it "should have github name" do + assert_equal @git_repo.github_name, "conference_hub" + end + + it "should have github_url" do + assert_equal @git_repo.github_url, GITHUB_URL + end + + it "should add zenslap remote" do + @git_repo.add_zenslap_remote(HEROKU_APP) + @git.should have_received(:add_remote).with(HEROKU_APP, HEROKU_URL) + end + + VALID_GITHUB_URLS.each do |url| + it "should accept valid github url #{url}" do + git_repo = stub(:remotes => [stub(:url => url)]) + Git.stubs(:open).returns(git_repo) + assert_equal @git_repo.github_url, url + end + end + + INVALID_GITHUB_URLS.each do |url| + it "should not accept invalid github url #{url}" do + git_repo = stub(:remotes => [stub(:url => url)]) + Git.stubs(:open).returns(git_repo) + lambda { + @git_repo.github_url + }.should raise_error(ConsoleError) + end + end + + context "with zenslap remote" do + it "should have zenslap app" do + @git.stubs(:remote).with("zenslap").returns(stub( :name => "zenslap", :url => ZENSLAP_GIT_REPO)) + assert_equal @git_repo.zenslap_app, ZENSLAP_APP + end + end + + context "with stored github.user" do + before do + @git_repo.stubs(:exec).with("git config --get github.user").returns(GITHUB_USER + "\n") + @git_repo.stubs(:exec).with("git config --get github.token").returns(GITHUB_TOKEN + "\n") + end + + it "should have github_credentials" do + assert_equal @git_repo.github_credentials, {:login => GITHUB_USER, :token => GITHUB_TOKEN} + end + end + + context "missing github credentials" do + before do + @git_repo.stubs(:exec).with("git config --get github.user").returns("") + @git_repo.stubs(:exec).with("git config --get github.token").returns("") + + @git_repo.stubs(:ask_for).with("your github user").returns(GITHUB_USER) + @git_repo.stubs(:ask_for).with("your github token").returns(GITHUB_TOKEN) + + @git_repo.stubs(:exec).with("git config --add github.user #{GITHUB_USER}") + @git_repo.stubs(:exec).with("git config --add github.token #{GITHUB_TOKEN}") + + @git_repo.github_credentials + end + + it "should have asked for a github user" do + assert_received @git_repo, :ask_for, &with("your github user") + end + + it "should have asked for a github token" do + assert_received @git_repo, :ask_for, &with("your github token") + end + end + + context "missing github address" do + it "should show error" do + Git.stubs( :open ).returns( stub( :remotes => [] ) ) + assert_raise ConsoleError do + @git_repo.github_url + end + end + end - context "with stored github.user" do - before do - @git_repo.stubs(:exec).with("git config --get github.user").returns(GITHUB_USER + "\n") - @git_repo.stubs(:exec).with("git config --get github.token").returns(GITHUB_TOKEN + "\n") - end - - it "should have github_credentials" do - assert_equal @git_repo.github_credentials, {:login => GITHUB_USER, :token => GITHUB_TOKEN} - end - end - - context "missing github credentials" do - before do - @git_repo.stubs(:exec).with("git config --get github.user").returns("") - @git_repo.stubs(:exec).with("git config --get github.token").returns("") - - @git_repo.stubs(:ask_for).with("your github user").returns(GITHUB_USER) - @git_repo.stubs(:ask_for).with("your github token").returns(GITHUB_TOKEN) - - @git_repo.stubs(:exec).with("git config --add github.user #{GITHUB_USER}") - @git_repo.stubs(:exec).with("git config --add github.token #{GITHUB_TOKEN}") - - @git_repo.github_credentials - end - - it "should have asked for a github user" do - assert_received @git_repo, :ask_for, &with("your github user") - end - - it "should have asked for a github token" do - assert_received @git_repo, :ask_for, &with("your github token") - end - end - - context "missing github address" do - it "should show error" do - Git.stubs( :open ).returns( stub( :remotes => [] ) ) - assert_raise ConsoleError do - @git_repo.github_url end end - end - end -end \ No newline at end of file + end \ No newline at end of file