Skip to content
Browse files

Add a debug option to log interaction. Add a remote test for the bank…

…list.
  • Loading branch information...
1 parent fbaa780 commit 35eeb176bd487f0f081b7083d5fed2a3197b19b3 @Manfred Manfred committed Feb 11, 2012
Showing with 25 additions and 3 deletions.
  1. +2 −1 Rakefile
  2. +8 −0 lib/supreme/api.rb
  3. +12 −1 remote/basic_test.rb
  4. +3 −1 remote/test_helper.rb
View
3 Rakefile
@@ -14,7 +14,8 @@ namespace :test do
task :remote do
# Run the tests in random order
files = FileList['remote/**/*_test.rb']
- sh "ruby -Ilib -I. -r '#{files.join("' -r '")}' -e ''"
+ env = ENV['DEBUG'] ? "env DEBUG=true " : ''
+ sh "#{env}ruby -Ilib -I. -r '#{files.join("' -r '")}' -e ''"
end
end
View
8 lib/supreme/api.rb
@@ -37,6 +37,7 @@ def test?
# Supreme.api.banklist.to_a # => [{ :id => '1006', :name => 'ABN AMRO Bank' }, …]
def banklist
response = get('banklist')
+ log('Banklist response', response.body)
if response.ok?
Supreme::Banklist.new(response.body)
end
@@ -85,6 +86,7 @@ def fetch(options)
:return_url => :returnurl,
:report_url => :reporturl
}, options))
+ log('Fetch response', response.body)
if response.ok?
Supreme::Transaction.new(response.body)
end
@@ -109,6 +111,7 @@ def check(options)
options = options.dup
options[:partner_id] ||= partner_id
response = get('check', options)
+ log('Status response', response.body)
if response.ok?
Supreme::Status.new(response.body)
end
@@ -131,7 +134,12 @@ def get(action, options={})
options[:a] = action
url = endpoint
url.query = query(options)
+ log('GET', url.to_s)
REST.get(url.to_s)
end
+
+ def log(thing, contents)
+ $stderr.write("\n#{thing}:\n\n#{contents}\n") if $DEBUG
+ end
end
end
View
13 remote/basic_test.rb
@@ -1 +1,12 @@
-require File.expand_path('../test_helper', __FILE__)
+require File.expand_path('../test_helper', __FILE__)
+
+class BasicTest < Test::Unit::TestCase
+ def setup
+ Supreme.mode = :test
+ end
+
+ def test_banklist
+ banklist = Supreme.api.banklist
+ assert !banklist.to_a.empty?
+ end
+end
View
4 remote/test_helper.rb
@@ -7,6 +7,8 @@
require "test/unit"
+$DEBUG = !!ENV["DEBUG"]
+
config_file = File.expand_path('../../config/test.yml', __FILE__)
if File.exist?(config_file)
require 'yaml'
@@ -16,5 +18,5 @@
end
else
puts "[!] Please copy config/test.yml.example to config/test.yml and set your partner ID to run the remote tests."
- exit -1
+ exit(-1)
end

0 comments on commit 35eeb17

Please sign in to comment.
Something went wrong with that request. Please try again.