Skip to content
This repository

Updating test suite to latest dependencies #49

Closed
wants to merge 6 commits into from

2 participants

Ryan Schlesinger Graham McIntire
Ryan Schlesinger

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.

Ryan Schlesinger

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

Ryan Schlesinger

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

Graham McIntire

@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.

Graham McIntire gmcintire closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  .gitignore
@@ -2,3 +2,5 @@ config/remote.yml
2 2
 spec/remote/remote.yml
3 3
 pkg
4 4
 .rvmrc
  5
+.bundle/
  6
+bin/
52  Gemfile.lock
@@ -18,40 +18,50 @@ GEM
18 18
       multi_json (~> 1.0)
19 19
     builder (3.0.0)
20 20
     diff-lcs (1.1.3)
21  
-    factory_girl (2.1.2)
22  
-      activesupport
  21
+    factory_girl (4.0.0)
  22
+      activesupport (>= 3.0.0)
23 23
     faker (1.0.1)
24 24
       i18n (~> 0.4)
25 25
     fakeweb (1.3.0)
  26
+    ffi (1.1.5)
26 27
     growl (1.0.3)
27  
-    guard (0.8.8)
28  
-      thor (~> 0.14.6)
29  
-    guard-rspec (0.5.0)
30  
-      guard (>= 0.8.4)
  28
+    guard (1.3.2)
  29
+      listen (>= 0.4.2)
  30
+      thor (>= 0.14.6)
  31
+    guard-rspec (1.2.1)
  32
+      guard (>= 1.1)
31 33
     i18n (0.6.0)
  34
+    listen (0.4.7)
  35
+      rb-fchange (~> 0.0.5)
  36
+      rb-fsevent (~> 0.9.1)
  37
+      rb-inotify (~> 0.8.8)
32 38
     multi_json (1.0.3)
33 39
     rake (0.9.2.2)
34  
-    rb-fsevent (0.4.3.1)
35  
-    rspec (2.7.0)
36  
-      rspec-core (~> 2.7.0)
37  
-      rspec-expectations (~> 2.7.0)
38  
-      rspec-mocks (~> 2.7.0)
39  
-    rspec-core (2.7.1)
40  
-    rspec-expectations (2.7.0)
41  
-      diff-lcs (~> 1.1.2)
42  
-    rspec-mocks (2.7.0)
43  
-    thor (0.14.6)
  40
+    rb-fchange (0.0.5)
  41
+      ffi
  42
+    rb-fsevent (0.9.1)
  43
+    rb-inotify (0.8.8)
  44
+      ffi (>= 0.5.0)
  45
+    rspec (2.11.0)
  46
+      rspec-core (~> 2.11.0)
  47
+      rspec-expectations (~> 2.11.0)
  48
+      rspec-mocks (~> 2.11.0)
  49
+    rspec-core (2.11.1)
  50
+    rspec-expectations (2.11.2)
  51
+      diff-lcs (~> 1.1.3)
  52
+    rspec-mocks (2.11.2)
  53
+    thor (0.16.0)
44 54
 
45 55
 PLATFORMS
46 56
   ruby
47 57
 
48 58
 DEPENDENCIES
49 59
   chargify_api_ares!
50  
-  factory_girl (~> 2.1.0)
  60
+  factory_girl (~> 4.0.0)
51 61
   faker (~> 1.0.1)
52 62
   fakeweb (~> 1.3.0)
53 63
   growl (~> 1.0.3)
54  
-  guard-rspec (~> 0.5.0)
55  
-  rake (~> 0.9.2)
56  
-  rb-fsevent (~> 0.4.2)
57  
-  rspec (~> 2.7.0)
  64
+  guard (~> 1.3.2)
  65
+  guard-rspec (~> 1.2.1)
  66
+  rake (~> 0.9.2.2)
  67
+  rspec (~> 2.11.0)
3  Rakefile
... ...
@@ -1,5 +1,4 @@
1  
-require 'bundler'
2  
-Bundler::GemHelper.install_tasks
  1
+require 'bundler/gem_tasks'
3 2
 require 'rspec/core/rake_task'
4 3
 
5 4
 RSpec::Core::RakeTask.new(:spec) do |t|
10  chargify_api_ares.gemspec
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
20 20
   s.add_runtime_dependency('activeresource', '>= 2.3.5')
21 21
 
22 22
   # Development Dependencies
23  
-  s.add_development_dependency('rake', '~> 0.9.2')
24  
-  s.add_development_dependency('rspec', '~> 2.7.0')
25  
-  s.add_development_dependency('factory_girl', '~> 2.1.0')
  23
+  s.add_development_dependency('rake', '~> 0.9.2.2')
  24
+  s.add_development_dependency('rspec', '~> 2.11.0')
  25
+  s.add_development_dependency('factory_girl', '~> 4.0.0')
26 26
   s.add_development_dependency('fakeweb', '~> 1.3.0')
27 27
   s.add_development_dependency('faker', '~> 1.0.1')
28  
-  s.add_development_dependency('guard-rspec', '~> 0.5.0')
  28
+  s.add_development_dependency('guard', '~> 1.3.2')
  29
+  s.add_development_dependency('guard-rspec', '~> 1.2.1')
29 30
   s.add_development_dependency('growl', '~> 1.0.3')
30  
-  s.add_development_dependency('rb-fsevent', '~> 0.4.2')
31 31
 end
4  spec/factories.rb
@@ -22,14 +22,14 @@
22 22
   factory :customer, :class => Chargify::Customer do |f|
23 23
     f.first_name { Faker::Name.first_name }
24 24
     f.last_name { Faker::Name.last_name }
25  
-    f.email { FactoryGirl.generate(:email) }
  25
+    f.email { generate(:email) }
26 26
     f.organization { Faker::Company.name }
27 27
     f.created_at { 2.days.ago }
28 28
     f.updated_at { 1.hour.ago }
29 29
   end
30 30
 
31 31
   factory :product, :class => Chargify::Product do |f|
32  
-    f.name { FactoryGirl.generate(:product_name) }
  32
+    f.name { generate(:product_name) }
33 33
   end
34 34
 
35 35
   factory :product_family, :class => Chargify::ProductFamily do |f|
11  spec/remote/spec_helper.rb → spec/remote/remote_helper.rb
... ...
@@ -1,9 +1,6 @@
1  
-require 'rubygems'
2  
-require 'rspec'
3  
-$LOAD_PATH.unshift(File.dirname(__FILE__))
4  
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
  1
+require 'spec_helper'
5 2
 
6  
-require 'chargify_api_ares'
  3
+FakeWeb.allow_net_connect = true
7 4
 
8 5
 unless File.exists?(File.join(File.dirname(__FILE__), 'remote.yml'))
9 6
   STDERR.puts "\nERROR: Make sure a remote.yml file exists at ./spec/remote/remote.yml\n\n"
@@ -11,10 +8,6 @@
11 8
 end
12 9
 
13 10
 RSpec.configure do |config|
14  
-  config.filter_run :focused => true
15  
-  config.run_all_when_everything_filtered = true
16  
-  config.alias_example_to :fit, :focused => true
17  
-  config.color_enabled = true
18 11
   config.before(:all) do
19 12
     Chargify.configure do |c|
20 13
       c.api_key = remote_configuration['api_key']
2  spec/remote/remote_spec.rb
... ...
@@ -1,4 +1,4 @@
1  
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
  1
+require 'remote/remote_helper'
2 2
 
3 3
 describe "Remote" do
4 4
 
8  spec/resources/coupon_spec.rb
... ...
@@ -1,8 +1,8 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Chargify::Coupon do
  3
+describe Chargify::Coupon, :fake_resource do
4 4
   context '.find_by_product_family_id_and_code' do
5  
-    let(:existing_coupon) { Factory.build(:coupon, :code => '20OFF') }
  5
+    let(:existing_coupon) { build(:coupon, :code => '20OFF') }
6 6
     
7 7
     before(:each) do
8 8
       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 @@
24 24
   end
25 25
   
26 26
   context '.find_all_by_product_family_id' do
27  
-    let(:coupon_1) { Factory.build(:coupon, :product_family_id => 5) }
28  
-    let(:coupon_2) { Factory.build(:coupon, :product_family_id => 5) }
  27
+    let(:coupon_1) { build(:coupon, :product_family_id => 5) }
  28
+    let(:coupon_2) { build(:coupon, :product_family_id => 5) }
29 29
     
30 30
     before do
31 31
       FakeWeb.register_uri(:get, "#{test_domain}/coupons.xml?product_family_id=5", :body => [coupon_1.attributes, coupon_2.attributes].to_xml)
2  spec/resources/customer_spec.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Chargify::Customer do
  3
+describe Chargify::Customer, :fake_resource do
4 4
   context '.find_by_reference' do
5 5
     let(:existing_customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }
6 6
 
2  spec/resources/product_family_spec.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Chargify::ProductFamily do
  3
+describe Chargify::ProductFamily, :fake_resource do
4 4
   context ".find_by_handle" do
5 5
     let(:product_family) { Chargify::ProductFamily.create(:id => 1, :handle => 'farming') }
6 6
     
2  spec/resources/product_spec.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Chargify::Product do
  3
+describe Chargify::Product, :fake_resource do
4 4
   
5 5
   context '.find_by_handle' do
6 6
     let(:existing_product) { Chargify::Product.create(:id => 2, :handle => 'green-money') }
2  spec/resources/subscription_component_spec.rb
... ...
@@ -1,6 +1,6 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Chargify::Subscription::Component do
  3
+describe Chargify::Subscription::Component, :fake_resource do
4 4
   before(:each) do
5 5
     @subscription = Chargify::Subscription.new(:id => 1)
6 6
     @sc1 = Chargify::Subscription::Component.new(
20  spec/resources/subscription_spec.rb
... ...
@@ -1,10 +1,10 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Chargify::Subscription do
  3
+describe Chargify::Subscription, :fake_resource do
4 4
   
5 5
   context 'strips nested association attributes before saving' do
6 6
     before do
7  
-      @subscription = FactoryGirl.build(:subscription_with_extra_attrs)
  7
+      @subscription = build(:subscription_with_extra_attrs)
8 8
     end
9 9
     
10 10
     it 'strips customer' do
@@ -26,15 +26,15 @@
26 26
     end
27 27
     
28 28
     it "doesn't strip other attrs" do
29  
-      subscription = FactoryGirl.build(:subscription)
  29
+      subscription = build(:subscription)
30 30
       
31 31
       lambda { subscription.save! }.should_not change(subscription, :attributes)
32 32
     end
33 33
   end
34 34
   
35 35
   it 'creates a one-time charge' do
36  
-    id = FactoryGirl.generate(:subscription_id)
37  
-    subscription = Factory(:subscription, :id => id)
  36
+    id = generate(:subscription_id)
  37
+    subscription = build(:subscription, :id => id)
38 38
     subscription.stub!(:persisted?).and_return(true)
39 39
     expected_response = {:charge => {:amount_in_cents => 1000, :memo => "one-time charge", :success => true}}.to_xml
40 40
     FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/charges.xml", :status => 201, :body => expected_response)
@@ -46,8 +46,8 @@
46 46
   end
47 47
   
48 48
   it 'finds by customer reference' do
49  
-    customer = Factory(:customer, :reference => 'roger', :id => 10)
50  
-    subscription = Factory(:subscription, :id => 11, :customer_id => customer.id, :product => Factory(:product))
  49
+    customer = build(:customer, :reference => 'roger', :id => 10)
  50
+    subscription = build(:subscription, :id => 11, :customer_id => customer.id, :product => build(:product))
51 51
     
52 52
     expected_response = [subscription.attributes].to_xml(:root => 'subscriptions')
53 53
     FakeWeb.register_uri(:get, "#{test_domain}/subscriptions.xml?customer_id=#{customer.id}", :status => 200, :body => expected_response)
@@ -57,7 +57,7 @@
57 57
   end
58 58
   
59 59
   it 'cancels the subscription' do
60  
-    @subscription = Factory(:subscription, :id => 1)
  60
+    @subscription = build(:subscription, :id => 1)
61 61
     find_subscription = lambda { Chargify::Subscription.find(1) }
62 62
     
63 63
     FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/1.xml", :body => @subscription.attributes.to_xml)
@@ -68,8 +68,8 @@
68 68
   end
69 69
 
70 70
   it 'migrates the subscription' do
71  
-    id = FactoryGirl.generate(:subscription_id)
72  
-    subscription = Factory(:subscription, :id => id)
  71
+    id = generate(:subscription_id)
  72
+    subscription = build(:subscription, :id => id)
73 73
     subscription.stub!(:persisted?).and_return(true)
74 74
     expected_response = [subscription.attributes].to_xml(:root => 'subscription')
75 75
     FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/migrations.xml?migration%5Bproduct_handle%5D=upgraded-plan", :status => 201, :body => expected_response)
10  spec/resources/usage_spec.rb
... ...
@@ -1,10 +1,10 @@
1 1
 require 'spec_helper'
2 2
 
3  
-describe Chargify::Usage do
  3
+describe Chargify::Usage, :fake_resource do
4 4
   context "create" do
5 5
     before do
6  
-      @subscription = Factory(:subscription)
7  
-      @component = Factory(:component)
  6
+      @subscription = build(:subscription)
  7
+      @component = build(:component)
8 8
       @now = DateTime.now.to_s
9 9
     end
10 10
     
@@ -24,8 +24,8 @@
24 24
   
25 25
   context "find" do
26 26
     before do
27  
-      @subscription = Factory(:subscription)
28  
-      @component = Factory(:component)
  27
+      @subscription = build(:subscription)
  28
+      @component = build(:component)
29 29
       @now = DateTime.now.to_s
30 30
     end
31 31
     
23  spec/spec_helper.rb
... ...
@@ -1,13 +1,11 @@
1 1
 $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
2 2
 
3  
-require 'chargify_api_ares'
4  
-require 'rspec'
5  
-require 'fakeweb'
  3
+require 'bundler'
  4
+Bundler.require(:default, :development)
  5
+
6 6
 require 'support/fake_resource'
7  
-require 'factory_girl'
8  
-require 'faker'
9  
-require 'factories'
10 7
 
  8
+FactoryGirl.find_definitions
11 9
 ActiveResource::Base.send :include, ActiveResource::FakeResource
12 10
 FakeWeb.allow_net_connect = false
13 11
 
@@ -19,11 +17,18 @@
19 17
 RSpec.configure do |config|
20 18
   config.filter_run :focused => true
21 19
   config.run_all_when_everything_filtered = true
  20
+  config.treat_symbols_as_metadata_keys_with_true_values = true
22 21
   config.alias_example_to :fit, :focused => true
23 22
   config.color_enabled = true
24  
-  
25  
-  config.after(:each) do
26  
-    ActiveResource::FakeResource.clean
  23
+
  24
+  config.include FactoryGirl::Syntax::Methods
  25
+
  26
+  config.before(:each, :fake_resource) do
  27
+    ActiveResource::FakeResource.enable
  28
+  end
  29
+
  30
+  config.after(:each, :fake_resource) do
  31
+    ActiveResource::FakeResource.disable
27 32
   end
28 33
 end
29 34
 
114  spec/support/fake_resource.rb
... ...
@@ -1,6 +1,6 @@
1 1
 # Taken from https://gist.github.com/238158/487a411c392e1fb2a0c00347e32444320f5cdd49
2 2
 module ActiveResource
3  
- 
  3
+
4 4
   #
5 5
   # The FakeResource fakes ActiveResources so that no real resources are transferred. It catches the creation methods
6 6
   # and stores the resources internally instead of sending to a remote service and responds these resources back on
@@ -10,71 +10,95 @@ module ActiveResource
10 10
   # fake a back end service in the BDD cycle
11 11
   #
12 12
   module FakeResource
13  
- 
  13
+    extend ActiveSupport::Concern
  14
+
14 15
     @@fake_resources = []
15  
- 
  16
+    @@enabled = false
  17
+
  18
+    def self.enable
  19
+      @@enabled = true
  20
+    end
  21
+
  22
+    def self.disable
  23
+      @@enabled = false
  24
+      self.clean
  25
+    end
  26
+
16 27
     def self.clean
17 28
       FakeWeb.clean_registry
18 29
       @@fake_resources = []
19 30
     end
20  
- 
21  
-    def self.included(base)
22  
-      base.class_eval do
23  
- 
24  
-        def save
  31
+
  32
+    included do
  33
+      def save_with_fake_resource
  34
+        if @@enabled
25 35
           @@fake_resources << self
26 36
           update_fake_responses
  37
+        else
  38
+          save_without_fake_resource
27 39
         end
28  
- 
29  
-        def destroy
  40
+      end
  41
+      alias_method_chain :save, :fake_resource
  42
+
  43
+      def destroy_with_fake_resource
  44
+        if @@enabled
30 45
           @@fake_resources.delete(self)
31 46
           update_fake_responses
  47
+        else
  48
+          destroy_without_fake_resource
32 49
         end
33  
- 
34  
-        def self.delete(id, options = {})
35  
-          puts "delete"
  50
+      end
  51
+      alias_method_chain :destroy, :fake_resource
  52
+
  53
+      def self.delete(id, options = {})
  54
+        if @@enabled
36 55
           @@fake_resources.delete_if {|r| r.id == id }
37 56
           #update_fake_responses
  57
+        else
  58
+          super
38 59
         end
39  
- 
40  
-        def self.exists?(id, options = {})
  60
+      end
  61
+
  62
+      def self.exists?(id, options = {})
  63
+        if @@enabled
41 64
           not @@fake_resources.select {|r| r.id == id}.blank?
  65
+        else
  66
+          super
42 67
         end
43  
- 
44 68
       end
45 69
     end
46  
- 
  70
+
47 71
     def save!
48  
-      save
49  
-    end
50  
-    
51  
-    def save
52  
-      super
  72
+      if @@enabled
  73
+        save
  74
+      else
  75
+        super
  76
+      end
53 77
     end
54  
- 
  78
+
55 79
     private
56  
- 
57  
-      def update_fake_responses
58  
-        FakeWeb.clean_registry
59  
- 
60  
-        @@fake_resources.each do |r|
61  
-          FakeWeb.register_uri(:get, element_uri, :body => r.to_xml)
62  
-        end
63  
- 
64  
-        FakeWeb.register_uri(:get, collection_uri, :body => @@fake_resources.to_xml)
65  
-      end
66  
- 
67  
-      def element_uri
68  
-        "#{base_uri}#{element_path}"
69  
-      end
70  
- 
71  
-      def collection_uri
72  
-        "#{base_uri}#{collection_path}"
73  
-      end
74  
- 
75  
-      def base_uri
76  
-        "#{connection.site.scheme}://#{connection.user}:#{connection.password}@#{connection.site.host}:#{connection.site.port}"
  80
+
  81
+    def update_fake_responses
  82
+      FakeWeb.clean_registry
  83
+
  84
+      @@fake_resources.each do |r|
  85
+        FakeWeb.register_uri(:get, element_uri, :body => r.to_xml)
77 86
       end
78  
- 
  87
+
  88
+      FakeWeb.register_uri(:get, collection_uri, :body => @@fake_resources.to_xml)
  89
+    end
  90
+
  91
+    def element_uri
  92
+      "#{base_uri}#{element_path}"
  93
+    end
  94
+
  95
+    def collection_uri
  96
+      "#{base_uri}#{collection_path}"
  97
+    end
  98
+
  99
+    def base_uri
  100
+      "#{connection.site.scheme}://#{connection.user}:#{connection.password}@#{connection.site.host}:#{connection.site.port}"
79 101
     end
  102
+
  103
+  end
80 104
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.