Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't run remote specs in default rake task

- Refactor and clean up the remote specs a bit more
  • Loading branch information...
commit 969b4695a64fd1b65e8d9ea1d0b0aea530f75426 1 parent c81d5dc
@shayfrendt shayfrendt authored
View
12 Rakefile
@@ -2,5 +2,15 @@ require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
-RSpec::Core::RakeTask.new(:spec)
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = FileList['spec/**/*_spec.rb'].exclude('spec/remote/**/*')
+end
+
+namespace :spec do
+ desc "Run remote specs"
+ RSpec::Core::RakeTask.new(:remote) do |t|
+ t.pattern = FileList['spec/remote/**/*_spec.rb']
+ end
+end
+
task :default => :spec
View
7 spec/remote/remote.example.yml
@@ -1,7 +1,6 @@
# Copy this file to spec/remote/remote.yml and make adjustments as necessary.
#
# Note: Remote tests will only work when configured to run on a test site that uses the Bogus gateway.
-# Warning: all data in the site specified by 'subdomain' will be cleared and replaced with test data.
-run_tests: true
-subdomain: yoursubdomain
-api_key: xxx
+# Warning: All data in the site specified will be cleared and replaced with test data.
+api_key: your_api_key
+site: your_site
View
732 spec/remote/remote_spec.rb
@@ -1,451 +1,409 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-if run_remote_tests?
- describe "Remote" do
- before(:all) do
- clear_site_data
- setup_plans
- setup_customer
- end
-
- describe "creating a new subscription to a product with a trial" do
- context "when providing valid attributes for the customer and the payment profile" do
- before(:all) do
- @subscription = Chargify::Subscription.create(
- :product_handle => @@basic_plan.handle,
- :customer_attributes => valid_customer_attributes,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
-
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
-
- it "sets the current_period_started_at attribute to now" do
- @subscription.current_period_started_at.utc.should be_within(60).of(now.utc)
- end
-
- it "sets the current_period_ends_at attribute to 1 month from now" do
- @subscription.current_period_ends_at.utc.should be_within(60).of(one_month_from_now.utc)
- end
-
- it "is in the trialing state" do
- @subscription.state.should == 'trialing'
- end
- end
- end
-
- describe "creating a new subscription to a product without a trial" do
- context "when providing an existing customer reference and valid payment profile attributes" do
- before(:all) do
- @subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- end
-
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
-
- it "sets the current_period_started_at attribute to now" do
- @subscription.current_period_started_at.utc.should be_within(60).of(now.utc)
- end
-
- it "sets the current_period_ends_at attribute to 1 month from now" do
- @subscription.current_period_ends_at.utc.should be_within(60).of(one_month_from_now.utc)
- end
-
- it "is in the active state" do
- @subscription.state.should == 'active'
- end
-
- it "belongs to the existing customer" do
- @subscription.customer.should == @@johnadoe
- end
- end
+describe "Remote" do
- context "when providing an existing customer reference and an existing payment profile" do
- before(:all) do
- @subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_id => @@johnadoes_credit_card.id.to_s
- )
- end
-
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
-
- it "is in the active state" do
- @subscription.state.should == 'active'
- end
-
- it "belongs to the existing customer" do
- @subscription.customer.should == @@johnadoe
- end
-
- it "uses the provided credit card" do
- expected_card = Chargify::PaymentProfile.find(@@johnadoes_credit_card.id)
- @subscription.payment_profile.id.should == @@johnadoes_credit_card.id
- @subscription.payment_profile.attributes.should == expected_card.attributes
- end
- end
+ let(:acme_projects) { Chargify::ProductFamily.create(:name => "Acme Projects") }
+
+ let(:basic_plan) do
+ Chargify::Product.create(
+ :product_family_id => acme_projects.id,
+ :name => "Basic Plan",
+ :handle => "basic",
+ :price_in_cents => 1000,
+ :interval => 1,
+ :interval_unit => 'month',
+ :trial_interval => 1,
+ :trial_interval_unit => 'month',
+ :trial_price_in_cents => 0)
+ end
- context "when providing valid attributes for the customer and attributes for a credit card that cannot be stored" do
- before(:all) do
- @customer_attributes = valid_customer_attributes.dup
- @subscription = Chargify::Subscription.create(
- :product_handle => @@basic_plan.handle,
- :customer_attributes => @customer_attributes,
- :payment_profile_attributes => unstorable_payment_profile_attributes
- )
- end
-
- it "does not create the subscription" do
- @subscription.should_not be_valid
- end
+ let(:pro_plan) do
+ Chargify::Product.create(
+ :product_family_id => acme_projects.id,
+ :name => "Pro Plan",
+ :handle => "pro",
+ :price_in_cents => 5000,
+ :interval => 1,
+ :interval_unit => 'month')
+ end
+
+ let(:johnadoe) do
+ Chargify::Customer.create(
+ :first_name => "John",
+ :last_name => "Doe",
+ :email => "john.doe@example.com",
+ :reference => "johndoe")
+ end
+
+ let(:johnadoes_credit_card) { Chargify::PaymentProfile.create(good_payment_profile_attributes.merge(:customer_id => johnadoe.id)) }
+
+ before(:all) do
+ # Make sure the test site data is set up correctly
+ clear_site_data; acme_projects; basic_plan; pro_plan; johnadoe; johnadoes_credit_card
+ end
+
+ describe "creating a new subscription to a product with a trial" do
+ context "when providing valid attributes for the customer and the payment profile" do
+ before(:all) do
+ @subscription = Chargify::Subscription.create(
+ :product_handle => basic_plan.handle,
+ :customer_attributes => {
+ :first_name => "Rick",
+ :last_name => "James",
+ :email => "rick@example.com",
+ :reference => "rickjames"
+ },
+ :payment_profile_attributes => good_payment_profile_attributes)
+ end
- it "does not create the customer" do
- lambda {
- Chargify::Customer.find_by_reference(@customer_attributes[:reference])
- }.should raise_error(ActiveResource::ResourceNotFound)
- end
+ it "sets the current_period_started_at attribute to now" do
+ @subscription.current_period_started_at.utc.should be_within(60).of(now.utc)
end
- end
-
- describe "importing a subscription to a product with a trial and a next billing date 10 days from now" do
- context "when giving valid attributes for the customer and the payment profile" do
- before(:all) do
- @subscription = Chargify::Subscription.create(
- :product_handle => @@basic_plan.handle,
- :customer_attributes => valid_customer_attributes,
- :payment_profile_attributes => pretokenized_card_attributes,
- :next_billing_at => ten_days_from_now.utc
- )
- end
-
- it "successfully creates the subscription" do
- @subscription.should be_a(Chargify::Subscription)
- end
-
- it "sets the current_period_started_at attribute to now" do
- @subscription.current_period_started_at.utc.should be_within(60).of(now.utc)
- end
-
- it "sets the current_period_ends_at attribute to 1 month from now" do
- @subscription.current_period_ends_at.utc.should be_within(60).of(ten_days_from_now.utc)
- end
-
- it "is in the active state" do
- @subscription.state.should == 'active'
- end
+ it "sets the current_period_ends_at attribute to 1 month from now" do
+ @subscription.current_period_ends_at.utc.should be_within(60).of(one_month_from_now.utc)
end
- end
- describe "creating failed subscriptions" do
- context "due to providing payment profile attribtues for a card that will be declined" do
- before(:all) do
- @customer_attributes = valid_customer_attributes.dup
- @subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_attributes => @customer_attributes,
- :payment_profile_attributes => declined_payment_profile_attributes
- )
- end
-
- it "does not create the subscription" do
- @subscription.should_not be_valid
- end
-
- it "does not create the customer" do
- lambda {
- Chargify::Customer.find_by_reference(@customer_attributes[:reference])
- }.should raise_error(ActiveResource::ResourceNotFound)
- end
+ it "is in the trialing state" do
+ @subscription.state.should == 'trialing'
end
end
-
- describe "cancelling a subscription" do
+ end
+
+ describe "creating a new subscription to a product without a trial" do
+ context "when providing an existing customer reference and valid payment profile attributes" do
before(:all) do
@subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- @subscription.cancel
+ :product_handle => pro_plan.handle,
+ :customer_reference => johnadoe.reference,
+ :payment_profile_attributes => good_payment_profile_attributes)
end
-
- it "is in the canceled state" do
- Chargify::Subscription.find(@subscription.id).state.should == 'canceled'
+
+ it "sets the current_period_started_at attribute to now" do
+ @subscription.current_period_started_at.utc.should be_within(60).of(now.utc)
end
- end
-
- describe "reactivating a subscriptions" do
- before(:all) do
- @subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
- @subscription.cancel
- @subscription.reload.state.should == 'canceled'
- @subscription.reactivate
+
+ it "sets the current_period_ends_at attribute to 1 month from now" do
+ @subscription.current_period_ends_at.utc.should be_within(60).of(one_month_from_now.utc)
end
-
- it "puts it in the active state" do
- @subscription.reload.state.should == 'active'
+
+ it "is in the active state" do
+ @subscription.state.should == 'active'
+ end
+
+ it "belongs to the existing customer" do
+ @subscription.customer.should == johnadoe
end
end
-
- describe "adding a one time charge" do
+
+ context "when providing an existing customer reference and an existing payment profile" do
before(:all) do
@subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
+ :product_handle => pro_plan.handle,
+ :customer_reference => johnadoe.reference,
+ :payment_profile_id => johnadoes_credit_card.id.to_s)
end
- it "creates a charge and payment" do
- lambda{
- @subscription.charge(:amount => 7, :memo => 'One Time Charge')
- }.should change{@subscription.reload.transactions.size}.by(2)
- most_recent_transaction(@subscription).amount_in_cents.should == 700
+ it "is in the active state" do
+ @subscription.state.should == 'active'
+ end
+
+ it "belongs to the existing customer" do
+ @subscription.customer.should == johnadoe
+ end
+
+ it "uses the provided credit card" do
+ expected_card = Chargify::PaymentProfile.find(johnadoes_credit_card.id)
+ @subscription.payment_profile.id.should == johnadoes_credit_card.id
+ @subscription.payment_profile.attributes.should == expected_card.attributes
end
end
-
- describe "adding a credit" do
+
+ context "when providing valid attributes for the customer and attributes for a credit card that cannot be stored" do
before(:all) do
@subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
+ :product_handle => basic_plan.handle,
+ :customer_attributes => {
+ :first_name => "Ziggy",
+ :last_name => "Marley",
+ :email => "ziggy@example.com",
+ :reference => "ziggy"
+ },
+ :payment_profile_attributes => unstorable_payment_profile_attributes)
end
-
- it "creates a credit" do
- lambda{
- @subscription.credit(:amount => 7, :memo => 'credit')
- }.should change{@subscription.reload.transactions.size}.by(1)
- most_recent_transaction(@subscription).amount_in_cents.should == -700
+
+ it "does not create the subscription" do
+ @subscription.should_not be_valid
+ end
+
+ it "does not create the customer" do
+ lambda {
+ Chargify::Customer.find_by_reference("ziggy")
+ }.should raise_error(ActiveResource::ResourceNotFound)
end
end
-
- describe "adding a refund" do
+
+ end
+
+ describe "importing a subscription to a product with a trial and a next billing date 10 days from now" do
+ context "when giving valid attributes for the customer and the payment profile" do
before(:all) do
@subscription = Chargify::Subscription.create(
- :product_handle => @@pro_plan.handle,
- :customer_reference => @@johnadoe.reference,
- :payment_profile_attributes => good_payment_profile_attributes
- )
+ :product_handle => basic_plan.handle,
+ :customer_attributes => {
+ :first_name => "John",
+ :last_name => "Denver",
+ :email => "john.denver@example.com",
+ :reference => "johndenver"
+ },
+ :payment_profile_attributes => pretokenized_card_attributes,
+ :next_billing_at => ten_days_from_now.utc)
+ @subscription.should be_a(Chargify::Subscription)
end
- before(:each) do
- @subscription.charge(:amount => 7, :memo => 'One Time Charge')
- @subscription.reload
- @payment = most_recent_transaction(@subscription)
- @payment.transaction_type.should == 'payment'
+ it "sets the current_period_started_at attribute to now" do
+ @subscription.current_period_started_at.utc.should be_within(60).of(now.utc)
end
-
- context "via Chargify::Subscription#refund" do
- it "creates a refund" do
- lambda{
- @subscription.refund :payment_id => @payment.id, :amount => 7,
- :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
-
- tx = most_recent_transaction(@subscription)
-
- tx.amount_in_cents.should == 700
- tx.transaction_type.should == 'refund'
- end
+
+ it "sets the current_period_ends_at attribute to 1 month from now" do
+ @subscription.current_period_ends_at.utc.should be_within(60).of(ten_days_from_now.utc)
end
-
- context "via Chargify::Transaction#refund" do
- it "creates a refund" do
- lambda{
- @payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
- tx = most_recent_transaction(@subscription)
-
- tx.amount_in_cents.should == 700
- tx.transaction_type.should == 'refund'
- end
-
- it "creates a full refund" do
- lambda{
- @payment.full_refund :memo => 'Refunding One Time Charge'
- }.should change{@subscription.reload.transactions.size}.by(1)
- tx = most_recent_transaction(@subscription)
-
- tx.amount_in_cents.should == 700
- tx.transaction_type.should == 'refund'
- end
+
+ it "is in the active state" do
+ @subscription.state.should == 'active'
end
end
-
- def clear_site_data
- begin
- Chargify::Site.clear_data!
- rescue ActiveResource::ForbiddenAccess
- raise StandardError.new("Remote specs may only be run against a site in test mode")
+ end
+
+ describe "creating failed subscriptions" do
+ context "due to providing payment profile attribtues for a card that will be declined" do
+ before(:all) do
+ @subscription = Chargify::Subscription.create(
+ :product_handle => pro_plan.handle,
+ :customer_attributes => {
+ :first_name => "Frank",
+ :last_name => "Sinatra",
+ :email => "frank.sinatra@example.com",
+ :reference => "franksinatra"
+ },
+ :payment_profile_attributes => declined_payment_profile_attributes)
end
- end
- # Create Basic and Pro products in the Acme Projects family
- def setup_plans
- @@acme_projects = Chargify::ProductFamily.new(
- :name => "Acme Projects"
- )
- result = @@acme_projects.save
- result.should be_true
-
- @@basic_plan = Chargify::Product.new(
- :product_family_id => @@acme_projects.id,
- :name => "Basic Plan",
- :handle => "basic",
- :price_in_cents => 1000,
- :interval => 1,
- :interval_unit => 'month',
- :trial_interval => 1,
- :trial_interval_unit => 'month',
- :trial_price_in_cents => 0
- )
- result = @@basic_plan.save
- result.should be_true
-
- @@pro_plan = Chargify::Product.new(
- :product_family_id => @@acme_projects.id,
- :name => "Pro Plan",
- :handle => "pro",
- :price_in_cents => 5000,
- :interval => 1,
- :interval_unit => 'month'
- )
- result = @@pro_plan.save
- result.should be_true
- end
+ it "does not create the subscription" do
+ @subscription.should_not be_valid
+ end
- def setup_customer
- # Create a customer
- @@johnadoe = Chargify::Customer.new(valid_customer_attributes)
- result = @@johnadoe.save
- result.should be_true
-
- @@johnadoes_credit_card = Chargify::PaymentProfile.new(
- good_payment_profile_attributes.merge(:customer_id => @@johnadoe.id)
- )
- result = @@johnadoes_credit_card.save
- result.should be_true
- end
-
- def now
- Time.now
+ it "does not create the customer" do
+ lambda {
+ Chargify::Customer.find_by_reference("franksinatra")
+ }.should raise_error(ActiveResource::ResourceNotFound)
+ end
end
-
- def one_month_from_now
- Time.now + 1.month
+ end
+
+ describe "cancelling a subscription" do
+ before(:all) do
+ @subscription = Chargify::Subscription.create(
+ :product_handle => pro_plan.handle,
+ :customer_reference => johnadoe.reference,
+ :payment_profile_attributes => good_payment_profile_attributes)
end
-
- def ten_days_from_now
- 10.days.from_now
+
+ it "is in the canceled state" do
+ @subscription.cancel
+ Chargify::Subscription.find(@subscription.id).state.should == 'canceled'
end
-
- def valid_customer_attributes
- initial = next_customer_initial
- {
- :first_name => "John #{initial.upcase}",
- :last_name => "Doe",
- :email => "john.#{initial}.doe@example.com",
- :reference => initial
- }
+ end
+
+ describe "reactivating a subscriptions" do
+ before(:all) do
+ @subscription = Chargify::Subscription.create(
+ :product_handle => pro_plan.handle,
+ :customer_reference => johnadoe.reference,
+ :payment_profile_attributes => good_payment_profile_attributes)
end
-
- def good_payment_profile_attributes
- {
- :full_number => '1',
- :expiration_month => '12',
- :expiration_year => Time.now.year + 1
- }
+
+ it "puts it in the active state" do
+ @subscription.cancel
+ @subscription.reload.state.should == 'canceled'
+ @subscription.reactivate
+ @subscription.reload.state.should == 'active'
end
+ end
- def declined_payment_profile_attributes
- {
- :full_number => '2',
- :expiration_month => '12',
- :expiration_year => Time.now.year + 1
- }
+ describe "adding a one time charge" do
+ before(:all) do
+ @subscription = Chargify::Subscription.create(
+ :product_handle => pro_plan.handle,
+ :customer_reference => johnadoe.reference,
+ :payment_profile_attributes => good_payment_profile_attributes)
end
- def unstorable_payment_profile_attributes
- {
- :full_number => '3',
- :expiration_month => '12',
- :expiration_year => Time.now.year + 1
- }
+ it "creates a charge and payment" do
+ lambda{
+ @subscription.charge(:amount => 7, :memo => 'One Time Charge')
+ }.should change{@subscription.reload.transactions.size}.by(2)
+ most_recent_transaction(@subscription).amount_in_cents.should == 700
end
+ end
- def expired_payment_profile_attributes
- {
- :full_number => '1',
- :expiration_month => '12',
- :expiration_year => Time.now.year - 1
- }
+ describe "adding a credit" do
+ before(:all) do
+ @subscription = Chargify::Subscription.create(
+ :product_handle => pro_plan.handle,
+ :customer_reference => johnadoe.reference,
+ :payment_profile_attributes => good_payment_profile_attributes)
end
-
- def pretokenized_card_attributes
- {
- :vault_token => '1',
- :current_vault => 'bogus',
- :expiration_month => '12',
- :expiration_year => Time.now.year + 1,
- :last_four => '1234',
- :card_type => 'visa'
- }
+
+ it "creates a credit" do
+ lambda{
+ @subscription.credit(:amount => 7, :memo => 'credit')
+ }.should change{@subscription.reload.transactions.size}.by(1)
+ most_recent_transaction(@subscription).amount_in_cents.should == -700
end
-
- # Don't create more than 26 customers until we add more initials :)
- def next_customer_initial
- @@customer_initial_index ||= 0
- initial = customer_initials[@@customer_initial_index]
- @@customer_initial_index += 1
- initial
+ end
+
+ describe "adding a refund" do
+ before(:all) do
+ @subscription = Chargify::Subscription.create(
+ :product_handle => pro_plan.handle,
+ :customer_reference => johnadoe.reference,
+ :payment_profile_attributes => good_payment_profile_attributes)
end
-
- # An array of intials
- def customer_initials
- @customer_initials ||= ('a'..'z').to_a
+
+ before(:each) do
+ @subscription.charge(:amount => 7, :memo => 'One Time Charge')
+ @subscription.reload
+ @payment = most_recent_transaction(@subscription)
+ @payment.transaction_type.should == 'payment'
end
- # Allows us to create remote resources once per spec hierarchy
- def create_once(type, &block)
- hierarchy = example_group_hierarchy.collect(&:object_id).to_s
+ context "via Chargify::Subscription#refund" do
+ it "creates a refund" do
+ lambda{
+ @subscription.refund :payment_id => @payment.id, :amount => 7,
+ :memo => 'Refunding One Time Charge'
+ }.should change{@subscription.reload.transactions.size}.by(1)
+
+ tx = most_recent_transaction(@subscription)
- unless resource(type, hierarchy)
- register_resource(type, hierarchy, block.call)
+ tx.amount_in_cents.should == 700
+ tx.transaction_type.should == 'refund'
end
- resource(type, hierarchy)
end
-
- def resource(type, hierarchy)
- @@resources ||= {}
- @@resources[type] ||= {}
- @@resources[type][hierarchy]
+
+ context "via Chargify::Transaction#refund" do
+ it "creates a refund" do
+ lambda{
+ @payment.refund :amount => 7, :memo => 'Refunding One Time Charge'
+ }.should change{@subscription.reload.transactions.size}.by(1)
+ tx = most_recent_transaction(@subscription)
+
+ tx.amount_in_cents.should == 700
+ tx.transaction_type.should == 'refund'
+ end
+
+ it "creates a full refund" do
+ lambda{
+ @payment.full_refund :memo => 'Refunding One Time Charge'
+ }.should change{@subscription.reload.transactions.size}.by(1)
+ tx = most_recent_transaction(@subscription)
+
+ tx.amount_in_cents.should == 700
+ tx.transaction_type.should == 'refund'
+ end
end
-
- def register_resource(type, hierarchy, resource)
- @@resources ||= {}
- @@resources[type] ||= {}
- @@resources[type][hierarchy] = resource
+ end
+
+ def clear_site_data
+ begin
+ Chargify::Site.clear_data!
+ Chargify::Product.find(:all).count.should == 0
+ Chargify::Customer.find(:all).count.should == 0
+ Chargify::ProductFamily.find(:all).count.should == 0
+ rescue ActiveResource::ForbiddenAccess
+ raise StandardError.new("Remote specs may only be run against a site in test mode")
end
+ end
+
+ def now
+ Time.now
+ end
+
+ def one_month_from_now
+ Time.now + 1.month
+ end
+
+ def ten_days_from_now
+ 10.days.from_now
+ end
+
+ def good_payment_profile_attributes
+ {
+ :full_number => '1',
+ :expiration_month => '12',
+ :expiration_year => Time.now.year + 1
+ }
+ end
+
+ def declined_payment_profile_attributes
+ {
+ :full_number => '2',
+ :expiration_month => '12',
+ :expiration_year => Time.now.year + 1
+ }
+ end
+
+ def unstorable_payment_profile_attributes
+ {
+ :full_number => '3',
+ :expiration_month => '12',
+ :expiration_year => Time.now.year + 1
+ }
+ end
+
+ def expired_payment_profile_attributes
+ {
+ :full_number => '1',
+ :expiration_month => '12',
+ :expiration_year => Time.now.year - 1
+ }
+ end
+
+ def pretokenized_card_attributes
+ {
+ :vault_token => '1',
+ :current_vault => 'bogus',
+ :expiration_month => '12',
+ :expiration_year => Time.now.year + 1,
+ :last_four => '1234',
+ :card_type => 'visa'
+ }
+ end
+
+ # Allows us to create remote resources once per spec hierarchy
+ def create_once(type, &block)
+ hierarchy = example_group_hierarchy.collect(&:object_id).to_s
- def most_recent_transaction(scope)
- scope.transactions.sort_by(&:id).last
+ unless resource(type, hierarchy)
+ register_resource(type, hierarchy, block.call)
end
+ resource(type, hierarchy)
+ end
+
+ def resource(type, hierarchy)
+ @resources ||= {}
+ @resources[type] ||= {}
+ @resources[type][hierarchy]
+ end
+
+ def register_resource(type, hierarchy, resource)
+ @resources ||= {}
+ @resources[type] ||= {}
+ @resources[type][hierarchy] = resource
+ end
+
+ def most_recent_transaction(scope)
+ scope.transactions.sort_by(&:id).last
end
end
View
26 spec/remote/spec_helper.rb
@@ -5,7 +5,16 @@
require 'chargify_api_ares'
+unless File.exists?(File.join(File.dirname(__FILE__), 'remote.yml'))
+ STDERR.puts "\nERROR: Make sure a remote.yml file exists at ./spec/remote/remote.yml\n\n"
+ abort
+end
+
RSpec.configure do |config|
+ config.filter_run :focused => true
+ config.run_all_when_everything_filtered = true
+ config.alias_example_to :fit, :focused => true
+ config.color_enabled = true
config.before(:all) do
Chargify.configure do |c|
c.api_key = remote_configuration['api_key']
@@ -14,21 +23,8 @@
end
end
-def run_remote_tests?
- remote_configuration['run_tests'] == true
-end
-
-def remote_configuration
- @remote_configuration ||= load_remote_configuration_file
-end
-
private
-def load_remote_configuration_file
- configuration_file = File.expand_path(File.join(File.dirname(__FILE__), 'remote.yml'))
- if File.exist?(configuration_file)
- YAML.load_file(configuration_file)
- else
- {}
- end
+def remote_configuration
+ @remote_configuration ||= YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), 'remote.yml')))
end
Please sign in to comment.
Something went wrong with that request. Please try again.