diff options
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/abstract_unit.rb | 13 | ||||
-rw-r--r-- | activeresource/test/authorization_test.rb | 8 | ||||
-rw-r--r-- | activeresource/test/base_test.rb | 22 | ||||
-rw-r--r-- | activeresource/test/connection_test.rb | 28 | ||||
-rw-r--r-- | activeresource/test/setter_trap.rb | 5 |
5 files changed, 35 insertions, 41 deletions
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb index e612412033..0f11ea482a 100644 --- a/activeresource/test/abstract_unit.rb +++ b/activeresource/test/abstract_unit.rb @@ -1,6 +1,11 @@ +require 'rubygems' require 'test/unit' +gem 'mocha', '>= 0.9.5' +require 'mocha' + $:.unshift "#{File.dirname(__FILE__)}/../lib" +$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib" require 'active_resource' require 'active_resource/http_mock' @@ -10,17 +15,9 @@ require 'setter_trap' ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log") def uses_gem(gem_name, test_name, version = '> 0') - require 'rubygems' gem gem_name.to_s, version require gem_name.to_s yield rescue LoadError $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again." end - -# Wrap tests that use Mocha and skip if unavailable. -unless defined? uses_mocha - def uses_mocha(test_name, &block) - uses_gem('mocha', test_name, '>= 0.5.5', &block) - end -end diff --git a/activeresource/test/authorization_test.rb b/activeresource/test/authorization_test.rb index ead7f5c12f..ca25f437e3 100644 --- a/activeresource/test/authorization_test.rb +++ b/activeresource/test/authorization_test.rb @@ -107,10 +107,10 @@ class AuthorizationTest < Test::Unit::TestCase end def test_raises_invalid_request_on_unauthorized_requests - assert_raises(ActiveResource::InvalidRequestError) { @conn.post("/people/2.xml") } - assert_raises(ActiveResource::InvalidRequestError) { @conn.post("/people/2/addresses.xml") } - assert_raises(ActiveResource::InvalidRequestError) { @conn.put("/people/2.xml") } - assert_raises(ActiveResource::InvalidRequestError) { @conn.delete("/people/2.xml") } + assert_raise(ActiveResource::InvalidRequestError) { @conn.post("/people/2.xml") } + assert_raise(ActiveResource::InvalidRequestError) { @conn.post("/people/2/addresses.xml") } + assert_raise(ActiveResource::InvalidRequestError) { @conn.put("/people/2.xml") } + assert_raise(ActiveResource::InvalidRequestError) { @conn.delete("/people/2.xml") } end protected diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index e22388f4a7..6ed6f1a406 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -47,7 +47,7 @@ class BaseTest < Test::Unit::TestCase {:name => 'Milena', :children => []}]}]}.to_xml(:root => 'customer') # - resource with yaml array of strings; for ActiveRecords using serialize :bar, Array - @marty = <<-eof + @marty = <<-eof.strip <?xml version=\"1.0\" encoding=\"UTF-8\"?> <person> <id type=\"integer\">5</id> @@ -564,14 +564,14 @@ class BaseTest < Test::Unit::TestCase def test_custom_header Person.headers['key'] = 'value' - assert_raises(ActiveResource::ResourceNotFound) { Person.find(4) } + assert_raise(ActiveResource::ResourceNotFound) { Person.find(4) } ensure Person.headers.delete('key') end def test_find_by_id_not_found - assert_raises(ActiveResource::ResourceNotFound) { Person.find(99) } - assert_raises(ActiveResource::ResourceNotFound) { StreetAddress.find(1) } + assert_raise(ActiveResource::ResourceNotFound) { Person.find(99) } + assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) } end def test_find_all_by_from @@ -689,7 +689,7 @@ class BaseTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to do |mock| mock.post "/people.xml", {}, nil, 409 end - assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') } + assert_raise(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') } end def test_create_without_location @@ -726,7 +726,7 @@ class BaseTest < Test::Unit::TestCase matz.non_ar_arr = ["not", "ARes"] matz_c = matz.clone assert matz_c.new? - assert_raises(NoMethodError) {matz_c.address} + assert_raise(NoMethodError) {matz_c.address} assert_equal matz.non_ar_hash, matz_c.non_ar_hash assert_equal matz.non_ar_arr, matz_c.non_ar_arr @@ -764,7 +764,7 @@ class BaseTest < Test::Unit::TestCase mock.get "/people/2.xml", {}, @david mock.put "/people/2.xml", @default_request_headers, nil, 409 end - assert_raises(ActiveResource::ResourceConflict) { Person.find(2).save } + assert_raise(ActiveResource::ResourceConflict) { Person.find(2).save } end def test_destroy @@ -772,7 +772,7 @@ class BaseTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1.xml", {}, nil, 404 end - assert_raises(ActiveResource::ResourceNotFound) { Person.find(1).destroy } + assert_raise(ActiveResource::ResourceNotFound) { Person.find(1).destroy } end def test_destroy_with_custom_prefix @@ -780,7 +780,7 @@ class BaseTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1/addresses/1.xml", {}, nil, 404 end - assert_raises(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) } + assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) } end def test_delete @@ -788,7 +788,7 @@ class BaseTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1.xml", {}, nil, 404 end - assert_raises(ActiveResource::ResourceNotFound) { Person.find(1) } + assert_raise(ActiveResource::ResourceNotFound) { Person.find(1) } end def test_delete_with_custom_prefix @@ -796,7 +796,7 @@ class BaseTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1/addresses/1.xml", {}, nil, 404 end - assert_raises(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) } + assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) } end def test_exists diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index 84bcf69219..831fbc4003 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -168,21 +168,19 @@ class ConnectionTest < Test::Unit::TestCase assert_equal 200, response.code end - uses_mocha('test_timeout, test_accept_http_header') do - def test_timeout - @http = mock('new Net::HTTP') - @conn.expects(:http).returns(@http) - @http.expects(:get).raises(Timeout::Error, 'execution expired') - assert_raise(ActiveResource::TimeoutError) { @conn.get('/people_timeout.xml') } - end - - def test_accept_http_header - @http = mock('new Net::HTTP') - @conn.expects(:http).returns(@http) - path = '/people/1.xml' - @http.expects(:get).with(path, {'Accept' => 'application/xhtml+xml'}).returns(ActiveResource::Response.new(@matz, 200, {'Content-Type' => 'text/xhtml'})) - assert_nothing_raised(Mocha::ExpectationError) { @conn.get(path, {'Accept' => 'application/xhtml+xml'}) } - end + def test_timeout + @http = mock('new Net::HTTP') + @conn.expects(:http).returns(@http) + @http.expects(:get).raises(Timeout::Error, 'execution expired') + assert_raise(ActiveResource::TimeoutError) { @conn.get('/people_timeout.xml') } + end + + def test_accept_http_header + @http = mock('new Net::HTTP') + @conn.expects(:http).returns(@http) + path = '/people/1.xml' + @http.expects(:get).with(path, {'Accept' => 'application/xhtml+xml'}).returns(ActiveResource::Response.new(@matz, 200, {'Content-Type' => 'text/xhtml'})) + assert_nothing_raised(Mocha::ExpectationError) { @conn.get(path, {'Accept' => 'application/xhtml+xml'}) } end protected diff --git a/activeresource/test/setter_trap.rb b/activeresource/test/setter_trap.rb index 9a899b0fa0..7cfd9ca111 100644 --- a/activeresource/test/setter_trap.rb +++ b/activeresource/test/setter_trap.rb @@ -1,9 +1,8 @@ class SetterTrap < ActiveSupport::BasicObject class << self def rollback_sets(obj) - returning yield(setter_trap = new(obj)) do - setter_trap.rollback_sets - end + trapped = new(obj) + yield(trapped).tap { trapped.rollback_sets } end end |