Skip to content

Commit

Permalink
Deploy specs
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Dec 7, 2009
1 parent 09fe1b3 commit 1c1cd79
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/lilypad/hoptoad/xml.rb
Expand Up @@ -10,7 +10,7 @@ def build(backtrace, env, exception, params, request_path)
xml = ::Builder::XmlMarkup.new
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
xml.notice :version => '2.0.0' do |n|
n.tag! 'api-key', api_key
n.tag! 'api-key', api_key(env, exception)
n.notifier do |n|
n.name 'Lilypad'
n.url 'http://github.com/winton/lilypad'
Expand Down
14 changes: 14 additions & 0 deletions spec/lilypad/config_spec.rb
Expand Up @@ -42,4 +42,18 @@
Lilypad::Config.should_receive(:require).with(adapter)
Lilypad::Config.sinatra
end

describe :Methods do

include Lilypad::Config::Methods

it "should provide an api_key method" do
Lilypad::Config.api_key 'api_key'
api_key.should == 'api_key'
Lilypad::Config.api_key { |env, e| [ env, e ].join '_' }
api_key.should == 'api_key' # api string takes precedence even when block configured
Lilypad::Config.class_eval { @api_key = nil }
api_key('api_key', 'block').should == 'api_key_block' # string is nil, now use the block
end
end
end
85 changes: 85 additions & 0 deletions spec/lilypad/hoptoad/deploy_spec.rb
@@ -0,0 +1,85 @@
require File.expand_path("#{File.dirname __FILE__}/../../spec_helper")

describe Lilypad::Hoptoad::Deploy do

before(:each) do
stub_net_http
@options = {
:username => 'username',
:environment => 'environment',
:revision => 'revision',
:repository => 'repository'
}
@instance = Lilypad::Hoptoad::Deploy.new(@options)
end

describe :initialize do

after(:each) do
@instance.send(:initialize, @options)
end

it "should call the post method" do
@instance.should_receive(:post)
end

it "should log the event" do
@instance.should_receive(:log).with(:debug, @http_ok)
end

it "should return the success status" do
@instance.should_receive(:success?)
end
end

describe :params do

before(:each) do
Lilypad { api_key '' }
end

it "should return parameters for the Hoptoad request" do
@instance.send(:params).should == {
'api_key' => '',
'deploy[local_username]' => @options[:username],
'deploy[rails_env]' => @options[:environment],
'deploy[scm_revision]' => @options[:revision],
'deploy[scm_repository]' => @options[:repository]
}
end
end

describe :post do

before(:each) do
URI.stub!(:parse).and_return('uri')
@instance.stub!(:params).and_return('params')
end

after(:each) do
@instance.send(:post)
end

it "should parse the URI" do
URI.should_receive(:parse).with(Lilypad::Config.deploy_url)
end

it "should post the form using the URI and params method" do
@instance.should_receive(:params)
Net::HTTP.should_receive(:post_form).with('uri', 'params')
end
end

describe :success? do

it "should make sure the response's superclass equals Net::HTTPSuccess" do
Net::HTTP.stub!(:post_form).and_return(nil)
@instance.send(:initialize, @options)
@instance.send(:success?).should == false

Net::HTTP.stub!(:post_form).and_return(@http_ok)
@instance.send(:initialize, @options)
@instance.send(:success?).should == true
end
end
end
2 changes: 1 addition & 1 deletion spec/lilypad_spec.rb
Expand Up @@ -65,7 +65,7 @@
end

it "should provide a deploy method" do
Net::HTTP.should_receive(:post_form).and_return(Net::HTTPOK.new(nil, nil, nil))
Net::HTTP.should_receive(:post_form)
Lilypad.deploy(
:username => 't1',
:environment => 't2',
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -28,11 +28,13 @@ def debug(object)
end

def stub_net_http
@http_ok = Net::HTTPOK.new(nil, nil, nil)
@http = mock(:http)
@http.stub!(:read_timeout=)
@http.stub!(:open_timeout=)
@http.stub!(:post).and_return Net::HTTPOK.new(nil, nil, nil)
@http.stub!(:post).and_return @http_ok
Net::HTTP.stub!(:start).and_yield(@http)
Net::HTTP.stub!(:post_form).and_return(@http_ok)
end

def validate_xml
Expand Down

0 comments on commit 1c1cd79

Please sign in to comment.