Skip to content

Commit

Permalink
make tests work ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly committed Aug 11, 2010
1 parent e73cca3 commit 4604ce8
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 68 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 Vitaly Kushner

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 changes: 13 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ Once you've configured the Ogone settings you need to set up a leaving page with

response.inspect

Copyright (c) 2010 Astrails Ltd., released under the MIT license
## Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

## Copyright

Copyright (c) 2010 Astrails Ltd. See LICENSE for details.
51 changes: 51 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "active_merchant_tranzila"
gem.summary = %Q{Tranzila gateway support for ActiveMerchant}
gem.description = %Q{Tranzila gateway support for ActiveMerchant}
gem.email = "[email protected]"
gem.homepage = "http://github.com/astrails/active_merchant_tranzila"
gem.authors = ["Astrails Ltd."]
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = true
end

begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end

task :test => :check_dependencies

task :default => :test

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "active_merchant_tranzila #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
50 changes: 50 additions & 0 deletions active_merchant_tranzila.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{active_merchant_tranzila}
s.version = "0.0.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Vitaly Kushner"]
s.date = %q{2010-08-11}
s.description = %q{TODO: longer description of your gem}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
"LICENSE",
"README.markdown"
]
s.files = [
"LICENSE",
"README.markdown",
"Rakefile",
"lib/active_merchant/billing/gateways/tranzila.rb",
"lib/active_merchant_tranzila.rb",
"test/helper.rb",
"test/remote/gateways/remote_tranzila_test.rb",
"test/unit/gateways/tranzila_test.rb"
]
s.homepage = %q{http://github.com/vitaly/active_merchant_tranzila}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.6}
s.summary = %q{TODO: one-line summary of your gem}
s.test_files = [
"test/helper.rb",
"test/remote/gateways/remote_tranzila_test.rb",
"test/unit/gateways/tranzila_test.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
end
else
end
end

1 change: 1 addition & 0 deletions lib/active_merchant/billing/gateways/tranzila.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'active_merchant'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
# This class implements the Tranzila (http://www.tranzila.com) Israeli payment gateway.
Expand Down
1 change: 1 addition & 0 deletions lib/active_merchant_tranzila.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'active_merchant/billing/gateways/tranzila'
107 changes: 107 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
require 'rubygems'
require 'test/unit'
require 'mocha'


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

ActiveMerchant::Billing::Base.mode = :test

module ActiveMerchant
module Assertions
AssertionClass = RUBY_VERSION > '1.9' ? MiniTest::Assertion : Test::Unit::AssertionFailedError

def assert_field(field, value)
clean_backtrace do
assert_equal value, @helper.fields[field]
end
end

# Allows the testing of you to check for negative assertions:
#
# # Instead of
# assert !something_that_is_false
#
# # Do this
# assert_false something_that_should_be_false
#
# An optional +msg+ parameter is available to help you debug.
def assert_false(boolean, message = nil)
message = build_message message, '<?> is not false or nil.', boolean

clean_backtrace do
assert_block message do
not boolean
end
end
end

# A handy little assertion to check for a successful response:
#
# # Instead of
# assert_success response
#
# # DRY that up with
# assert_success response
#
# A message will automatically show the inspection of the response
# object if things go afoul.
def assert_success(response)
clean_backtrace do
assert response.success?, "Response failed: #{response.inspect}"
end
end

# The negative of +assert_success+
def assert_failure(response)
clean_backtrace do
assert_false response.success?, "Response expected to fail: #{response.inspect}"
end
end

def assert_valid(validateable)
clean_backtrace do
assert validateable.valid?, "Expected to be valid"
end
end

def assert_not_valid(validateable)
clean_backtrace do
assert_false validateable.valid?, "Expected to not be valid"
end
end

private
def clean_backtrace(&block)
yield
rescue AssertionClass => e
path = File.expand_path(__FILE__)
raise AssertionClass, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
end
end

module Fixtures
private
def credit_card(number = '4242424242424242', options = {})
defaults = {
:number => number,
:month => 9,
:year => Time.now.year + 1,
:first_name => 'Longbob',
:last_name => 'Longsen',
:verification_value => '123',
:type => 'visa'
}.update(options)

Billing::CreditCard.new(defaults)
end
end
end

class Test::Unit::TestCase
include ActiveMerchant::Billing
include ActiveMerchant::Fixtures
include ActiveMerchant::Assertions
end
57 changes: 0 additions & 57 deletions test/remote/gateways/remote_tranzila_test.rb

This file was deleted.

20 changes: 10 additions & 10 deletions test/unit/gateways/tranzila_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test_helper'
require 'helper'
require 'rubygems'
require 'ruby-debug'

Expand All @@ -8,9 +8,9 @@ def setup

@credit_card = credit_card('4444333322221111')
@amount = 100.00
@options = {
:cred_type => '1',

@options = {
:cred_type => '1',
:myid => '306122847',
:ConfirmationCode => '0000000',
:index => '11'
Expand All @@ -19,18 +19,18 @@ def setup

def test_successful(successful_response, action)
@gateway.expects(:ssl_post).returns(successful_response)

assert response = @gateway.send(action, @amount, @credit_card, @options)
assert_instance_of Response, response
assert_instance_of Response, response
assert_success response

assert_equal '000', response.params['Response']
assert response.test?
end

def test_unsuccessful(failed_response, action, opts = {})
@gateway.expects(:ssl_post).returns(failed_response)

assert response = @gateway.send(action, @amount, @credit_card, @options)
assert_failure response
assert response.test?
Expand All @@ -40,7 +40,7 @@ def test_successful_purchase
test_successful(successful_purchase_response, :purchase)
end

def test_unsuccessful_purchas
def test_unsuccessful_purchase
test_unsuccessful(failed_purchase_response, :purchase)
end

Expand Down Expand Up @@ -104,5 +104,5 @@ def failed_purchase_response
def successful_purchase_response
"Response=000&ccno=4444333322221111&currency=1&cred_type=1&mycvv=123&expyear=15&supplier=test3&expmonth=09&myid=306122847&expdate=0915&sum=1.00&ConfirmationCode=0000000&index=88&Tempref=01300001&CVVstatus=3&Responsesource=0\n\n"
end

end

0 comments on commit 4604ce8

Please sign in to comment.