Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding a few more tests for #post! and #deploy!

  • Loading branch information...
commit 99f9c696748d0705df961c437a0ec7eec1ab4b6f 1 parent 1341459
@sfgeorge sfgeorge authored
View
7 test/helper.rb
@@ -3,7 +3,10 @@
require 'fakeweb'
require 'toadhopper'
-FakeWeb.allow_net_connect = true
+def reset_test_env
+ FakeWeb.clean_registry
+ FakeWeb.allow_net_connect = false
+end
def toadhopper
@toadhopper ||= Toadhopper.new(ENV['AIRBRAKE_API_KEY'] || ENV['HOPTOAD_API_KEY'] || "test api key", toadhopper_args)
@@ -16,3 +19,5 @@ def toadhopper_args
def error
begin; raise "Kaboom!"; rescue => e; e end
end
+
+reset_test_env
View
42 test/test_deploy_tracking.rb
@@ -4,12 +4,46 @@
class Toadhopper::TestDeployTracking < Test::Unit::TestCase
def test_deploy
- FakeWeb.register_uri(:post, 'http://airbrakeapp.com/deploys.txt', :status => ['200', 'Ok'])
- options = {:framework_env => 'test', :scm_revision => 3, :scm_repository => 'some/where', :username => 'phil'}
+ response_body = 'Recorded deploy of My Awesome App to test.'
+ FakeWeb.register_uri(:post, 'http://airbrakeapp.com/deploys.txt', :body => response_body, :status => ['200', 'Ok'])
response = Toadhopper('bogus key').deploy!(options)
- request = FakeWeb.last_request
+ # Check our request
expected_parameters = {'api_key' => 'bogus key', 'deploy[rails_env]' => 'test', 'deploy[scm_revision]' => '3', 'deploy[scm_repository]' => 'some/where', 'deploy[local_username]' => 'phil'}
- assert_equal 200, response.status
assert_equal expected_parameters, Hash[CGI.unescape(FakeWeb.last_request.body).split('&').map { |x| x.split('=') }]
+ # Check how we capture the mock response
+ assert_equal 200, response.status, response
+ assert_equal response_body, response.body, response
+ assert_equal [], response.errors, response
+ end
+
+ def test_deploy_integration_bad_key
+ FakeWeb.allow_net_connect = true
+ response = Toadhopper('bogus key').deploy!(options)
+ # Check how we capture the live response
+ assert_equal 403, response.status, response
+ expected_error = 'could not find a project with API key'
+ assert_match expected_error, response.body, response
+ assert_equal [], response.errors, response # @TODO populate the error here
+ end
+
+ if ENV['AIRBRAKE_API_KEY'] and not ENV['SECURE'] # @TODO Make deployments work under SSL
+ def test_deploy_integration_good_key
+ FakeWeb.allow_net_connect = true
+ opts = {:scm_repository => 'git://github.com/toolmantim/toadhopper.git', :scm_revision => 'a4aa47e5146c5a4cf84d87654efe53934b99daad'}
+ response = toadhopper.deploy!(opts)
+ # Check how we capture the live response
+ assert_equal 200, response.status, response
+ assert_match 'Recorded deploy', response.body, response
+ assert_equal [], response.errors, response
+ end
+ end
+
+ def options
+ @options ||= {:framework_env => 'test', :scm_revision => 3, :scm_repository => 'some/where', :username => 'phil'}
+ end
+
+ # This method is called automatically after every test
+ def teardown
+ reset_test_env
end
end
View
24 test/test_posting.rb
@@ -1,18 +1,42 @@
require 'helper'
class Toadhopper::TestPosting < Test::Unit::TestCase
+ def test_mock_posting
+ key = 'lolc@tz'
+ response_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<notice/>"
+ FakeWeb.register_uri(:post, 'http://airbrakeapp.com/notifier_api/v2/notices', :body => response_body, :status => ['200', 'OK'])
+ response = Toadhopper(key).post!(error)
+ # Check our request
+ assert_match key, FakeWeb.last_request.body, FakeWeb.last_request.body
+ # Check how we capture the mock response
+ assert_equal 200, response.status, response
+ assert_equal response_body, response.body, response
+ assert_equal [], response.errors, response
+ end
+
def test_posting
+ FakeWeb.allow_net_connect = true
response = Toadhopper('bogus key').post!(error)
+ # Check how we capture the live response
assert_equal 422, response.status, response
+ assert_match '</error>', response.body, response
assert_equal ['No project exists with the given API key.'], response.errors, response
end
if ENV['AIRBRAKE_API_KEY']
def test_posting_integration
+ FakeWeb.allow_net_connect = true
toadhopper.filters = "AIRBRAKE_API_KEY", "ROOT_PASSWORD"
response = toadhopper.post!(error)
+ # Check how we capture the live response
assert_equal 200, response.status, response
+ assert_match '</error-id>', response.body, response
assert_equal [], response.errors, response
end
end
+
+ # This method is called automatically after every test
+ def teardown
+ reset_test_env
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.