Created
April 30, 2012 10:17
-
-
Save coop/2557027 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class PayPalExpress::TransactionSearchTest < ActiveSupport::TestCase | |
test "#search returns a collection of transactions" do | |
account = MiniTest::Mock.new | |
period = MiniTest::Mock.new | |
requester = MiniTest::Mock.new | |
params = {} | |
params['ACK'] = 'Success' | |
params.default = [] | |
requester.expect :perform, params | |
transaction_search = PayPalExpress::TransactionSearch.new :period => period, :account => account, :requester => requester | |
transactions = transaction_search.search | |
assert_empty transactions | |
requester.verify | |
end | |
test "#search sends an email when PayPal returns a failure" do | |
account = MiniTest::Mock.new | |
period = MiniTest::Mock.new | |
requester = MiniTest::Mock.new | |
notifier = MiniTest::Mock.new | |
notifier.expect :deliver | |
params = {} | |
params['ACK'] = 'Error' | |
params.default = [] | |
transaction_search = PayPalExpress::TransactionSearch.new :period => period, :account => account, :requester => requester | |
transactions = transaction_search.search | |
assert notifier.verify | |
end | |
end |
I ended up doing something very similar to my proposal.
require 'test_helper'
class PayPalExpress::TransactionSearchTest < ActiveSupport::TestCase
test "#search returns a collection of transactions" do
account = MiniTest::Mock.new
period = MiniTest::Mock.new
requester = MiniTest::Mock.new
requester.expect :perform, OpenStruct.new(:success? => true)
transaction_search = PayPalExpress::TransactionSearch.new :period => period, :account => account, :requester => requester
transactions = transaction_search.search
assert_empty transactions
assert requester.verify
end
test "#search sends an email when PayPal returns a failure" do
account = MiniTest::Mock.new
period = MiniTest::Mock.new
requester = MiniTest::Mock.new
requester.expect :perform, OpenStruct.new(:success? => true)
notifier = MiniTest::Mock.new
notifier.expect :deliver_failed_transaction_search
transaction_search = PayPalExpress::TransactionSearch.new :period => period, :account => account, :requester => requester
transactions = transaction_search.search
assert requester.verify
assert notifier.verify
end
end
I wrapped the response object in code land because it's gross and could change. This allows me to not depend on the hash structure that I was relying on and instead rely on message passing!
Not sure how I came across this, but dig the badge.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am having to build a lot of setup here to test and I feel that what I'm actually wanting to test is getting lost. I think it might be more intention revealing if I ditch the hash (which I probably should be doing anyway) and do something more like:
Even writing that out feels better - at the moment I'm exposing too much of the implementation.