Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Updating test suite to latest dependencies #49

Closed
wants to merge 6 commits into from

2 participants

@ryansch

This updates rspec/guard/factory_girl/rake to the latest versions. This was motivated by needing a newer guard to get around rb-fsevent not building in mac os. Guard fixed this with the listen gem which deals with all of that.

multi_json and active* are not updated in this commit

This also changes the way FakeResource works; when FakeResource is included into ActiveResource::Base it is disabled by default. It can be enabled by using the :face_resource rspec metadata tag.

@ryansch ryansch referenced this pull request
Closed

Fix component create tests #51

@ryansch

@jeremywrowe Could the pulls on this gem get some love too? :smiley:

@ryansch

This probably needs to have the dependencies bumped again. Once a project maintainer shows interest I'd be happy to do it again.

@gmcintire

@ryansch go ahead and work on it again and I'll make sure it gets merged. There have been a few updates to master, so make sure you're using the lastest.

@gmcintire gmcintire closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 22, 2012
  1. @ryansch

    Updating test suite to latest dependencies

    ryansch authored
    multi_json and active* are not updated in this commit
  2. @ryansch
  3. @ryansch
Commits on Aug 28, 2012
  1. @ryansch
Commits on Aug 29, 2012
  1. @ryansch
  2. @ryansch

    Enable/Disable FakeResource

    ryansch authored
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -2,3 +2,5 @@ config/remote.yml
spec/remote/remote.yml
pkg
.rvmrc
+.bundle/
+bin/
View
52 Gemfile.lock
@@ -18,40 +18,50 @@ GEM
multi_json (~> 1.0)
builder (3.0.0)
diff-lcs (1.1.3)
- factory_girl (2.1.2)
- activesupport
+ factory_girl (4.0.0)
+ activesupport (>= 3.0.0)
faker (1.0.1)
i18n (~> 0.4)
fakeweb (1.3.0)
+ ffi (1.1.5)
growl (1.0.3)
- guard (0.8.8)
- thor (~> 0.14.6)
- guard-rspec (0.5.0)
- guard (>= 0.8.4)
+ guard (1.3.2)
+ listen (>= 0.4.2)
+ thor (>= 0.14.6)
+ guard-rspec (1.2.1)
+ guard (>= 1.1)
i18n (0.6.0)
+ listen (0.4.7)
+ rb-fchange (~> 0.0.5)
+ rb-fsevent (~> 0.9.1)
+ rb-inotify (~> 0.8.8)
multi_json (1.0.3)
rake (0.9.2.2)
- rb-fsevent (0.4.3.1)
- rspec (2.7.0)
- rspec-core (~> 2.7.0)
- rspec-expectations (~> 2.7.0)
- rspec-mocks (~> 2.7.0)
- rspec-core (2.7.1)
- rspec-expectations (2.7.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.7.0)
- thor (0.14.6)
+ rb-fchange (0.0.5)
+ ffi
+ rb-fsevent (0.9.1)
+ rb-inotify (0.8.8)
+ ffi (>= 0.5.0)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.2)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.2)
+ thor (0.16.0)
PLATFORMS
ruby
DEPENDENCIES
chargify_api_ares!
- factory_girl (~> 2.1.0)
+ factory_girl (~> 4.0.0)
faker (~> 1.0.1)
fakeweb (~> 1.3.0)
growl (~> 1.0.3)
- guard-rspec (~> 0.5.0)
- rake (~> 0.9.2)
- rb-fsevent (~> 0.4.2)
- rspec (~> 2.7.0)
+ guard (~> 1.3.2)
+ guard-rspec (~> 1.2.1)
+ rake (~> 0.9.2.2)
+ rspec (~> 2.11.0)
View
3  Rakefile
@@ -1,5 +1,4 @@
-require 'bundler'
-Bundler::GemHelper.install_tasks
+require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
View
10 chargify_api_ares.gemspec
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('activeresource', '>= 2.3.5')
# Development Dependencies
- s.add_development_dependency('rake', '~> 0.9.2')
- s.add_development_dependency('rspec', '~> 2.7.0')
- s.add_development_dependency('factory_girl', '~> 2.1.0')
+ s.add_development_dependency('rake', '~> 0.9.2.2')
+ s.add_development_dependency('rspec', '~> 2.11.0')
+ s.add_development_dependency('factory_girl', '~> 4.0.0')
s.add_development_dependency('fakeweb', '~> 1.3.0')
s.add_development_dependency('faker', '~> 1.0.1')
- s.add_development_dependency('guard-rspec', '~> 0.5.0')
+ s.add_development_dependency('guard', '~> 1.3.2')
+ s.add_development_dependency('guard-rspec', '~> 1.2.1')
s.add_development_dependency('growl', '~> 1.0.3')
- s.add_development_dependency('rb-fsevent', '~> 0.4.2')
end
View
4 spec/factories.rb
@@ -22,14 +22,14 @@
factory :customer, :class => Chargify::Customer do |f|
f.first_name { Faker::Name.first_name }
f.last_name { Faker::Name.last_name }
- f.email { FactoryGirl.generate(:email) }
+ f.email { generate(:email) }
f.organization { Faker::Company.name }
f.created_at { 2.days.ago }
f.updated_at { 1.hour.ago }
end
factory :product, :class => Chargify::Product do |f|
- f.name { FactoryGirl.generate(:product_name) }
+ f.name { generate(:product_name) }
end
factory :product_family, :class => Chargify::ProductFamily do |f|
View
11 spec/remote/spec_helper.rb → spec/remote/remote_helper.rb
@@ -1,9 +1,6 @@
-require 'rubygems'
-require 'rspec'
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
+require 'spec_helper'
-require 'chargify_api_ares'
+FakeWeb.allow_net_connect = true
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"
@@ -11,10 +8,6 @@
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']
View
2  spec/remote/remote_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'remote/remote_helper'
describe "Remote" do
View
8 spec/resources/coupon_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
-describe Chargify::Coupon do
+describe Chargify::Coupon, :fake_resource do
context '.find_by_product_family_id_and_code' do
- let(:existing_coupon) { Factory.build(:coupon, :code => '20OFF') }
+ let(:existing_coupon) { build(:coupon, :code => '20OFF') }
before(:each) do
FakeWeb.register_uri(:get, "#{test_domain}/coupons/lookup.xml?code=#{existing_coupon.code}&product_family_id=10", :body => existing_coupon.attributes.to_xml)
@@ -24,8 +24,8 @@
end
context '.find_all_by_product_family_id' do
- let(:coupon_1) { Factory.build(:coupon, :product_family_id => 5) }
- let(:coupon_2) { Factory.build(:coupon, :product_family_id => 5) }
+ let(:coupon_1) { build(:coupon, :product_family_id => 5) }
+ let(:coupon_2) { build(:coupon, :product_family_id => 5) }
before do
FakeWeb.register_uri(:get, "#{test_domain}/coupons.xml?product_family_id=5", :body => [coupon_1.attributes, coupon_2.attributes].to_xml)
View
2  spec/resources/customer_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Chargify::Customer do
+describe Chargify::Customer, :fake_resource do
context '.find_by_reference' do
let(:existing_customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }
View
2  spec/resources/product_family_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Chargify::ProductFamily do
+describe Chargify::ProductFamily, :fake_resource do
context ".find_by_handle" do
let(:product_family) { Chargify::ProductFamily.create(:id => 1, :handle => 'farming') }
View
2  spec/resources/product_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Chargify::Product do
+describe Chargify::Product, :fake_resource do
context '.find_by_handle' do
let(:existing_product) { Chargify::Product.create(:id => 2, :handle => 'green-money') }
View
2  spec/resources/subscription_component_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Chargify::Subscription::Component do
+describe Chargify::Subscription::Component, :fake_resource do
before(:each) do
@subscription = Chargify::Subscription.new(:id => 1)
@sc1 = Chargify::Subscription::Component.new(
View
20 spec/resources/subscription_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
-describe Chargify::Subscription do
+describe Chargify::Subscription, :fake_resource do
context 'strips nested association attributes before saving' do
before do
- @subscription = FactoryGirl.build(:subscription_with_extra_attrs)
+ @subscription = build(:subscription_with_extra_attrs)
end
it 'strips customer' do
@@ -26,15 +26,15 @@
end
it "doesn't strip other attrs" do
- subscription = FactoryGirl.build(:subscription)
+ subscription = build(:subscription)
lambda { subscription.save! }.should_not change(subscription, :attributes)
end
end
it 'creates a one-time charge' do
- id = FactoryGirl.generate(:subscription_id)
- subscription = Factory(:subscription, :id => id)
+ id = generate(:subscription_id)
+ subscription = build(:subscription, :id => id)
subscription.stub!(:persisted?).and_return(true)
expected_response = {:charge => {:amount_in_cents => 1000, :memo => "one-time charge", :success => true}}.to_xml
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/charges.xml", :status => 201, :body => expected_response)
@@ -46,8 +46,8 @@
end
it 'finds by customer reference' do
- customer = Factory(:customer, :reference => 'roger', :id => 10)
- subscription = Factory(:subscription, :id => 11, :customer_id => customer.id, :product => Factory(:product))
+ customer = build(:customer, :reference => 'roger', :id => 10)
+ subscription = build(:subscription, :id => 11, :customer_id => customer.id, :product => build(:product))
expected_response = [subscription.attributes].to_xml(:root => 'subscriptions')
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions.xml?customer_id=#{customer.id}", :status => 200, :body => expected_response)
@@ -57,7 +57,7 @@
end
it 'cancels the subscription' do
- @subscription = Factory(:subscription, :id => 1)
+ @subscription = build(:subscription, :id => 1)
find_subscription = lambda { Chargify::Subscription.find(1) }
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/1.xml", :body => @subscription.attributes.to_xml)
@@ -68,8 +68,8 @@
end
it 'migrates the subscription' do
- id = FactoryGirl.generate(:subscription_id)
- subscription = Factory(:subscription, :id => id)
+ id = generate(:subscription_id)
+ subscription = build(:subscription, :id => id)
subscription.stub!(:persisted?).and_return(true)
expected_response = [subscription.attributes].to_xml(:root => 'subscription')
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/migrations.xml?migration%5Bproduct_handle%5D=upgraded-plan", :status => 201, :body => expected_response)
View
10 spec/resources/usage_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
-describe Chargify::Usage do
+describe Chargify::Usage, :fake_resource do
context "create" do
before do
- @subscription = Factory(:subscription)
- @component = Factory(:component)
+ @subscription = build(:subscription)
+ @component = build(:component)
@now = DateTime.now.to_s
end
@@ -24,8 +24,8 @@
context "find" do
before do
- @subscription = Factory(:subscription)
- @component = Factory(:component)
+ @subscription = build(:subscription)
+ @component = build(:component)
@now = DateTime.now.to_s
end
View
23 spec/spec_helper.rb
@@ -1,13 +1,11 @@
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
-require 'chargify_api_ares'
-require 'rspec'
-require 'fakeweb'
+require 'bundler'
+Bundler.require(:default, :development)
+
require 'support/fake_resource'
-require 'factory_girl'
-require 'faker'
-require 'factories'
+FactoryGirl.find_definitions
ActiveResource::Base.send :include, ActiveResource::FakeResource
FakeWeb.allow_net_connect = false
@@ -19,11 +17,18 @@
RSpec.configure do |config|
config.filter_run :focused => true
config.run_all_when_everything_filtered = true
+ config.treat_symbols_as_metadata_keys_with_true_values = true
config.alias_example_to :fit, :focused => true
config.color_enabled = true
-
- config.after(:each) do
- ActiveResource::FakeResource.clean
+
+ config.include FactoryGirl::Syntax::Methods
+
+ config.before(:each, :fake_resource) do
+ ActiveResource::FakeResource.enable
+ end
+
+ config.after(:each, :fake_resource) do
+ ActiveResource::FakeResource.disable
end
end
View
114 spec/support/fake_resource.rb
@@ -1,6 +1,6 @@
# Taken from https://gist.github.com/238158/487a411c392e1fb2a0c00347e32444320f5cdd49
module ActiveResource
-
+
#
# The FakeResource fakes ActiveResources so that no real resources are transferred. It catches the creation methods
# and stores the resources internally instead of sending to a remote service and responds these resources back on
@@ -10,71 +10,95 @@ module ActiveResource
# fake a back end service in the BDD cycle
#
module FakeResource
-
+ extend ActiveSupport::Concern
+
@@fake_resources = []
-
+ @@enabled = false
+
+ def self.enable
+ @@enabled = true
+ end
+
+ def self.disable
+ @@enabled = false
+ self.clean
+ end
+
def self.clean
FakeWeb.clean_registry
@@fake_resources = []
end
-
- def self.included(base)
- base.class_eval do
-
- def save
+
+ included do
+ def save_with_fake_resource
+ if @@enabled
@@fake_resources << self
update_fake_responses
+ else
+ save_without_fake_resource
end
-
- def destroy
+ end
+ alias_method_chain :save, :fake_resource
+
+ def destroy_with_fake_resource
+ if @@enabled
@@fake_resources.delete(self)
update_fake_responses
+ else
+ destroy_without_fake_resource
end
-
- def self.delete(id, options = {})
- puts "delete"
+ end
+ alias_method_chain :destroy, :fake_resource
+
+ def self.delete(id, options = {})
+ if @@enabled
@@fake_resources.delete_if {|r| r.id == id }
#update_fake_responses
+ else
+ super
end
-
- def self.exists?(id, options = {})
+ end
+
+ def self.exists?(id, options = {})
+ if @@enabled
not @@fake_resources.select {|r| r.id == id}.blank?
+ else
+ super
end
-
end
end
-
+
def save!
- save
- end
-
- def save
- super
+ if @@enabled
+ save
+ else
+ super
+ end
end
-
+
private
-
- def update_fake_responses
- FakeWeb.clean_registry
-
- @@fake_resources.each do |r|
- FakeWeb.register_uri(:get, element_uri, :body => r.to_xml)
- end
-
- FakeWeb.register_uri(:get, collection_uri, :body => @@fake_resources.to_xml)
- end
-
- def element_uri
- "#{base_uri}#{element_path}"
- end
-
- def collection_uri
- "#{base_uri}#{collection_path}"
- end
-
- def base_uri
- "#{connection.site.scheme}://#{connection.user}:#{connection.password}@#{connection.site.host}:#{connection.site.port}"
+
+ def update_fake_responses
+ FakeWeb.clean_registry
+
+ @@fake_resources.each do |r|
+ FakeWeb.register_uri(:get, element_uri, :body => r.to_xml)
end
-
+
+ FakeWeb.register_uri(:get, collection_uri, :body => @@fake_resources.to_xml)
+ end
+
+ def element_uri
+ "#{base_uri}#{element_path}"
+ end
+
+ def collection_uri
+ "#{base_uri}#{collection_path}"
+ end
+
+ def base_uri
+ "#{connection.site.scheme}://#{connection.user}:#{connection.password}@#{connection.site.host}:#{connection.site.port}"
end
+
+ end
end
Something went wrong with that request. Please try again.