Permalink
Browse files

Deploy specs

  • Loading branch information...
1 parent 09fe1b3 commit 1c1cd795f96110bdd53aa4353d4b3f5f9716f4d0 @winton committed Dec 7, 2009
Showing with 104 additions and 3 deletions.
  1. +1 −1 lib/lilypad/hoptoad/xml.rb
  2. +14 −0 spec/lilypad/config_spec.rb
  3. +85 −0 spec/lilypad/hoptoad/deploy_spec.rb
  4. +1 −1 spec/lilypad_spec.rb
  5. +3 −1 spec/spec_helper.rb
@@ -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'
@@ -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
@@ -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
@@ -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',
View
@@ -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

0 comments on commit 1c1cd79

Please sign in to comment.