Skip to content

Commit d97db22

Browse files
committed
Use logger instead of puts and default to loglevel ERROR when runnings specs.
1 parent 0252548 commit d97db22

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

spec/sample_code_spec.rb

+22-23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
include AuthorizeNet::API
1515

1616
describe "SampleCode Testing" do
17+
# LOGLEVEL=INFO rspec ./spec/sample_code_spec.rb # INFO for verbose output, otherwise defaults to ERROR only.
18+
def logger
19+
ENV['LOGLEVEL'] ||= 'ERROR'
20+
@logger ||= Logger.new(STDOUT).tap { |logger| logger.level = Logger.const_get(ENV['LOGLEVEL']) }
21+
end
1722

1823
before :all do
1924
begin
@@ -22,16 +27,10 @@
2227
item = item[0..-4]
2328

2429
if item != specpath + 'sample_code_spec'
25-
puts "working on: #{item}"
30+
logger.info "requiring #{item}"
2631
require item
2732
end
2833
end
29-
# Dir.glob("./sample-code-ruby/RecurringBilling/*") do |item| # note one extra "*"
30-
# next if item == '.' or item == '..'
31-
# item = item[0..-4]
32-
# puts "working on: #{item}"
33-
# require item
34-
# end
3534

3635
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
3736
@api_key = creds['api_transaction_key']
@@ -40,7 +39,7 @@
4039
rescue Errno::ENOENT => e
4140
@api_key = "TEST"
4241
@api_login = "TEST"
43-
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
42+
logger.warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
4443
end
4544
end
4645
def validate_response(response= nil)
@@ -51,7 +50,7 @@ def validate_response(response= nil)
5150
end
5251

5352
it "should be able to run all Customer Profile sample code" do
54-
puts "START - Customer Profiles"
53+
logger.info "START - Customer Profiles"
5554

5655
response = create_customer_profile()
5756
validate_response(response)
@@ -112,7 +111,7 @@ def validate_response(response= nil)
112111
end
113112

114113
it "should be able to run all Recurring Billing sample code" do
115-
puts "START - Recurring Billing"
114+
logger.info "START - Recurring Billing"
116115

117116
response = create_Subscription()
118117
validate_response(response)
@@ -124,9 +123,9 @@ def validate_response(response= nil)
124123
shipping_response = create_customer_shipping_address(profile_response.customerProfileId)
125124

126125
#waiting for creating customer profile.
127-
puts "Waiting for creation of customer profile..."
126+
logger.info "Waiting for creation of customer profile..."
128127
sleep 50
129-
puts "Proceeding"
128+
logger.info "Proceeding"
130129

131130
response = create_subscription_from_customer_profile(profile_response.customerProfileId, payment_response.customerPaymentProfileId, shipping_response.customerAddressId)
132131
validate_response(response)
@@ -155,7 +154,7 @@ def validate_response(response= nil)
155154

156155

157156
it "should be able to run all Payment Transaction sample code" do
158-
puts "START - Payment Transactions"
157+
logger.info "START - Payment Transactions"
159158

160159
response = authorize_credit_card()
161160
validate_response(response)
@@ -209,34 +208,34 @@ def validate_response(response= nil)
209208

210209

211210
it "should be able to run all PayPal Express Checkout sample code" do
212-
puts "START - PayPal Express Checkout"
211+
logger.info "START - PayPal Express Checkout"
213212

214-
puts "TEST - authorization and capture"
213+
logger.info "TEST - authorization and capture"
215214
response = authorization_and_capture()
216215
validate_response(response)
217216

218217
# response = authorization_and_capture_continued()
219218
# validate_response(response)
220219

221-
puts "TEST - authorization only"
220+
logger.info "TEST - authorization only"
222221
response = authorization_only()
223222
validate_response(response)
224223

225224
authTransId = response.transactionResponse.transId
226-
puts "TransId to be used for AuthOnlyContinued, GetDetails & Void : #{authTransId}"
225+
logger.info "TransId to be used for AuthOnlyContinued, GetDetails & Void : #{authTransId}"
227226

228-
puts "TEST - authorization only continued"
227+
logger.info "TEST - authorization only continued"
229228
response = authorization_only_continued(authTransId)
230229
validate_response(response)
231230

232231
# response = credit()
233232
# validate_response(response)
234233

235-
puts "TEST - Get Details"
234+
logger.info "TEST - Get Details"
236235
response = get_details(authTransId)
237236
validate_response(response)
238237

239-
puts "TEST - prior authorization and capture"
238+
logger.info "TEST - prior authorization and capture"
240239
response = prior_authorization_capture()
241240
validate_response(response)
242241

@@ -248,7 +247,7 @@ def validate_response(response= nil)
248247
end
249248

250249
it "should be able to run all Transaction Reporting sample code" do
251-
puts "START - Transaction Reporting"
250+
logger.info "START - Transaction Reporting"
252251

253252
response = get_settled_batch_List()
254253
validate_response(response)
@@ -276,7 +275,7 @@ def validate_response(response= nil)
276275

277276

278277
it "should be able to run Merchant Details sample code" do
279-
puts "START - Transaction Reporting / Merchant Details"
278+
logger.info "START - Transaction Reporting / Merchant Details"
280279

281280
response = get_merchant_details()
282281
validate_response(response)
@@ -285,7 +284,7 @@ def validate_response(response= nil)
285284

286285

287286
it "should be able to run all Visa Checkout sample code" do
288-
puts "START - Visa Checkout"
287+
logger.info "START - Visa Checkout"
289288

290289
# response = create_visa_checkout_transaction()
291290
# validate_response(response)

0 commit comments

Comments
 (0)