require File.dirname(__FILE__) + '/test_helper.rb' class TestError < Test::Unit::TestCase include Instapaper::Exceptions include Instapaper::Response include Instapaper::Request def setup @username = "instapaper-rubygem" @password = @username @instapaper_a = Instapaper::Base.new(@username,@password) @instapaper_b = Instapaper::Base.new("") end def test_abstract_class req = AbstractRequest.new assert_raise(AbstractRequestException) { @instapaper_a.send_request(req) } end def test_add_url_blank assert_raise(InvalidRequestDetailsException) {@instapaper_a.add("")} end def test_authenticate_blank assert_raise(InvalidRequestDetailsException) {@instapaper_b.authenticate} end def test_authentication_request_errors req = AuthenticationRequest.new("") err = req.post_data(false) assert_instance_of(RequestErrors, err) assert(!err.valid?) assert_equal(1,err.length) assert_instance_of(RequestError,err.first) assert_equal(:validate_auth,err.first.type) end def test_add_request_errors req = AddURLRequest.new({},@username,@password) err = req.post_data(false) assert_instance_of(RequestErrors, err) assert(!err.valid?) assert_equal(1,err.length) assert_instance_of(RequestError,err.first) assert_equal(:validate_url,err.first.type) end def test_auth_add_request_errors req = AddURLRequest.new({},"","") err = req.post_data(false) assert_instance_of(RequestErrors, err) assert(!err.valid?) assert_equal(2,err.length) assert_instance_of(RequestError,err.first) assert_equal(:validate_auth,err.first.type) assert_instance_of(RequestError,err.last) assert_equal(:validate_url,err.last.type) end def test_add_request_invalid_input_errors assert_raise(InvalidRequestDetailsException) { @instapaper_a.add("","foo") } end end