Sha256: 46daf9cd3e97d9f6af314fe71f8e4326fcef3d42019465abc06c69e05fc7f0eb

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

if respond_to?(:require_relative, true)
  require_relative 'common'
else
  require File.dirname(__FILE__) + '/common'
end

require 'json'

describe RestGraph do
  before do
    @id    = lambda{ |obj| obj }
    @error = '{"error":{"type":"Exception","message":"(#2500)"}}'
    @error_hash = JSON.parse(@error)

    reset_webmock
    stub_request(:get, 'https://graph.facebook.com/me').
      to_return(:body => @error)
  end

  it 'would call error_handler if error occurred' do
    RestGraph.new(:error_handler => @id).get('me').should == @error_hash
  end

  it 'would raise ::RestGraph::Error in default error_handler' do
    begin
      RestGraph.new.get('me')
    rescue ::RestGraph::Error => e
      e.message.should == @error_hash
    end
  end
end

describe RestGraph do
  before do
    reset_webmock
  end

  after do
    RR.verify
  end

  it 'would log whenever doing network request' do
    stub_request(:get, 'https://graph.facebook.com/me').
      to_return(:body => '{}')

    mock(Time).now{ 666 }
    mock(Time).now{ 999 }

    logger = []
    rg = RestGraph.new(:log_handler => lambda{ |d, u| logger << [d, u] })
    rg.get('me')

    logger.last.should == [333, 'https://graph.facebook.com/me']
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-graph-1.4.0 test/test_handler.rb
rest-graph-1.3.0 test/test_handler.rb
rest-graph-1.2.1 test/test_handler.rb
rest-graph-1.2.0 test/test_handler.rb