Skip to content
This repository

Fixes Issue 2 "Uninitialized class variable @@fakes" under ruby 1.9 #3

Open
wants to merge 1 commit into from

1 participant

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

Showing 1 unique commit by 1 author.

Mar 04, 2011
Sven Riedel Fix "Uninitialized class variable @@fakes" for ruby 1.9 6f9f6e5
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 6 deletions. Show diff stats Hide diff stats

  1. 13  lib/http.rb
13  lib/http.rb
@@ -4,7 +4,7 @@ module NetHTTP
4 4
     def self.extended(base) #:nodoc:
5 5
       base.class_eval do
6 6
         alias :alias_for_request :request
7  
-        @@fakes = fakes_cache || []
  7
+        class_variable_set :@@fakes, fakes_cache || []
8 8
 
9 9
         # request is overridden and the request and response are stored as a hash that can be written to a cache file
10 10
         def request(req, body = nil, &block)
@@ -18,7 +18,8 @@ def request(req, body = nil, &block)
18 18
           scope = NetRecorder.scope || 'global'
19 19
           path = "http://#{req.bauth if req.bauth}#{req['host']}#{req.path}"
20 20
           
21  
-          existing_fake = @@fakes.detect do |fake| 
  21
+          fakes = self.class.class_variable_get :@@fakes
  22
+          existing_fake = fakes.detect do |fake| 
22 23
             fake[Fake::REQUEST] == path && 
23 24
             fake[Fake::RESPONSE][scope] && 
24 25
             fake[Fake::RESPONSE][scope][:method] == req.method
@@ -27,7 +28,7 @@ def request(req, body = nil, &block)
27 28
           if existing_fake
28 29
             existing_fake[Fake::RESPONSE][scope][:response] << {:response => response}
29 30
           else
30  
-            @@fakes << [path, {scope => {:method => req.method, :response => [{:response => response}]}}]
  31
+            fakes << [path, {scope => {:method => req.method, :response => [{:response => response}]}}]
31 32
           end
32 33
 
33 34
           yield response if block
@@ -36,11 +37,11 @@ def request(req, body = nil, &block)
36 37
         
37 38
         # returns the fakes hash
38 39
         def self.fakes
39  
-          @@fakes
  40
+          class_variable_get :@@fakes
40 41
         end
41 42
         
42 43
         def self.clear_netrecorder_cache! #:nodoc:
43  
-          @@fakes = []
  44
+          class_variable_set :@@fakes, []
44 45
         end
45 46
       end
46 47
     end
@@ -58,4 +59,4 @@ def fakes_cache #:nodoc:
58 59
   
59 60
   return fakes if fakes.class == Hash
60 61
   nil
61  
-end
  62
+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.