diff options
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/abstract_unit.rb | 14 | ||||
-rw-r--r-- | activeresource/test/connection_test.rb | 9 |
2 files changed, 22 insertions, 1 deletions
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb index db1e0b9535..615a6d9222 100644 --- a/activeresource/test/abstract_unit.rb +++ b/activeresource/test/abstract_unit.rb @@ -7,4 +7,16 @@ require 'active_resource/http_mock' $:.unshift "#{File.dirname(__FILE__)}/../test" require 'setter_trap' -ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")
\ No newline at end of file +ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log") + +# Wrap tests that use Mocha and skip if unavailable. +def uses_mocha(test_name) + unless Object.const_defined?(:Mocha) + require 'mocha' + require 'stubba' + end + yield +rescue LoadError => load_error + raise unless load_error.message =~ /mocha/i + $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." +end
\ No newline at end of file diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index 6c907614e7..8e43e451ff 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -168,6 +168,15 @@ class ConnectionTest < Test::Unit::TestCase assert_equal 200, response.code end + uses_mocha('test_timeout') do + def test_timeout + @http = mock('new Net::HTTP') + @conn.expects(:http).returns(@http) + @http.expects(:get).raises(Timeout::Error, 'execution expired') + assert_raises(ActiveResource::TimeoutError) { @conn.get('/people_timeout.xml') } + end + end + protected def assert_response_raises(klass, code) assert_raise(klass, "Expected response code #{code} to raise #{klass}") do |