Skip to content

Instantly share code, notes, and snippets.

@windock
Created May 30, 2010 20:08
Show Gist options
  • Save windock/419286 to your computer and use it in GitHub Desktop.
Save windock/419286 to your computer and use it in GitHub Desktop.
require 'spec_helper'
include ActiveMerchant::Billing
describe BillingTransaction do
describe "remote requests" do
before :each do
@response = mock("response")
@response.stub!(:success?).and_return true
@response.stub!(:authorization).and_return "some reference"
@gateway = mock("gateway")
@billing_transaction = BillingTransaction.new
@billing_transaction.gateway = @gateway
end
describe ".puchase" do
before do
@gateway.stub!(:purchase).and_return @response
end
it "should take processor response as message" do
@response.stub!(:message).and_return "I'm a gateway response"
@billing_transaction.purchase!(100, Factory.build(:credit_card))
@billing_transaction.message.should == "I'm a gateway response"
end
end
describe ".credit" do
before do
@gateway.stub!(:credit).and_return @response
end
it "should take processor response as message" do
@response.stub!(:message).and_return "I'm a gateway response"
@billing_transaction.credit!(100, Factory.build(:credit_card))
@billing_transaction.message.should == "I'm a gateway response"
end
end
end
end
@windock
Copy link
Author

windock commented May 30, 2010

I have a problem: "should take processor response as message" code examples are mostly duplicated. And I have a lot of such code examples. What are the ways to refactor it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment