Sha256: 85a73ca1e22fbf2c41b81fa145c0a06bee77a1ba4ee60b34d225e2a341782b3b

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
instapaper-0.1.0 test/test_error.rb