Module: Ebayr::TestHelper

Defined in:
lib/ebayr/test_helper.rb

Constant Summary collapse

@@success =
Ebayr.xml(:Ack => "Success")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/ebayr/test_helper.rb', line 6

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

Instance Method Details

#stub_ebay_call!(call, content, &block) ⇒ Object

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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ebayr/test_helper.rb', line 23

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