module Ebayr::TestHelper

Public Class Methods

included(mod) click to toggle source
# File lib/ebayr/test_helper.rb, line 5
def self.included(mod)
  begin
    require 'fakeweb' unless const_defined?(:FakeWeb)
  rescue LoadError
    throw "Couldn't load fakeweb! Is it in your Gemfile?"
  end
end

Public Instance Methods

stub_ebay_call!(call, content) { || ... } click to toggle source

Allows you to stub out the calls within the given block. For example:

def test_something
  stub_ebay_call!(:GeteBayOffficialTime, :Timestamp => "Yo") do
    assert Ebayr.call(:GeteBayOfficialTime) # => stubbed call
  end
end

This method is deprecated, and will be removed in a future release.

# File lib/ebayr/test_helper.rb, line 22
    def stub_ebay_call!(call, content, &block)
      puts <<DEPRECATION
stub_ebay_call! is deprecated, and will be removed in a future release. Please
use Ruby techniques to stub eBay calls your way. See the wiki for details.
DEPRECATION
      content = Ebayr.xml(content) unless content.is_a?(String)
      _allow_net_connect_ = FakeWeb.allow_net_connect?
      FakeWeb.allow_net_connect = false
      body = <<-XML
        <#{call}Response>
          #{Ebayr.xml(:Ack => "Success")}
          #{content}
        </#{call}Response>
      XML
      FakeWeb.register_uri(:any, Ebayr.uri, :body => body)
      yield
      FakeWeb.clean_registry
      FakeWeb.allow_net_connect = _allow_net_connect_
    end