Sha256: 8c9fe6229d6aadba6cbcfa4a1f01fbf130c0245b8e10c99d6ff8e06474a8500c

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'rubygems'
require 'fakeweb'

require 'simple_currency'
require 'rspec'
require 'rspec/autorun'

module HelperMethods
  def fixture(name)
    File.read(File.dirname(__FILE__) +  "/support/#{name}")
  end

  def mock_xurrency_api(from_currency, to_currency, amount, result, options = {})
    args = [from_currency, to_currency, amount]

    response = "{\"result\":{\"value\":#{result},\"target\":\"#{to_currency}\",\"base\":\"#{from_currency}\"},\"status\":\"ok\"}"

    response = "{\"message\":\"#{options[:fail_with]}\", \"status\":\"fail\"\}" if options[:fail_with]

    FakeWeb.register_uri(:get, "http://xurrency.com/api/#{args.join('/')}", :body => response)
  end

  def mock_xavier_api(date, options = {})
    date = date.send(:to_date)
    args = [date.year, date.month.to_s.rjust(2, '0'), date.day.to_s.rjust(2,'0')]

    response = {:body => fixture("xavier.xml")}
    response = {:body => "No exchange rate available", :status => ["404", "Not Found"]} if options[:fail]

    FakeWeb.register_uri(:get, "http://api.finance.xaviermedia.com/api/#{args.join('/')}.xml", response)
  end

end

RSpec.configuration.include(HelperMethods)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_currency-1.1.2 spec/spec_helper.rb
simple_currency-1.1.1 spec/spec_helper.rb