carousel-ruby-api 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/.travis.yml +1 -8
- data/README.md +3 -2
- data/carousel.gemspec +4 -2
- data/lib/carousel/client.rb +11 -2
- data/lib/carousel/order.rb +1 -1
- data/lib/carousel/response.rb +18 -6
- data/lib/carousel/version.rb +1 -1
- data/spec/fixtures/error_order_response.xml +7 -0
- data/spec/fixtures/inventory_request.xml +5 -0
- data/spec/fixtures/success_inventory_response.xml +21 -0
- data/spec/fixtures/success_order_response.xml +7 -0
- data/spec/fixtures/test_address_builder.xml +8 -0
- data/spec/fixtures/test_build_user.xml +3 -0
- data/spec/fixtures/test_line_items.xml +6 -0
- data/spec/fixtures/test_order.xml +29 -0
- data/spec/fixtures/test_request.xml +4 -0
- data/spec/fixtures/test_shipping_address_builder.xml +8 -0
- data/spec/lib/client_spec.rb +246 -50
- data/spec/lib/country_spec.rb +18 -0
- data/spec/lib/inventory_spec.rb +13 -0
- data/spec/lib/order_spec.rb +23 -18
- data/spec/lib/request_spec.rb +27 -0
- data/spec/lib/response_spec.rb +69 -0
- data/spec/lib/shipping_spec.rb +16 -0
- data/spec/lib/tracking_spec.rb +40 -0
- data/spec/logs/spec.log +0 -0
- data/spec/spec_helper.rb +180 -120
- metadata +80 -20
- data/spec/lib/soap_spec.rb +0 -39
data/spec/lib/order_spec.rb
CHANGED
@@ -1,34 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Carousel::Order do
|
4
|
-
|
5
|
-
|
6
|
-
@client = Carousel::Client.new("the_username", "the_password")
|
7
|
-
@order_client = Carousel::Order.new(@client)
|
8
|
-
@xml = Builder::XmlMarkup.new
|
9
|
-
end
|
4
|
+
let(:client) { Carousel::Client.new("the_username", "the_password") }
|
5
|
+
let(:order_request) { Carousel::Order.new(client) }
|
10
6
|
|
11
7
|
describe '#build_order_request' do
|
12
|
-
it '
|
13
|
-
|
14
|
-
@client.type.should == "new_order_entry"
|
15
|
-
request_body = xml_order_request_string(order_hash)
|
16
|
-
response.should == xml_string("new_order_entry", request_body)
|
8
|
+
it 'builds an xml file based on the order' do
|
9
|
+
expect(order_request.build_order_request(order_hash)).to eq(read_xml(:test_order))
|
17
10
|
end
|
18
11
|
end
|
19
12
|
|
20
13
|
describe 'private#build_address' do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
before do
|
15
|
+
@xml = ::Builder::XmlMarkup.new :indent => 2
|
16
|
+
@xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'given a billing address' do
|
20
|
+
it 'adds the address tags with the "inv" prefix' do
|
21
|
+
expect(order_request.send(:build_address, @xml, address_hash, :billing)).to eq(read_xml(:test_shipping_address_builder))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context 'given any other address' do
|
25
|
+
it 'adds the address tags to the xml file' do
|
26
|
+
expect(order_request.send(:build_address, @xml, address_hash, "shipping")).to eq(read_xml(:test_address_builder))
|
27
|
+
end
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
31
|
describe 'private#build_line_items' do
|
29
|
-
it '
|
30
|
-
|
31
|
-
|
32
|
+
it 'adds the line_items tags to the xml file under orderline' do
|
33
|
+
xml = ::Builder::XmlMarkup.new :indent => 2
|
34
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
35
|
+
order_request.send(:build_line_items, xml, order_hash)
|
36
|
+
expect(xml.target!).to eq(read_xml(:test_line_items))
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Carousel::Request do
|
4
|
+
|
5
|
+
let(:client) { Carousel::Client.new("the_username", "the_password") }
|
6
|
+
let(:request) { Carousel::Request.new(client) }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'sets the client' do
|
10
|
+
expect(request.instance_variable_get(:@client)).to eq(client)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#construct_xml' do
|
15
|
+
it 'creates xml with a given block' do
|
16
|
+
expect(request.construct_xml("order"){|xml| xml.test "test"}).to eq(read_xml(:test_request))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#build_user' do
|
21
|
+
it 'adds user and password to xml file' do
|
22
|
+
xml = ::Builder::XmlMarkup.new :indent => 2
|
23
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
24
|
+
expect(request.build_user(xml)).to eq(read_xml(:test_build_user))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Carousel::Response do
|
4
|
+
|
5
|
+
let(:raw_xml) { read_xml(:success_order_response) }
|
6
|
+
let(:raw_fail_xml) { read_xml(:error_order_response) }
|
7
|
+
let(:failed_response) { Carousel::Response.new(raw_fail_xml, "order") }
|
8
|
+
let(:successful_response) { Carousel::Response.new(raw_xml, "order") }
|
9
|
+
let(:message) { {"order"=>[{"number"=>"12345", "status"=>["OK"], "details"=>[{}]}]} }
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
it 'sets the raw_response. response, and type' do
|
13
|
+
expect(successful_response.instance_variable_get(:@raw_response)).to eq(raw_xml)
|
14
|
+
expect(successful_response.instance_variable_get(:@type)).to eq("order")
|
15
|
+
expect(successful_response.response).to eq(message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#failure?' do
|
20
|
+
context 'the status is "OK"' do
|
21
|
+
it 'returns false' do
|
22
|
+
expect(successful_response.failure?).to eq(false)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context 'the status is not "OK"' do
|
26
|
+
it 'returns true' do
|
27
|
+
expect(failed_response.failure?).to eq(true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#success?' do
|
33
|
+
context 'the status is "OK"' do
|
34
|
+
it 'returns true' do
|
35
|
+
expect(successful_response.success?).to eq(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context 'the status is not "OK"' do
|
39
|
+
it 'returns false' do
|
40
|
+
expect(failed_response.success?).to eq(false)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#status' do
|
46
|
+
context 'with a successful response' do
|
47
|
+
it 'returns succesful status code' do
|
48
|
+
expect(successful_response.status).to eq("OK")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'with an failed response' do
|
52
|
+
it 'returns a failed status code' do
|
53
|
+
expect(failed_response.status).to eq("ERROR")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#message' do
|
59
|
+
it 'returns the details from the response' do
|
60
|
+
expect(successful_response.message).to eq({})
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#parse_response' do
|
65
|
+
it 'returns the parsed xml' do
|
66
|
+
expect(successful_response.parse_response(raw_xml)).to eq(message)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Carousel::Shipping do
|
4
|
+
describe '.map' do
|
5
|
+
context 'with the code within the shipping map' do
|
6
|
+
it 'returns the value for the given key' do
|
7
|
+
expect(Carousel::Shipping.map("standard")).to eq("ECONOMY")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
context 'with the code not in the shipping map' do
|
11
|
+
it 'returns the given code' do
|
12
|
+
expect(Carousel::Shipping.map("first-class")).to eq("first-class")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Carousel::Tracking do
|
4
|
+
|
5
|
+
let(:tracking) { Carousel::Tracking.new('carousel', '123456')}
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'sets the carrier and tracking number' do
|
9
|
+
expect(tracking.instance_variable_get(:@carrier)).to eq("carousel")
|
10
|
+
expect(tracking.instance_variable_get(:@tracking_number)).to eq("123456")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#carrier_destination' do
|
15
|
+
context 'when carrier is FedEx' do
|
16
|
+
it 'returns the FedEx tracking url' do
|
17
|
+
tracking.carrier = "fedex"
|
18
|
+
expect(tracking.url).to eq("http://www.fedexuk.net/accounts/QuickTrack.aspx?consignment=123456")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context 'when carrier is Carousel' do
|
22
|
+
it 'returns the Carousel tracking url' do
|
23
|
+
expect(tracking.url).to eq("https://web.carousel.eu/easyweb/default.asp?action=clienttrack&type=Carousel&acct1=BEC01&reference=123456")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
describe '#url' do
|
28
|
+
context 'when carrier is FedEx' do
|
29
|
+
it 'returns the FedEx tracking url including the tracking number' do
|
30
|
+
tracking.carrier = "fedex"
|
31
|
+
expect(tracking.url).to eq("http://www.fedexuk.net/accounts/QuickTrack.aspx?consignment=123456")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context 'when carrier is Carousel' do
|
35
|
+
it 'returns the Carousel tracking url including the tracking number' do
|
36
|
+
expect(tracking.url).to eq("https://web.carousel.eu/easyweb/default.asp?action=clienttrack&type=Carousel&acct1=BEC01&reference=123456")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/logs/spec.log
ADDED
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,129 +1,189 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
-
# loaded once.
|
5
|
-
|
6
|
-
require 'rubygems'
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
7
3
|
require 'bundler/setup'
|
8
|
-
Bundler.require(:default, :development)
|
9
|
-
require 'hashie'
|
10
4
|
require 'carousel'
|
5
|
+
require 'rspec'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
require 'hashie'
|
8
|
+
|
9
|
+
Bundler.setup
|
10
|
+
|
11
|
+
WebMock.disable_net_connect!(:allow => "codeclimate.com")
|
11
12
|
|
12
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
13
13
|
RSpec.configure do |config|
|
14
|
-
config.
|
15
|
-
config.
|
16
|
-
config.
|
17
|
-
config.order = 'random'
|
18
|
-
end
|
19
|
-
|
20
|
-
def xml_string(type, body)
|
21
|
-
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
22
|
-
xml += "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">"
|
23
|
-
xml += xml_header_string(type)
|
24
|
-
xml += "<s:Body><#{type} xmlns=\"SII\">"
|
25
|
-
xml += xml_user_string
|
26
|
-
xml += body
|
27
|
-
xml += "</#{type}></s:Body></s:Envelope>"
|
28
|
-
end
|
29
|
-
|
30
|
-
def xml_header_string(type)
|
31
|
-
xml = "<s:Header><a:Action s:mustUnderstand=\"1\">SII/ISIIService/#{type}</a:Action>"
|
32
|
-
xml += "<a:MessageID>urn:uuid:56b55a70-8bbc-471d-94bb-9ca060bcf99f</a:MessageID>"
|
33
|
-
xml += "<a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>"
|
34
|
-
xml += "<a:To s:mustUnderstand=\"1\">https://www.carousel.us/webservices/SIIService.svc</a:To></s:Header>"
|
35
|
-
end
|
36
|
-
|
37
|
-
def xml_user_string
|
38
|
-
xml = "<user xmlns:b=\"http://schemas.datacontract.org/2004/07/\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"
|
39
|
-
xml += "<b:user_name><![CDATA[the_username]]></b:user_name><b:user_password><![CDATA[the_password]]></b:user_password></user>"
|
40
|
-
end
|
41
|
-
|
42
|
-
def xml_address_string(type, address)
|
43
|
-
full_name = "#{address[:first_name]} #{address[:last_name]}"
|
44
|
-
xml = "<b:#{type}_NAME><![CDATA[#{full_name}]]></b:#{type}_NAME>"
|
45
|
-
xml += "<b:#{type}_ADDRESS_1><![CDATA[#{address[:address1]}]]></b:#{type}_ADDRESS_1>"
|
46
|
-
xml += "<b:#{type}_ADDRESS_2><![CDATA[#{address[:address2]}]]></b:#{type}_ADDRESS_2>"
|
47
|
-
xml += "<b:#{type}_ADDRESS_3><![CDATA[#{address[:address3]}]]></b:#{type}_ADDRESS_3>"
|
48
|
-
xml += "<b:#{type}_ADDRESS_CITY>#{address[:city]}</b:#{type}_ADDRESS_CITY>"
|
49
|
-
xml += "<b:#{type}_ADDRESS_COUNTRY>#{address[:country]}</b:#{type}_ADDRESS_COUNTRY>"
|
50
|
-
xml += "<b:#{type}_ADDRESS_STATE>#{address[:state]}</b:#{type}_ADDRESS_STATE>"
|
51
|
-
xml += "<b:#{type}_ADDRESS_ZIP>#{address[:zipcode]}</b:#{type}_ADDRESS_ZIP>"
|
52
|
-
xml += "<b:#{type}_TELEPHONE>#{address[:phone]}</b:#{type}_TELEPHONE>"
|
53
|
-
end
|
54
|
-
|
55
|
-
def xml_line_items_string(order)
|
56
|
-
xml = "<b:Order_Details>"
|
57
|
-
order[:line_items].each do |line_item|
|
58
|
-
xml += "<b:Order_Detail_New>"
|
59
|
-
xml += "<b:PRICE>#{line_item[:price]}</b:PRICE>"
|
60
|
-
xml += "<b:QUANTITY>#{line_item[:quantity]}</b:QUANTITY>"
|
61
|
-
xml += "<b:SIZE>#{line_item[:size]}</b:SIZE>"
|
62
|
-
xml += "<b:sku>#{line_item[:sku]}</b:sku>"
|
63
|
-
xml += "</b:Order_Detail_New>"
|
64
|
-
end
|
65
|
-
xml += "</b:Order_Details>"
|
66
|
-
end
|
67
|
-
|
68
|
-
def xml_order_request_string(order)
|
69
|
-
xml = "<ohn xmlns:b=\"http://schemas.datacontract.org/2004/07/\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"
|
70
|
-
xml += "<b:SERVICE>90</b:SERVICE>"
|
71
|
-
xml += "<b:USER1><![CDATA[http://example.com/R123123123/invoice]]></b:USER1>"
|
72
|
-
xml += "<b:CARRIER>FEDEX</b:CARRIER>"
|
73
|
-
xml += "<b:CUSTOMER_CODE/><b:DELIVERY_GIFT_WRAP/>"
|
74
|
-
xml += "<b:DELIVERY_MESSAGE><![CDATA[Happy Birthday!]]></b:DELIVERY_MESSAGE>"
|
75
|
-
xml += "<b:EMAIL>someone@somehwere.com</b:EMAIL>"
|
76
|
-
xml += "<b:ORDER_ID>R123123123</b:ORDER_ID>"
|
77
|
-
xml += "<b:ORDER_TYPE>OO</b:ORDER_TYPE>"
|
78
|
-
xml += "<b:DELIVERY_FROM i:nil=\"true\"/><b:DELIVERY_TO i:nil=\"true\"/>"
|
79
|
-
xml += "<b:DELIVERY_ID i:nil=\"true\"/><b:FREIGHT_ACCOUNT i:nil=\"true\"/>"
|
80
|
-
xml += xml_address_string("CUSTOMER", order[:billing_address])
|
81
|
-
xml += xml_address_string("DELIVERY", order[:shipping_address])
|
82
|
-
xml += xml_line_items_string(order)
|
83
|
-
xml += "</ohn>"
|
14
|
+
config.include WebMock::API
|
15
|
+
config.before(:all, &:silence_output)
|
16
|
+
config.after(:all, &:enable_output)
|
84
17
|
end
|
85
18
|
|
86
|
-
def
|
87
|
-
{
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
19
|
+
def read_xml(type)
|
20
|
+
File.read( File.expand_path("spec/fixtures/#{type}.xml") )
|
21
|
+
end
|
22
|
+
|
23
|
+
def fixture(type)
|
24
|
+
XmlSimple.xml_in( read_xml(type) )
|
25
|
+
end
|
26
|
+
|
27
|
+
def base_url
|
28
|
+
'https://web.carousel.eu/carouselwms/default.asp?'
|
29
|
+
end
|
30
|
+
|
31
|
+
def stub_get(path)
|
32
|
+
stub_request(:get, "#{base_url}#{path}")
|
33
|
+
end
|
34
|
+
|
35
|
+
def stub_post(path)
|
36
|
+
stub_request(:post, "#{base_url}#{path}")
|
37
|
+
end
|
38
|
+
|
39
|
+
def xml_headers
|
40
|
+
{'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/xml', 'User-Agent'=>'Ruby'}
|
41
|
+
end
|
42
|
+
|
43
|
+
def json_post_headers
|
44
|
+
{
|
45
|
+
'Accept' => '*/*',
|
46
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
47
|
+
'Content-Type' => 'application/json',
|
48
|
+
'User-Agent' => 'Ruby'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def success_response
|
53
|
+
{
|
54
|
+
'Response' => {
|
55
|
+
'CallStatus' => {
|
56
|
+
'Code' => 0,
|
57
|
+
'Message' => {},
|
58
|
+
'Success' => true
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def error_product_response
|
65
|
+
{
|
66
|
+
'CallStatus' => {
|
67
|
+
'Success' => false,
|
68
|
+
'Code' => 100,
|
69
|
+
'Message' => 'Error Submitting Product Master: LJ-W-BERN-S-GW - Error. Product Code already exists.'
|
70
|
+
}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def configuration
|
75
|
+
{
|
76
|
+
supplier_code: 'Supplier1',
|
77
|
+
supplier_description: 'My Supplier',
|
78
|
+
supplier_uom: 1,
|
79
|
+
warehouses: {},
|
80
|
+
token: 'token123'
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def address_hash
|
85
|
+
{
|
86
|
+
city: 'Windsor',
|
87
|
+
country: 'GB',
|
88
|
+
first_name: 'Stephen',
|
89
|
+
last_name: 'Jones',
|
90
|
+
address1: '23 Victoria Street',
|
91
|
+
address2: '',
|
92
|
+
phone: '0123 336 6676',
|
93
|
+
zipcode: 'SL4 1HE'
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def line_items_array
|
98
|
+
[
|
119
99
|
{
|
120
|
-
|
121
|
-
quantity:
|
122
|
-
sku: "123332211",
|
123
|
-
size: "XS"
|
100
|
+
sku: 100083,
|
101
|
+
quantity: 2
|
124
102
|
}
|
125
|
-
]
|
126
|
-
|
127
|
-
|
128
|
-
|
103
|
+
]
|
104
|
+
end
|
105
|
+
|
106
|
+
def company_hash
|
107
|
+
{
|
108
|
+
code: 'IND001',
|
109
|
+
description: 'Indigina'
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
def order_hash
|
114
|
+
{
|
115
|
+
number: 123456,
|
116
|
+
email: 'stephen.jones@gmail.com',
|
117
|
+
shipping_address: address_hash,
|
118
|
+
billing_address: address_hash,
|
119
|
+
line_items: line_items_array,
|
120
|
+
warehouse: 'DC123',
|
121
|
+
date: '2013-12-12',
|
122
|
+
shipping_method: 'standard'
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
def company_order_hash
|
127
|
+
order_hash.merge(company: company_hash)
|
128
|
+
end
|
129
|
+
|
130
|
+
def company_address_hash
|
131
|
+
{
|
132
|
+
city: 'High Wycombe',
|
133
|
+
country: 'GB',
|
134
|
+
country_name: 'Buckinghamshire',
|
135
|
+
address1: 'The Farthings',
|
136
|
+
address2: 'Sandpits Lane',
|
137
|
+
address3: 'Beaconsfield',
|
138
|
+
zipcode: 'HP8 TTT'
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
def company_submit_hash
|
143
|
+
{
|
144
|
+
code: 123456,
|
145
|
+
description: 'My Test company',
|
146
|
+
address: company_address_hash
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
def fake_response
|
151
|
+
Hashie::Mash.new( {body: read_xml(:success_order_response)} )
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
public
|
156
|
+
# Redirects stderr and stout to /log/spec.log
|
157
|
+
def silence_output
|
158
|
+
# Store the original stderr and stdout in order to restore them later
|
159
|
+
@original_stderr = $stderr
|
160
|
+
@original_stdout = $stdout
|
161
|
+
|
162
|
+
# Redirect stderr and stdout
|
163
|
+
$stderr = File.new(log_file, 'w')
|
164
|
+
$stdout = File.new(log_file, 'w')
|
165
|
+
end
|
166
|
+
|
167
|
+
def log_file
|
168
|
+
File.join(File.dirname(__FILE__), 'logs', 'spec.log')
|
169
|
+
end
|
170
|
+
|
171
|
+
# Replace stderr and stdout so anything else is output correctly
|
172
|
+
def enable_output
|
173
|
+
$stderr = @original_stderr
|
174
|
+
$stdout = @original_stdout
|
175
|
+
@original_stderr = nil
|
176
|
+
@original_stdout = nil
|
177
|
+
`rm #{log_file} && touch #{log_file}`
|
178
|
+
end
|
179
|
+
|
180
|
+
def capture_stdout(&block)
|
181
|
+
original_stdout = $stdout
|
182
|
+
$stdout = fake = StringIO.new
|
183
|
+
begin
|
184
|
+
yield
|
185
|
+
ensure
|
186
|
+
$stdout = original_stdout
|
187
|
+
end
|
188
|
+
fake.string
|
129
189
|
end
|