Skip to content

Commit

Permalink
Restructured the spec directory in order to split up the spec_helper …
Browse files Browse the repository at this point in the history
…into provider-specific helpers, as well as some general cleanup of configuration and response files.
  • Loading branch information
laserlemon authored and binarylogic committed Aug 21, 2010
1 parent 0ec5fd1 commit b8dfd52
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,4 +3,4 @@
coverage
rdoc
pkg
spec/fedex_credentials.yml
spec/*_credentials.yml
File renamed without changes.
3 changes: 3 additions & 0 deletions spec/config/ups_credentials.example.yml
@@ -0,0 +1,3 @@
key: your key
password: your password
account: your account username
2 changes: 1 addition & 1 deletion spec/fedex/cancel_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Track" do
it "should cancel the shipment" do
Expand Down
2 changes: 1 addition & 1 deletion spec/fedex/error_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Error" do
it "should handle blank response errors" do
Expand Down
2 changes: 1 addition & 1 deletion spec/fedex/rate_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Rate" do
it "should rate the shipment" do
Expand Down
2 changes: 1 addition & 1 deletion spec/fedex/request_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Attributes" do
it "should convert full country names to country codes" do
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion spec/fedex/service_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Service" do
it "should not hit fedex until needed" do
Expand Down
2 changes: 1 addition & 1 deletion spec/fedex/ship_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Ship" do
before(:each) do
Expand Down
2 changes: 1 addition & 1 deletion spec/fedex/signature_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Signature" do
it "should return an image of the signature" do
Expand Down
83 changes: 83 additions & 0 deletions spec/fedex/spec_helper.rb
@@ -0,0 +1,83 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

Shippinglogic::FedEx.options[:test] = true

Spec::Runner.configure do |config|
config.before(:each) do
FakeWeb.clean_registry

if File.exists?("#{SPEC_ROOT}/fedex/responses/_new.xml")
raise "You have a new response in your response folder, you need to rename this before we can continue testing."
end
end

def new_fedex
Shippinglogic::FedEx.new(*fedex_credentials.values_at("key", "password", "account", "meter"))
end

def fedex_credentials
return @fedex_credentials if defined?(@fedex_credentials)

fedex_credentials_path = "#{SPEC_ROOT}/config/fedex_credentials.yml"

unless File.exists?(fedex_credentials_path)
raise "You need to add your own FedEx test credentials in spec/config/fedex_credentials.yml. See spec/config/fedex_credentials.example.yml for an example."
end

@fedex_credentials = YAML.load(File.read(fedex_credentials_path))
end

def fedex_tracking_number
"077973360403984"
end

def fedex_shipper
{
:shipper_name => "Name",
:shipper_title => "Title",
:shipper_company_name => "Company",
:shipper_phone_number => "2222222222",
:shipper_email => "a@a.com",
:shipper_streets => "260 Broadway",
:shipper_city => "New York",
:shipper_state => "NY",
:shipper_postal_code => "10007",
:shipper_country => "US"
}
end

def fedex_recipient
{
:recipient_name => "Name",
:recipient_title => "Title",
:recipient_department => "Department",
:recipient_company_name => "Dallas City Hall",
:recipient_phone_number => "2222222222",
:recipient_email => "a@a.com",
:recipient_streets => "1500 Marilla Street",
:recipient_city => "Dallas",
:recipient_state => "TX",
:recipient_postal_code => "75201",
:recipient_country => "US"
}
end

def fedex_package
{
:package_weight => 2,
:package_length => 2,
:package_width => 2,
:package_height => 2
}
end

def use_response(key, options = {})
path = "#{SPEC_ROOT}/fedex/responses/#{key}.xml"
if File.exists?(path)
options[:content_type] ||= "text/xml"
options[:body] ||= File.read(path)
url = Shippinglogic::FedEx.options[:test_url]
FakeWeb.register_uri(:post, url, options)
end
end
end
2 changes: 1 addition & 1 deletion spec/fedex/track_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "FedEx Track" do
it "should track the package" do
Expand Down
89 changes: 3 additions & 86 deletions spec/spec_helper.rb
@@ -1,95 +1,12 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'rubygems'
require 'shippinglogic'
require 'spec'
require 'spec/autorun'
begin; require 'ruby-debug'; rescue LoadError; end
require 'fakeweb'
require File.dirname(__FILE__) + "/lib/interceptor"

Shippinglogic::FedEx.options[:test] = true

Spec::Runner.configure do |config|
config.before(:each) do
FakeWeb.clean_registry

if File.exists?(File.dirname(__FILE__) + "/responses/_new.xml")
raise "You have a new response in your response folder, you need to rename this before we can continue testing."
end
end

def new_fedex
Shippinglogic::FedEx.new(
fedex_credentials["key"],
fedex_credentials["password"],
fedex_credentials["account"],
fedex_credentials["meter"]
)
end

def fedex_credentials
return @fedex_credentials if defined?(@fedex_credentials)

fedex_credentials_path = File.dirname(__FILE__) + "/fedex_credentials.yml"

if !File.exists?(fedex_credentials_path)
raise "You need to add your own FedEx test credentials in spec/fedex_credentials.yml. See spec/fedex_credentials.example.yml for an example."
end

@fedex_credentials = YAML.load(File.read(fedex_credentials_path))
end

def fedex_tracking_number
"077973360403984"
end

def fedex_shipper
{
:shipper_name => "Name",
:shipper_title => "Title",
:shipper_company_name => "Company",
:shipper_phone_number => "2222222222",
:shipper_email => "a@a.com",
:shipper_streets => "260 Broadway",
:shipper_city => "New York",
:shipper_state => "NY",
:shipper_postal_code => "10007",
:shipper_country => "US"
}
end

def fedex_recipient
{
:recipient_name => "Name",
:recipient_title => "Title",
:recipient_department => "Department",
:recipient_company_name => "Dallas City Hall",
:recipient_phone_number => "2222222222",
:recipient_email => "a@a.com",
:recipient_streets => "1500 Marilla Street",
:recipient_city => "Dallas",
:recipient_state => "TX",
:recipient_postal_code => "75201",
:recipient_country => "US"
}
end

def fedex_package
{
:package_weight => 2,
:package_length => 2,
:package_width => 2,
:package_height => 2
}
end

def use_response(key, options = {})
path = File.dirname(__FILE__) + "/responses/#{key}.xml"
if File.exists?(path)
options[:content_type] ||= "text/xml"
options[:body] ||= File.read(path)
FakeWeb.register_uri(:post, "https://gatewaybeta.fedex.com:443/xml", options)
end
end
end
SPEC_ROOT = File.dirname(__FILE__).freeze
require SPEC_ROOT + "/lib/interceptor"

0 comments on commit b8dfd52

Please sign in to comment.