Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use thoughtbot style #40

Merged
merged 1 commit into from

1 participant

@gabebw

No description provided.

@gabebw gabebw merged commit cebe680 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 22, 2013
  1. @gabebw

    Use thoughtbot style

    gabebw authored
This page is out of date. Refresh to see the latest.
View
2  Gemfile
@@ -1,4 +1,4 @@
-source "http://rubygems.org"
+source 'http://rubygems.org'
# Specify your gem's dependencies in fake_braintree.gemspec
gemspec
View
8 Rakefile
@@ -1,8 +1,8 @@
-require "bundler/setup"
-require "bundler/gem_tasks"
-require "rspec/core/rake_task"
+require 'bundler/setup'
+require 'bundler/gem_tasks'
+require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
-desc "Run specs"
+desc 'Run specs'
task :default => [:spec]
View
14 fake_braintree.gemspec
@@ -1,20 +1,20 @@
# -*- encoding: utf-8 -*-
-$:.push File.expand_path("../lib", __FILE__)
-require "fake_braintree/version"
+$:.push File.expand_path('../lib', __FILE__)
+require 'fake_braintree/version'
Gem::Specification.new do |s|
- s.name = "fake_braintree"
+ s.name = 'fake_braintree'
s.version = FakeBraintree::VERSION
- s.authors = ["thoughtbot, inc."]
- s.email = ["gabe@thoughtbot.com", "ben@thoughtbot.com"]
- s.homepage = ""
+ s.authors = ['thoughtbot, inc.']
+ s.email = ['gabe@thoughtbot.com', 'ben@thoughtbot.com']
+ s.homepage = ''
s.summary = %q{A fake Braintree that you can run integration tests against}
s.description = %q{A fake Braintree that you can run integration tests against}
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = ["lib"]
+ s.require_paths = ['lib']
s.add_dependency 'capybara'
s.add_dependency 'activesupport'
View
62 lib/fake_braintree.rb
@@ -46,26 +46,32 @@ def self.failure?(card_number)
def self.failure_response(card_number = nil)
failure = registry.failures[card_number] || {}
- failure["errors"] ||= { "errors" => [] }
-
- { "message" => failure["message"],
- "verification" => { "status" => failure["status"],
- "processor_response_text" => failure["message"],
- "processor_response_code" => failure["code"],
- "gateway_rejection_reason" => "cvv",
- "cvv_response_code" => failure["code"] },
- "errors" => failure["errors"],
- "params" => {}}
+ failure['errors'] ||= { 'errors' => [] }
+
+ {
+ 'message' => failure['message'],
+ 'verification' => {
+ 'status' => failure['status'],
+ 'processor_response_text' => failure['message'],
+ 'processor_response_code' => failure['code'],
+ 'gateway_rejection_reason' => 'cvv',
+ 'cvv_response_code' => failure['code']
+ },
+ 'errors' => failure['errors'],
+ 'params' => {}
+ }
end
def self.create_failure
{
- "message" => "Do Not Honor",
- "verification" => { "status" => "processor_declined",
- "processor_response_text" => "Do Not Honor",
- "processor_response_code" => '2000' },
- "errors" => { 'errors' => [] },
- "params" => {}
+ 'message' => 'Do Not Honor',
+ 'verification' => {
+ 'status' => 'processor_declined',
+ 'processor_response_text' => 'Do Not Honor',
+ 'processor_response_code' => '2000'
+ },
+ 'errors' => { 'errors' => [] },
+ 'params' => {}
}
end
@@ -82,23 +88,27 @@ def self.verify_all_cards!
end
def self.generate_transaction(options = {})
- history_item = { 'timestamp' => Time.now,
- 'amount' => options[:amount],
- 'status' => options[:status] }
+ history_item = {
+ 'timestamp' => Time.now,
+ 'amount' => options[:amount],
+ 'status' => options[:status]
+ }
created_at = options[:created_at] || Time.now
- {'status_history' => [history_item],
- 'subscription_id' => options[:subscription_id],
- 'created_at' => created_at,
- 'amount' => options[:amount] }
+ {
+ 'status_history' => [history_item],
+ 'subscription_id' => options[:subscription_id],
+ 'created_at' => created_at,
+ 'amount' => options[:amount]
+ }
end
private
def self.set_configuration
Braintree::Configuration.environment = :development
- Braintree::Configuration.merchant_id = "xxx"
- Braintree::Configuration.public_key = "xxx"
- Braintree::Configuration.private_key = "xxx"
+ Braintree::Configuration.merchant_id = 'xxx'
+ Braintree::Configuration.public_key = 'xxx'
+ Braintree::Configuration.private_key = 'xxx'
end
def self.boot_server
View
21 lib/fake_braintree/credit_card.rb
@@ -81,7 +81,10 @@ def response_for_card_not_found
end
def response_for_invalid_card
- gzipped_response(422, FakeBraintree.failure_response.merge('params' => {:credit_card => @hash}).to_xml(:root => 'api_error_response'))
+ gzipped_response(422, FakeBraintree.failure_response.merge(
+ 'params' => {:credit_card => @hash}
+ ).
+ to_xml(:root => 'api_error_response'))
end
def expiration_month
@@ -94,20 +97,20 @@ def expiration_year
def set_up_credit_card(credit_card_hash_from_params, options)
@hash = {
- "token" => options[:token],
- "merchant_id" => options[:merchant_id],
- "customer_id" => options[:customer_id],
- "default" => options[:make_default]
+ 'token' => options[:token],
+ 'merchant_id' => options[:merchant_id],
+ 'customer_id' => options[:customer_id],
+ 'default' => options[:make_default]
}.merge(credit_card_hash_from_params)
end
def set_expiration_month_and_year
if expiration_month
- @hash["expiration_month"] = expiration_month
+ @hash['expiration_month'] = expiration_month
end
if expiration_year
- @hash["expiration_year"] = expiration_year
+ @hash['expiration_year'] = expiration_year
end
end
@@ -120,8 +123,8 @@ def token
end
def expiration_date_parts
- if @hash.key?("expiration_date")
- @hash["expiration_date"].split('/')
+ if @hash.key?('expiration_date')
+ @hash['expiration_date'].split('/')
else
[]
end
View
42 lib/fake_braintree/customer.rb
@@ -4,8 +4,8 @@ class Customer
def initialize(customer_hash_from_params, options)
@customer_hash = {
- "id" => options[:id],
- "merchant_id" => options[:merchant_id]
+ 'id' => options[:id],
+ 'merchant_id' => options[:merchant_id]
}
@customer_hash.merge!(customer_hash_from_params)
set_customer_id
@@ -15,7 +15,7 @@ def create
if invalid?
response_for_invalid_card
else
- credit_cards = customer_hash["credit_cards"]
+ credit_cards = customer_hash['credit_cards']
create_customer_with(customer_hash)
credit_cards.each { |card| add_credit_card_to_registry(card) }
response_for_created_customer(customer_hash)
@@ -48,11 +48,11 @@ def invalid?
end
def create_customer_with(hash)
- FakeBraintree.registry.customers[hash["id"]] = hash
+ FakeBraintree.registry.customers[hash['id']] = hash
end
def add_credit_card_to_registry(new_credit_card_hash)
- token = new_credit_card_hash["token"]
+ token = new_credit_card_hash['token']
FakeBraintree.registry.credit_cards[token] = new_credit_card_hash
end
@@ -61,7 +61,7 @@ def update_existing_customer(updates_hash)
end
def customer_hash
- @customer_hash.merge("credit_cards" => generate_credit_cards_from(@customer_hash["credit_card"]))
+ @customer_hash.merge('credit_cards' => generate_credit_cards_from(@customer_hash['credit_card']))
end
def customer_from_registry
@@ -83,11 +83,11 @@ def invalid_credit_card?
def verify_credit_card?(customer_hash_for_verification)
return true if FakeBraintree.verify_all_cards
- credit_card_hash_for_verification = customer_hash_for_verification["credit_card"]
+ credit_card_hash_for_verification = customer_hash_for_verification['credit_card']
if credit_card_hash_for_verification.is_a?(Hash) &&
- credit_card_hash_for_verification.key?("options")
- options = credit_card_hash_for_verification["options"]
- options["verify_card"] == true
+ credit_card_hash_for_verification.key?('options')
+ options = credit_card_hash_for_verification['options']
+ options['verify_card'] == true
end
end
@@ -97,20 +97,20 @@ def has_invalid_credit_card?(customer_hash)
end
def credit_card_number
- credit_card_hash["number"]
+ credit_card_hash['number']
end
def generate_credit_cards_from(new_credit_card_hash)
if new_credit_card_hash.present? && new_credit_card_hash.is_a?(Hash)
- new_credit_card_hash["last_4"] = new_credit_card_hash["number"][-4..-1]
- new_credit_card_hash["token"] = credit_card_token(new_credit_card_hash)
+ new_credit_card_hash['last_4'] = new_credit_card_hash['number'][-4..-1]
+ new_credit_card_hash['token'] = credit_card_token(new_credit_card_hash)
if credit_card_expiration_month
- new_credit_card_hash["expiration_month"] = credit_card_expiration_month
+ new_credit_card_hash['expiration_month'] = credit_card_expiration_month
end
if credit_card_expiration_year
- new_credit_card_hash["expiration_year"] = credit_card_expiration_year
+ new_credit_card_hash['expiration_year'] = credit_card_expiration_year
end
[new_credit_card_hash]
@@ -128,8 +128,8 @@ def credit_card_expiration_year
end
def credit_card_expiration_date
- if credit_card_hash.key?("expiration_date")
- credit_card_hash["expiration_date"].split('/')
+ if credit_card_hash.key?('expiration_date')
+ credit_card_hash['expiration_date'].split('/')
else
[]
end
@@ -164,7 +164,7 @@ def failure_response(code)
end
def customer_id
- customer_hash["id"]
+ customer_hash['id']
end
def has_credit_card?
@@ -172,15 +172,15 @@ def has_credit_card?
end
def credit_card_hash
- @customer_hash["credit_card"] || {}
+ @customer_hash['credit_card'] || {}
end
def set_customer_id
- @customer_hash["id"] ||= create_id(@customer_hash["merchant_id"])
+ @customer_hash['id'] ||= create_id(@customer_hash['merchant_id'])
end
def credit_card_token(credit_card_hash_without_token)
- md5("#{credit_card_hash_without_token["number"]}#{@customer_hash["merchant_id"]}")
+ md5("#{credit_card_hash_without_token['number']}#{@customer_hash['merchant_id']}")
end
end
end
View
2  lib/fake_braintree/helpers.rb
@@ -9,7 +9,7 @@ def gzip(content)
end
def gzipped_response(status_code, uncompressed_content)
- [status_code, { "Content-Encoding" => "gzip" }, gzip(uncompressed_content)]
+ [status_code, { 'Content-Encoding' => 'gzip' }, gzip(uncompressed_content)]
end
def md5(content)
View
6 lib/fake_braintree/redirect.rb
@@ -5,7 +5,7 @@ class Redirect
attr_reader :id
def initialize(params, merchant_id)
- hash, query = *params[:tr_data].split("|", 2)
+ hash, query = *params[:tr_data].split('|', 2)
@transparent_data = Rack::Utils.parse_nested_query(query)
@merchant_id = merchant_id
@id = create_id(@merchant_id)
@@ -19,7 +19,7 @@ def url
def confirm
if @kind == 'create_customer'
- Customer.new(@params["customer"], {:merchant_id => @merchant_id}).create
+ Customer.new(@params['customer'], {:merchant_id => @merchant_id}).create
elsif @kind == 'create_payment_method'
credit_card_options = {:merchant_id => @merchant_id}
credit_card_options.merge!(@transparent_data['credit_card'].fetch('options', {}))
@@ -32,7 +32,7 @@ def confirm
private
def uri
- URI.parse(@transparent_data["redirect_url"]).merge("?#{base_query}&hash=#{hash(base_query)}")
+ URI.parse(@transparent_data['redirect_url']).merge("?#{base_query}&hash=#{hash(base_query)}")
end
def base_query
View
80 lib/fake_braintree/sinatra_app.rb
@@ -21,14 +21,14 @@ def hash_from_request_body_with_key(key)
end
# Braintree::Customer.create
- post "/merchants/:merchant_id/customers" do
- customer_hash = hash_from_request_body_with_key("customer")
+ post '/merchants/:merchant_id/customers' do
+ customer_hash = hash_from_request_body_with_key('customer')
options = {:merchant_id => params[:merchant_id]}
Customer.new(customer_hash, options).create
end
# Braintree::Customer.find
- get "/merchants/:merchant_id/customers/:id" do
+ get '/merchants/:merchant_id/customers/:id' do
customer = FakeBraintree.registry.customers[params[:id]]
if customer
gzipped_response(200, customer.to_xml(:root => 'customer'))
@@ -38,28 +38,28 @@ def hash_from_request_body_with_key(key)
end
# Braintree::Customer.update
- put "/merchants/:merchant_id/customers/:id" do
- customer_hash = hash_from_request_body_with_key("customer")
+ put '/merchants/:merchant_id/customers/:id' do
+ customer_hash = hash_from_request_body_with_key('customer')
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Customer.new(customer_hash, options).update
end
# Braintree::Customer.delete
- delete "/merchants/:merchant_id/customers/:id" do
+ delete '/merchants/:merchant_id/customers/:id' do
customer_hash = {}
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Customer.new(customer_hash, options).delete
end
# Braintree::Subscription.create
- post "/merchants/:merchant_id/subscriptions" do
- subscription_hash = hash_from_request_body_with_key("subscription")
+ post '/merchants/:merchant_id/subscriptions' do
+ subscription_hash = hash_from_request_body_with_key('subscription')
options = {:merchant_id => params[:merchant_id]}
Subscription.new(subscription_hash, options).create
end
# Braintree::Subscription.find
- get "/merchants/:merchant_id/subscriptions/:id" do
+ get '/merchants/:merchant_id/subscriptions/:id' do
subscription = FakeBraintree.registry.subscriptions[params[:id]]
if subscription
gzipped_response(200, subscription.to_xml(:root => 'subscription'))
@@ -69,40 +69,40 @@ def hash_from_request_body_with_key(key)
end
# Braintree::Subscription.update
- put "/merchants/:merchant_id/subscriptions/:id" do
- subscription_hash = hash_from_request_body_with_key("subscription")
+ put '/merchants/:merchant_id/subscriptions/:id' do
+ subscription_hash = hash_from_request_body_with_key('subscription')
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Subscription.new(subscription_hash, options).update
end
# Braintree::Subscription.cancel
- put "/merchants/:merchant_id/subscriptions/:id/cancel" do
- updates = {"status" => Braintree::Subscription::Status::Canceled}
+ put '/merchants/:merchant_id/subscriptions/:id/cancel' do
+ updates = {'status' => Braintree::Subscription::Status::Canceled}
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Subscription.new(updates, options).update
end
# Braintree::CreditCard.find
- get "/merchants/:merchant_id/payment_methods/:credit_card_token" do
+ get '/merchants/:merchant_id/payment_methods/:credit_card_token' do
credit_card = FakeBraintree.registry.credit_cards[params[:credit_card_token]]
if credit_card
- gzipped_response(200, credit_card.to_xml(:root => "credit_card"))
+ gzipped_response(200, credit_card.to_xml(:root => 'credit_card'))
else
gzipped_response(404, {})
end
end
# Braintree::CreditCard.update
- put "/merchants/:merchant_id/payment_methods/:credit_card_token" do
+ put '/merchants/:merchant_id/payment_methods/:credit_card_token' do
credit_card = FakeBraintree.registry.credit_cards[params[:credit_card_token]]
- updates = hash_from_request_body_with_key("credit_card")
+ updates = hash_from_request_body_with_key('credit_card')
options = {:token => params[:credit_card_token], :merchant_id => params[:merchant_id]}
CreditCard.new(updates, options).update
end
# Braintree::CreditCard.create
- post "/merchants/:merchant_id/payment_methods" do
- credit_card_hash = hash_from_request_body_with_key("credit_card")
+ post '/merchants/:merchant_id/payment_methods' do
+ credit_card_hash = hash_from_request_body_with_key('credit_card')
options = {:merchant_id => params[:merchant_id]}
if credit_card_hash['options']
@@ -114,61 +114,61 @@ def hash_from_request_body_with_key(key)
# Braintree::Transaction.sale
# Braintree::CreditCard.sale
- post "/merchants/:merchant_id/transactions" do
+ post '/merchants/:merchant_id/transactions' do
if FakeBraintree.decline_all_cards?
gzipped_response(422, FakeBraintree.create_failure.to_xml(:root => 'api_error_response'))
else
- transaction = hash_from_request_body_with_key("transaction")
- transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
- transaction_response = {"id" => transaction_id, "amount" => transaction["amount"]}
+ transaction = hash_from_request_body_with_key('transaction')
+ transaction_id = md5('#{params[:merchant_id]}#{Time.now.to_f}')
+ transaction_response = {'id' => transaction_id, 'amount' => transaction['amount']}
FakeBraintree.registry.transactions[transaction_id] = transaction_response
- gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction_response.to_xml(:root => 'transaction'))
end
end
# Braintree::Transaction.find
- get "/merchants/:merchant_id/transactions/:transaction_id" do
+ get '/merchants/:merchant_id/transactions/:transaction_id' do
transaction = FakeBraintree.registry.transactions[params[:transaction_id]]
if transaction
- gzipped_response(200, transaction.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction.to_xml(:root => 'transaction'))
else
gzipped_response(404, {})
end
end
# Braintree::Transaction.refund
- post "/merchants/:merchant_id/transactions/:transaction_id/refund" do
- transaction = hash_from_request_body_with_key("transaction")
- transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
- transaction_response = {"id" => transaction_id, "amount" => transaction["amount"], "type" => "credit"}
+ post '/merchants/:merchant_id/transactions/:transaction_id/refund' do
+ transaction = hash_from_request_body_with_key('transaction')
+ transaction_id = md5('#{params[:merchant_id]}#{Time.now.to_f}')
+ transaction_response = {'id' => transaction_id, 'amount' => transaction['amount'], 'type' => 'credit'}
FakeBraintree.registry.transactions[transaction_id] = transaction_response
- gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction_response.to_xml(:root => 'transaction'))
end
# Braintree::Transaction.void
- put "/merchants/:merchant_id/transactions/:transaction_id/void" do
+ put '/merchants/:merchant_id/transactions/:transaction_id/void' do
transaction = FakeBraintree.registry.transactions[params[:transaction_id]]
- transaction_response = {"id" => transaction["id"],
- "type" => transaction["sale"],
- "amount" => transaction["amount"],
- "status" => Braintree::Transaction::Status::Voided}
+ transaction_response = {'id' => transaction['id'],
+ 'type' => transaction['sale'],
+ 'amount' => transaction['amount'],
+ 'status' => Braintree::Transaction::Status::Voided}
FakeBraintree.registry.transactions[transaction['id']] = transaction_response
- gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction_response.to_xml(:root => 'transaction'))
end
# Braintree::TransparentRedirect.url
- post "/merchants/:merchant_id/transparent_redirect_requests" do
+ post '/merchants/:merchant_id/transparent_redirect_requests' do
if params[:tr_data]
redirect = Redirect.new(params, params[:merchant_id])
FakeBraintree.registry.redirects[redirect.id] = redirect
redirect to(redirect.url), 303
else
- [422, { "Content-Type" => "text/html" }, ["Invalid submission"]]
+ [422, { 'Content-Type' => 'text/html' }, ['Invalid submission']]
end
end
# Braintree::TransparentRedirect.confirm
- post "/merchants/:merchant_id/transparent_redirect_requests/:id/confirm" do
+ post '/merchants/:merchant_id/transparent_redirect_requests/:id/confirm' do
redirect = FakeBraintree.registry.redirects[params[:id]]
redirect.confirm
end
View
38 lib/fake_braintree/subscription.rb
@@ -3,8 +3,10 @@ class Subscription
include Helpers
def initialize(subscription_hash_from_params, options)
- @subscription_hash = subscription_hash_from_params.merge("merchant_id" => options[:merchant_id],
- "id" => options[:id])
+ @subscription_hash = subscription_hash_from_params.merge(
+ 'merchant_id' => options[:merchant_id],
+ 'id' => options[:id]
+ )
set_subscription_id
set_subscription_status
end
@@ -26,10 +28,12 @@ def update
private
def subscription_hash
- @subscription_hash.merge({"transactions" => [],
- "add_ons" => added_add_ons,
- "discounts" => added_discounts,
- "next_billing_date" => braintree_formatted_date(1.month.from_now)})
+ @subscription_hash.merge(
+ 'transactions' => [],
+ 'add_ons' => added_add_ons,
+ 'discounts' => added_discounts,
+ 'next_billing_date' => braintree_formatted_date(1.month.from_now)
+ )
end
def update_existing_subscription(updates)
@@ -38,7 +42,7 @@ def update_existing_subscription(updates)
end
def create_subscription_with(new_subscription_hash)
- FakeBraintree.registry.subscriptions[new_subscription_hash["id"]] = new_subscription_hash
+ FakeBraintree.registry.subscriptions[new_subscription_hash['id']] = new_subscription_hash
end
def subscription_from_registry
@@ -54,31 +58,31 @@ def braintree_formatted_date(date)
end
def added_add_ons
- if @subscription_hash["add_ons"].is_a?(Hash) && @subscription_hash["add_ons"]["add"]
- @subscription_hash["add_ons"]["add"].map { |add_on| { "id" => add_on["inherited_from_id"] } }
+ if @subscription_hash['add_ons'].is_a?(Hash) && @subscription_hash['add_ons']['add']
+ @subscription_hash['add_ons']['add'].map { |add_on| { 'id' => add_on['inherited_from_id'] } }
else
[]
end
end
def added_discounts
- if @subscription_hash["discounts"].is_a?(Hash) && @subscription_hash["discounts"]["add"]
- @subscription_hash["discounts"]["add"].map { |discount| { "id" => discount["inherited_from_id"] } }
+ if @subscription_hash['discounts'].is_a?(Hash) && @subscription_hash['discounts']['add']
+ @subscription_hash['discounts']['add'].map { |discount| { 'id' => discount['inherited_from_id'] } }
else
[]
end
end
def set_subscription_id
- @subscription_hash["id"] ||= generate_new_subscription_id
+ @subscription_hash['id'] ||= generate_new_subscription_id
end
def set_subscription_status
- @subscription_hash["status"] ||= active_status
+ @subscription_hash['status'] ||= active_status
end
def subscription_id
- subscription_hash["id"]
+ subscription_hash['id']
end
def generate_new_subscription_id
@@ -86,7 +90,7 @@ def generate_new_subscription_id
end
def payment_method_token
- @subscription_hash["payment_method_token"]
+ @subscription_hash['payment_method_token']
end
def active_status
@@ -94,7 +98,7 @@ def active_status
end
def response_for_created_subscription(hash)
- gzipped_response(201, hash.to_xml(:root => "subscription"))
+ gzipped_response(201, hash.to_xml(:root => 'subscription'))
end
def response_for_subscription_not_found
@@ -102,7 +106,7 @@ def response_for_subscription_not_found
end
def response_for_created_subscription(hash)
- gzipped_response(201, hash.to_xml(:root => "subscription"))
+ gzipped_response(201, hash.to_xml(:root => 'subscription'))
end
end
end
View
21 spec/fake_braintree/credit_card_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
-describe "Braintree::CreditCard.find" do
- it "gets the correct credit card" do
+describe 'Braintree::CreditCard.find' do
+ it 'gets the correct credit card' do
credit_card = Braintree::CreditCard.find(token)
credit_card.last_4.should == TEST_CC_NUMBER[-4,4]
@@ -14,8 +14,8 @@
let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, [month, year].join('/')) }
end
-describe "Braintree::CreditCard.sale" do
- it "successfully creates a sale" do
+describe 'Braintree::CreditCard.sale' do
+ it 'successfully creates a sale' do
result = Braintree::CreditCard.sale(cc_token, :amount => 10.00)
result.should be_success
Braintree::Transaction.find(result.transaction.id).should be
@@ -23,7 +23,7 @@
end
-describe "Braintree::CreditCard.create" do
+describe 'Braintree::CreditCard.create' do
def build_credit_card_hash
{
:customer_id => @customer && @customer.id,
@@ -50,6 +50,7 @@ def build_credit_card_hash
before do
@customer = Braintree::Customer.create.customer
end
+
it 'fails to create a credit card if decline_all_cards is set' do
FakeBraintree.decline_all_cards!
result = Braintree::CreditCard.create(build_credit_card_hash)
@@ -86,9 +87,9 @@ def build_credit_card_hash
end
end
-describe "Braintree::CreditCard.update" do
- it "successfully updates the credit card" do
- new_expiration_date = "08/2012"
+describe 'Braintree::CreditCard.update' do
+ it 'successfully updates the credit card' do
+ new_expiration_date = '08/2012'
token = cc_token
result = Braintree::CreditCard.update(token, :expiration_date => new_expiration_date)
@@ -96,7 +97,7 @@ def build_credit_card_hash
Braintree::CreditCard.find(token).expiration_date.should == new_expiration_date
end
- it "raises an error for a nonexistent credit card" do
- lambda { Braintree::CreditCard.update("foo", {:number => TEST_CC_NUMBER}) }.should raise_error(Braintree::NotFoundError)
+ it 'raises an error for a nonexistent credit card' do
+ lambda { Braintree::CreditCard.update('foo', {:number => TEST_CC_NUMBER}) }.should raise_error(Braintree::NotFoundError)
end
end
View
124 spec/fake_braintree/customer_spec.rb
@@ -1,127 +1,151 @@
require 'spec_helper'
-describe "Braintree::Customer.create" do
+describe 'Braintree::Customer.create' do
after { FakeBraintree.verify_all_cards = false }
- it "successfully creates a customer" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_date => '04/2016'})
+ it 'successfully creates a customer' do
+ result = Braintree::Customer.create(
+ :credit_card => {
+ :number => TEST_CC_NUMBER,
+ :expiration_date => '04/2016'
+ }
+ )
result.should be_success
end
- it "associates a created credit card with the customer" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_date => '04/2016'})
+ it 'associates a created credit card with the customer' do
+ result = Braintree::Customer.create(
+ :credit_card => {
+ :number => TEST_CC_NUMBER,
+ :expiration_date => '04/2016'
+ }
+ )
credit_cards = Braintree::Customer.find(result.customer.id).credit_cards
credit_cards.size.should == 1
- credit_cards.first.expiration_date.should == "04/2016"
+ credit_cards.first.expiration_date.should == '04/2016'
end
it "successfully creates the customer's credit card" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_date => '04/2016'})
+ result = Braintree::Customer.create(
+ :credit_card => {
+ :number => TEST_CC_NUMBER,
+ :expiration_date => '04/2016'
+ }
+ )
cc_token = result.customer.credit_cards.first.token
expect { Braintree::CreditCard.find(cc_token) }.not_to raise_error(Braintree::NotFoundError)
end
- it "can handle an empty credit card hash" do
+ it 'can handle an empty credit card hash' do
result = Braintree::Customer.create(:credit_card => {})
result.should be_success
end
- it "does not overwrite a passed customer id" do
- result = Braintree::Customer.create({ "id" => '123' })
+ it 'does not overwrite a passed customer id' do
+ result = Braintree::Customer.create({ 'id' => '123' })
result.customer.id.should eq('123')
end
- it "creates a customer using an expiration month and year" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_month => '04',
- :expiration_year => '2016'})
+ it 'creates a customer using an expiration month and year' do
+ result = Braintree::Customer.create(
+ :credit_card => {
+ :number => TEST_CC_NUMBER,
+ :expiration_month => '04',
+ :expiration_year => '2016'
+ }
+ )
result.should be_success
end
- it "records the billing address" do
+ it 'records the billing address' do
result = create_customer(
:billing_address => {
- :street_address => "1 E Main St",
- :extended_address => "Suite 3",
- :locality => "Chicago",
- :region => "Illinois",
- :postal_code => "60622",
- :country_code_alpha2 => "US"
+ :street_address => '1 E Main St',
+ :extended_address => 'Suite 3',
+ :locality => 'Chicago',
+ :region => 'Illinois',
+ :postal_code => '60622',
+ :country_code_alpha2 => 'US'
}
)
billing_address = result.customer.credit_cards[0].billing_address
- billing_address.street_address.should == "1 E Main St"
- billing_address.postal_code.should == "60622"
+ billing_address.street_address.should == '1 E Main St'
+ billing_address.postal_code.should == '60622'
end
end
-describe "Braintree::Customer.create", "when passed :verify_card => true" do
- it "accepts valid cards" do
+describe 'Braintree::Customer.create', 'when passed :verify_card => true' do
+ it 'accepts valid cards' do
create_customer(:options => { :verify_card => true }).should be_success
end
- it "rejects invalid cards" do
+ it 'rejects invalid cards' do
create_customer_with_invalid_card(:options => { :verify_card => true }).should_not be_success
end
end
-describe "Braintree::Customer.create", "when FakeBraintree.verify_all_cards == true" do
+describe 'Braintree::Customer.create', 'when FakeBraintree.verify_all_cards == true' do
before { FakeBraintree.verify_all_cards! }
- it "accepts valid cards" do
+ it 'accepts valid cards' do
create_customer.should be_success
end
- it "rejects invalid cards" do
+ it 'rejects invalid cards' do
create_customer_with_invalid_card.should_not be_success
end
end
-describe "Braintree::Customer.find" do
- it "successfully finds a customer" do
- result = Braintree::Customer.create(:first_name => "Bob",
- :last_name => "Smith")
+describe 'Braintree::Customer.find' do
+ it 'successfully finds a customer' do
+ result = Braintree::Customer.create(
+ :first_name => 'Bob',
+ :last_name => 'Smith'
+ )
- Braintree::Customer.find(result.customer.id).first_name.should == "Bob"
+ Braintree::Customer.find(result.customer.id).first_name.should == 'Bob'
end
- it "raises an error for a nonexistent customer" do
- lambda { Braintree::Customer.find("foo") }.should raise_error(Braintree::NotFoundError)
+ it 'raises an error for a nonexistent customer' do
+ lambda { Braintree::Customer.find('foo') }.should raise_error(Braintree::NotFoundError)
end
end
-describe "Braintree::Customer.update" do
- it "successfully updates a customer" do
+describe 'Braintree::Customer.update' do
+ it 'successfully updates a customer' do
customer_id = create_customer.customer.id
- result = Braintree::Customer.update(customer_id, :first_name => "Jerry")
+ result = Braintree::Customer.update(customer_id, :first_name => 'Jerry')
result.should be_success
- Braintree::Customer.find(customer_id).first_name.should == "Jerry"
+ Braintree::Customer.find(customer_id).first_name.should == 'Jerry'
end
- it "raises an error for a nonexistent customer" do
- lambda { Braintree::Customer.update("foo", {:first_name => "Bob"}) }.should raise_error(Braintree::NotFoundError)
+ it 'raises an error for a nonexistent customer' do
+ lambda { Braintree::Customer.update('foo', {:first_name => 'Bob'}) }.should raise_error(Braintree::NotFoundError)
end
- it "does not allow a customer to be updated to a failing credit card" do
- bad_credit_card = "123456"
+ it 'does not allow a customer to be updated to a failing credit card' do
+ bad_credit_card = '123456'
FakeBraintree.registry.failures[bad_credit_card] = FakeBraintree.failure_response
customer = create_customer
- result = Braintree::Customer.update(customer.customer.id, {:credit_card => { :number => bad_credit_card }})
+ result = Braintree::Customer.update(customer.customer.id,
+ {
+ :credit_card => {
+ :number => bad_credit_card
+ }
+ }
+ )
result.should_not be_success
end
end
-describe "Braintree::Customer.delete" do
- it "successfully deletes a customer" do
+describe 'Braintree::Customer.delete' do
+ it 'successfully deletes a customer' do
customer_id = create_customer.customer.id
result = Braintree::Customer.delete(customer_id)
View
13 spec/fake_braintree/registry_spec.rb
@@ -9,7 +9,7 @@
it { should have_hash_accessor_for(:credit_cards) }
end
-describe FakeBraintree::Registry, "#clear!" do
+describe FakeBraintree::Registry, '#clear!' do
it { should clear_hash_when_cleared(:customers) }
it { should clear_hash_when_cleared(:subscriptions) }
it { should clear_hash_when_cleared(:failures) }
@@ -18,15 +18,14 @@
it { should clear_hash_when_cleared(:credit_cards) }
end
-describe FakeBraintree::Registry, "#failure?" do
- it "returns false if the given CC number is not marked as a failure" do
- registry.failure?('not-a-failure').should be_false
+describe FakeBraintree::Registry, '#failure?' do
+ it 'returns false if the given CC number is not marked as a failure' do
+ FakeBraintree::Registry.new.failure?('not-a-failure').should be_false
end
- it "returns true if the given CC number is marked as a failure" do
+ it 'returns true if the given CC number is marked as a failure' do
+ registry = FakeBraintree::Registry.new
registry.failures['abc123'] = 'whatever'
registry.failure?('abc123').should be_true
end
-
- let(:registry) { subject }
end
View
62 spec/fake_braintree/subscription_spec.rb
@@ -1,44 +1,50 @@
require 'spec_helper'
-describe "Braintree::Subscription.create" do
+describe 'Braintree::Subscription.create' do
let(:plan_id) { 'plan-id-from-braintree-control-panel' }
- let(:expiration_date) { "04/2016" }
+ let(:expiration_date) { '04/2016' }
- it "successfully creates a subscription" do
- Braintree::Subscription.create(:payment_method_token => cc_token,
- :plan_id => 'my_plan_id').should be_success
+ it 'successfully creates a subscription' do
+ Braintree::Subscription.create(
+ :payment_method_token => cc_token,
+ :plan_id => 'my_plan_id'
+ ).should be_success
end
- it "assigns a Braintree-esque ID to the subscription" do
+ it 'assigns a Braintree-esque ID to the subscription' do
create_subscription.subscription.id.should =~ /^[a-z0-9]{6}$/
end
- it "assigns unique IDs to each subscription" do
+ it 'assigns unique IDs to each subscription' do
cc_token_1 = cc_token
cc_token_2 = braintree_credit_card_token(TEST_CC_NUMBER.sub('1', '5'), expiration_date)
- first_result = Braintree::Subscription.create(:payment_method_token => cc_token_1,
- :plan_id => plan_id)
- second_result = Braintree::Subscription.create(:payment_method_token => cc_token_2,
- :plan_id => plan_id)
+ first_result = Braintree::Subscription.create(
+ :payment_method_token => cc_token_1,
+ :plan_id => plan_id
+ )
+ second_result = Braintree::Subscription.create(
+ :payment_method_token => cc_token_2,
+ :plan_id => plan_id
+ )
first_result.subscription.id.should_not == second_result.subscription.id
end
- it "stores created subscriptions in FakeBraintree.registry.subscriptions" do
+ it 'stores created subscriptions in FakeBraintree.registry.subscriptions' do
FakeBraintree.registry.subscriptions[create_subscription.subscription.id].should_not be_nil
end
- it "sets the next billing date to a string of 1.month.from_now in UTC" do
+ it 'sets the next billing date to a string of 1.month.from_now in UTC' do
Timecop.freeze do
create_subscription.subscription.next_billing_date.should == 1.month.from_now.strftime('%Y-%m-%d')
end
end
end
-describe "Braintree::Subscription.find" do
- it "can find a created subscription" do
+describe 'Braintree::Subscription.find' do
+ it 'can find a created subscription' do
payment_method_token = cc_token
- plan_id = "abc123"
+ plan_id = 'abc123'
subscription_id =
create_subscription(:payment_method_token => payment_method_token, :plan_id => plan_id).subscription.id
subscription = Braintree::Subscription.find(subscription_id)
@@ -47,13 +53,13 @@
subscription.plan_id.should == plan_id
end
- it "raises a Braintree:NotFoundError when it cannot find a subscription" do
+ it 'raises a Braintree:NotFoundError when it cannot find a subscription' do
create_subscription
expect { Braintree::Subscription.find('abc123') }.to raise_error(Braintree::NotFoundError, /abc123/)
end
- it "returns add-ons added with the subscription" do
- add_on_id = "def456"
+ it 'returns add-ons added with the subscription' do
+ add_on_id = 'def456'
subscription_id = create_subscription(:add_ons => { :add => [{ :inherited_from_id => add_on_id }] }).subscription.id
subscription = Braintree::Subscription.find(subscription_id)
add_ons = subscription.add_ons
@@ -61,9 +67,9 @@
add_ons.first.id.should == add_on_id
end
- it "returns discounts added with the subscription" do
- discount_id = "def456"
- subscription_id = create_subscription(:discounts => { :add => [{ :inherited_from_id => discount_id, :amount => BigDecimal.new("15.00") }]}).subscription.id
+ it 'returns discounts added with the subscription' do
+ discount_id = 'def456'
+ subscription_id = create_subscription(:discounts => { :add => [{ :inherited_from_id => discount_id, :amount => BigDecimal.new('15.00') }]}).subscription.id
subscription = Braintree::Subscription.find(subscription_id)
discounts = subscription.discounts
discounts.size.should == 1
@@ -71,8 +77,8 @@
end
end
-describe "Braintree::Subscription.update" do
- it "can update a subscription" do
+describe 'Braintree::Subscription.update' do
+ it 'can update a subscription' do
Braintree::Subscription.update(subscription_id, :plan_id => 'a_new_plan')
Braintree::Subscription.find(subscription_id).plan_id.should == 'a_new_plan'
end
@@ -81,14 +87,14 @@
let(:subscription) { create_subscription }
end
-describe "Braintree::Subscription.cancel" do
- it "can cancel a subscription" do
+describe 'Braintree::Subscription.cancel' do
+ it 'can cancel a subscription' do
Braintree::Subscription.cancel(subscription_id).should be_success
Braintree::Subscription.find(subscription_id).status.should == Braintree::Subscription::Status::Canceled
end
- it "can't cancel an unknown subscription" do
- expect { Braintree::Subscription.cancel("totally-bogus-id") }.to raise_error(Braintree::NotFoundError)
+ it 'cannot cancel an unknown subscription' do
+ expect { Braintree::Subscription.cancel('totally-bogus-id') }.to raise_error(Braintree::NotFoundError)
end
let(:subscription_id) { subscription.subscription.id }
View
39 spec/fake_braintree/transaction_spec.rb
@@ -1,17 +1,23 @@
require 'spec_helper'
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.sale" do
- it "successfully creates a transaction" do
- result = Braintree::Transaction.sale(:payment_method_token => cc_token, :amount => 10.00)
+ context 'Braintree::Transaction.sale' do
+ it 'successfully creates a transaction' do
+ result = Braintree::Transaction.sale(
+ :payment_method_token => cc_token,
+ :amount => 10.00
+ )
result.should be_success
end
- context "when all cards are declined" do
+ context 'when all cards are declined' do
before { FakeBraintree.decline_all_cards! }
- it "fails" do
- result = Braintree::Transaction.sale(:payment_method_token => cc_token, :amount => 10.00)
+ it 'fails' do
+ result = Braintree::Transaction.sale(
+ :payment_method_token => cc_token,
+ :amount => 10.00
+ )
result.should_not be_success
end
end
@@ -19,8 +25,8 @@
end
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.refund" do
- it "successfully refunds a transaction" do
+ context 'Braintree::Transaction.refund' do
+ it 'successfully refunds a transaction' do
result = Braintree::Transaction.refund(create_id('foobar'), '1')
result.should be_success
end
@@ -28,9 +34,12 @@
end
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.void" do
- it "successfully voids a transaction" do
- sale = Braintree::Transaction.sale(:payment_method_token => cc_token, :amount => 10.00)
+ context 'Braintree::Transaction.void' do
+ it 'successfully voids a transaction' do
+ sale = Braintree::Transaction.sale(
+ :payment_method_token => cc_token,
+ :amount => 10.00
+ )
result = Braintree::Transaction.void(sale.transaction.id)
result.should be_success
result.transaction.status.should == Braintree::Transaction::Status::Voided
@@ -39,19 +48,19 @@
end
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.find" do
- it "can find a created sale" do
+ context 'Braintree::Transaction.find' do
+ it 'can find a created sale' do
id = create_transaction.id
result = Braintree::Transaction.find(id)
result.amount.should == amount
end
- it "can find >1 transaction" do
+ it 'can find >1 transaction' do
Braintree::Transaction.find(create_transaction.id).should be
Braintree::Transaction.find(create_transaction.id).should be
end
- it "raises an error when the transaction does not exist" do
+ it 'raises an error when the transaction does not exist' do
expect { Braintree::Transaction.find('foobar') }.to raise_error(Braintree::NotFoundError)
end
View
58 spec/fake_braintree/transparent_redirect_spec.rb
@@ -1,30 +1,30 @@
require 'spec_helper'
describe FakeBraintree::SinatraApp do
- context "Braintree::TransparentRedirect.url" do
- it "returns a URL that will redirect with a token for the specified request" do
- redirect_url = "http://example.com/redirect_path"
+ context 'Braintree::TransparentRedirect.url' do
+ it 'returns a URL that will redirect with a token for the specified request' do
+ redirect_url = 'http://example.com/redirect_path'
response = post_transparent_redirect(:create_customer_data, :redirect_url => redirect_url, :customer => build_customer_hash)
- response.code.should == "303"
- response["Location"].should =~ %r{http://example\.com/redirect_path}
+ response.code.should == '303'
+ response['Location'].should =~ %r{http://example\.com/redirect_path}
params = parse_redirect(response)
- params[:http_status].should == "200"
+ params[:http_status].should == '200'
params[:id].should_not be_nil
params[:kind].should_not be_nil
end
- it "rejects submissions without transparent redirect data" do
+ it 'rejects submissions without transparent redirect data' do
response = post_transparent_redirect_without_data
- response.code.should == "422"
+ response.code.should == '422'
end
end
- context "Braintree::TransparentRedirect.confirm" do
- describe "Creating customers" do
- it "confirms and runs the specified request" do
- number = "4111111111111111"
+ context 'Braintree::TransparentRedirect.confirm' do
+ describe 'Creating customers' do
+ it 'confirms and runs the specified request' do
+ number = '4111111111111111'
customer_hash = build_customer_hash(:credit_card => { :number => number })
response = post_transparent_redirect(:create_customer_data, :customer => customer_hash)
query = parse_query(response)
@@ -34,14 +34,14 @@
result.should be_success
customer = Braintree::Customer.find(result.customer.id)
- customer.credit_cards.first.last_4.should == "1111"
+ customer.credit_cards.first.last_4.should == '1111'
end
end
- describe "Creating credit cards" do
- it "confirms and runs the specified request" do
+ describe 'Creating credit cards' do
+ it 'confirms and runs the specified request' do
customer = create_customer.customer
- number = "4111111111111337"
+ number = '4111111111111337'
credit_card_hash = build_credit_card_hash({ :number => number, :customer_id => customer.id})
response = post_transparent_redirect(:create_credit_card_data, :credit_card => credit_card_hash)
query = parse_query(response)
@@ -51,7 +51,7 @@
result.should be_success
customer = Braintree::Customer.find(customer.id)
- customer.credit_cards.first.last_4.should == "1111"
+ customer.credit_cards.first.last_4.should == '1111'
end
end
end
@@ -59,31 +59,31 @@
def build_customer_hash(options = {})
{
:credit_card => {
- :number => "4111111111111111",
- :expiration_date => "4/2015",
- :cardholder_name => "Susie Spender"
+ :number => '4111111111111111',
+ :expiration_date => '4/2015',
+ :cardholder_name => 'Susie Spender'
}.update(options[:credit_card] || {})
}
end
def build_credit_card_hash(options = {})
{
- :number => "4111111111111111",
- :expiration_date => "4/2015",
- :cardholder_name => "Susie Spender",
+ :number => '4111111111111111',
+ :expiration_date => '4/2015',
+ :cardholder_name => 'Susie Spender',
:cvv => '123',
:billing_address => {
- :street_address => "123 Sesame Street",
- :locality => "San Francisco",
- :region => "CA",
- :postal_code => "94110"
+ :street_address => '123 Sesame Street',
+ :locality => 'San Francisco',
+ :region => 'CA',
+ :postal_code => '94110'
}
}.update(options || {})
end
def post_transparent_redirect(type, data)
params = data.dup
- redirect_url = params.delete(:redirect_url) || "http://example.com/redirect_path"
+ redirect_url = params.delete(:redirect_url) || 'http://example.com/redirect_path'
params[:tr_data] = Braintree::TransparentRedirect.send(type, {:redirect_url => redirect_url}.merge(params))
post_transparent_redirect_params(params)
end
@@ -105,6 +105,6 @@ def parse_redirect(response)
end
def parse_query(response)
- URI.parse(response["Location"]).query
+ URI.parse(response['Location']).query
end
end
View
66 spec/fake_braintree_spec.rb
@@ -1,13 +1,13 @@
require 'spec_helper'
-describe FakeBraintree, ".decline_all_cards!" do
+describe FakeBraintree, '.decline_all_cards!' do
before { FakeBraintree.decline_all_cards! }
- it "declines all cards" do
+ it 'declines all cards' do
create_sale.should_not be_success
end
- it "stops declining cards after clear! is called" do
+ it 'stops declining cards after clear! is called' do
FakeBraintree.clear!
create_sale.should be_success
end
@@ -17,8 +17,8 @@ def create_sale
end
end
-describe FakeBraintree, ".log_file_path" do
- it "is tmp/log" do
+describe FakeBraintree, '.log_file_path' do
+ it 'is tmp/log' do
FakeBraintree.log_file_path.should == 'tmp/log'
end
end
@@ -26,36 +26,36 @@ def create_sale
describe Braintree::Configuration do
subject { Braintree::Configuration }
- it "is running in the development environment" do
+ it 'is running in the development environment' do
subject.environment.should == :development
end
- it "has some fake API credentials" do
- subject.merchant_id.should == "xxx"
- subject.public_key.should == "xxx"
- subject.private_key.should == "xxx"
+ it 'has some fake API credentials' do
+ subject.merchant_id.should == 'xxx'
+ subject.public_key.should == 'xxx'
+ subject.private_key.should == 'xxx'
end
end
describe FakeBraintree do
- it "creates a log file" do
+ it 'creates a log file' do
File.exist?(FakeBraintree.log_file_path).should == true
end
- it "logs to the correct path" do
+ it 'logs to the correct path' do
Braintree::Configuration.logger.info('Logger test')
File.readlines(FakeBraintree.log_file_path).last.should == "Logger test\n"
end
end
-describe FakeBraintree, ".clear_log!" do
- it "clears the log file" do
+describe FakeBraintree, '.clear_log!' do
+ it 'clears the log file' do
write_to_log
subject.clear_log!
- File.read(FakeBraintree.log_file_path).should == ""
+ File.read(FakeBraintree.log_file_path).should == ''
end
- it "is called by clear!" do
+ it 'is called by clear!' do
FakeBraintree.expects(:clear_log!)
FakeBraintree.clear!
end
@@ -65,8 +65,8 @@ def write_to_log
end
end
-describe FakeBraintree, "VALID_CREDIT_CARDS" do
- it "includes only credit cards that are valid in the Braintree sandbox" do
+describe FakeBraintree, 'VALID_CREDIT_CARDS' do
+ it 'includes only credit cards that are valid in the Braintree sandbox' do
FakeBraintree::VALID_CREDIT_CARDS.sort.should == valid_credit_cards.sort
end
@@ -82,46 +82,46 @@ def write_to_log
end
end
-describe FakeBraintree, ".failure_response" do
- it "can be called with no arguments" do
+describe FakeBraintree, '.failure_response' do
+ it 'can be called with no arguments' do
expect { FakeBraintree.failure_response }.not_to raise_error
end
end
-describe FakeBraintree, ".generate_transaction" do
- it "allows setting the subscription id" do
+describe FakeBraintree, '.generate_transaction' do
+ it 'allows setting the subscription id' do
transaction = FakeBraintree.generate_transaction(:subscription_id => 'foobar')
transaction['subscription_id'].should == 'foobar'
end
- it "allows setting created_at" do
+ it 'allows setting created_at' do
time = Time.now
transaction = FakeBraintree.generate_transaction(:created_at => time)
transaction['created_at'].should == time
end
- it "sets created_at to Time.now by default" do
+ it 'sets created_at to Time.now by default' do
Timecop.freeze do
transaction = FakeBraintree.generate_transaction
transaction['created_at'].should == Time.now
end
end
- it "has the correct amount" do
- transaction = FakeBraintree.generate_transaction(:amount => "20.00")
- transaction['amount'].should == "20.00"
+ it 'has the correct amount' do
+ transaction = FakeBraintree.generate_transaction(:amount => '20.00')
+ transaction['amount'].should == '20.00'
end
- it "allows no arguments" do
+ it 'allows no arguments' do
expect { FakeBraintree.generate_transaction }.not_to raise_error
end
- context "status_history" do
- it "returns a hash with a status_history key" do
+ context 'status_history' do
+ it 'returns a hash with a status_history key' do
FakeBraintree.generate_transaction(:amount => '20').should have_key('status_history')
end
- it "has a timestamp of Time.now" do
+ it 'has a timestamp of Time.now' do
Timecop.freeze do
transaction = FakeBraintree.generate_transaction(:status => Braintree::Transaction::Status::Failed,
:subscription_id => 'my_subscription_id')
@@ -129,12 +129,12 @@ def write_to_log
end
end
- it "has the desired amount" do
+ it 'has the desired amount' do
transaction = FakeBraintree.generate_transaction(:amount => '20.00')
transaction['status_history'].first['amount'].should == '20.00'
end
- it "has the desired status" do
+ it 'has the desired status' do
status = Braintree::Transaction::Status::Failed
transaction = FakeBraintree.generate_transaction(:status => status)
transaction['status_history'].first['status'].should == status
View
2  spec/spec_helper.rb
@@ -11,7 +11,7 @@ def clear_braintree_log
File.new('tmp/braintree_log', 'w').close
end
- Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
clear_braintree_log
View
2  spec/support/braintree_helpers.rb
@@ -1,7 +1,7 @@
module BraintreeHelpers
def create_braintree_customer(cc_number, expiration_date)
Braintree::Customer.create(
- :email => "me@example.com",
+ :email => 'me@example.com',
:credit_card => {
:number => cc_number,
:expiration_date => expiration_date
View
2  spec/support/matchers/clear_hash_when_cleared.rb
@@ -1,6 +1,6 @@
RSpec::Matchers.define :clear_hash_when_cleared do |property|
match do |object|
- object.send(property.to_sym)["key"] = "value"
+ object.send(property.to_sym)['key'] = 'value'
object.clear!
object.send(property.to_sym).should be_empty
end
Something went wrong with that request. Please try again.