netrecorder 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -5,6 +5,7 @@ features/manage_cache.feature
5
5
  features/step_definitions/manage_cache_steps.rb
6
6
  features/support/env.rb
7
7
  lib/config.rb
8
+ lib/fake.rb
8
9
  lib/http.rb
9
10
  lib/http_header.rb
10
11
  lib/netrecorder.rb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('netrecorder', '0.2.1') do |p|
5
+ Echoe.new('netrecorder', '0.2.2') do |p|
6
6
  p.description = "Record network responses for easy stubbing of external calls"
7
7
  p.url = "http://github.com/chrisyoung/netrecorder"
8
8
  p.author = "Chris Young"
data/lib/fake.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Fake
2
+ Fake::REQUEST = 0
3
+ Fake::RESPONSE = 1
4
+
5
+ def self.to_array(cache_file)
6
+ if File.exist?(cache_file)
7
+ File.open(cache_file, "r") do |f|
8
+ YAML.load(f.read)
9
+ end
10
+ end || []
11
+ end
12
+ end
data/lib/http.rb CHANGED
@@ -15,8 +15,15 @@ module NetRecorder
15
15
  scope = NetRecorder.scope || 'global'
16
16
  path = "http://#{req.bauth if req.bauth}#{req['host']}#{req.path}"
17
17
 
18
- existing_fake = @@fakes.detect{|fake| fake[0] == path && fake[1][scope] && fake[1][scope][:method] == req.method}
19
- existing_fake[1][scope][:response] << {:response => response} and return response if existing_fake
18
+ existing_fake = @@fakes.detect do |fake|
19
+ fake[Fake::REQUEST] == path &&
20
+ fake[Fake::RESPONSE][scope] &&
21
+ fake[Fake::RESPONSE][scope][:method] == req.method
22
+ end
23
+
24
+ if existing_fake
25
+ existing_fake[Fake::RESPONSE][scope][:response] << {:response => response} and return response
26
+ end
20
27
 
21
28
  @@fakes << [path, {scope => {:method => req.method, :response => [{:response => response}]}}]
22
29
  yield response if block
data/lib/netrecorder.rb CHANGED
@@ -5,6 +5,7 @@ require 'yaml'
5
5
  require "#{File.dirname(__FILE__)}/http"
6
6
  require "#{File.dirname(__FILE__)}/http_header"
7
7
  require "#{File.dirname(__FILE__)}/config"
8
+ require "#{File.dirname(__FILE__)}/fake"
8
9
 
9
10
  # NetRecorder - the global namespace
10
11
  module NetRecorder
@@ -15,11 +16,7 @@ module NetRecorder
15
16
  end
16
17
 
17
18
  def self.fakes
18
- if File.exist?(@@config.cache_file)
19
- File.open(@@config.cache_file, "r") do |f|
20
- YAML.load(f.read)
21
- end
22
- end || []
19
+ Fake.to_array(@@config.cache_file)
23
20
  end
24
21
 
25
22
  # configure netrecorder
@@ -68,9 +65,11 @@ private
68
65
  # load the cache and register all of the urls with fakeweb
69
66
  def self.fakeweb(scope='global')
70
67
  fakes.each do |fake|
71
- if fake[1][scope]
72
- FakeWeb.register_uri(fake[1][scope][:method].downcase.to_sym, fake[0], fake[1][scope][:response])
73
- end
68
+ method = fake[Fake::RESPONSE][scope][:method].downcase.to_sym
69
+ response = fake[Fake::RESPONSE][scope][:response]
70
+ request = fake[Fake::REQUEST]
71
+
72
+ FakeWeb.register_uri(method, request, response)
74
73
  end
75
74
  end
76
75
 
data/netrecorder.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{netrecorder}
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Chris Young"]
9
9
  s.date = %q{2010-04-13}
10
10
  s.description = %q{Record network responses for easy stubbing of external calls}
11
11
  s.email = %q{beesucker@gmail.com}
12
- s.extra_rdoc_files = ["README.rdoc", "lib/config.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb"]
13
- s.files = ["Manifest", "README.rdoc", "Rakefile", "features/manage_cache.feature", "features/step_definitions/manage_cache_steps.rb", "features/support/env.rb", "lib/config.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb", "netrecorder.gemspec"]
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/config.rb", "lib/fake.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "features/manage_cache.feature", "features/step_definitions/manage_cache_steps.rb", "features/support/env.rb", "lib/config.rb", "lib/fake.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb", "netrecorder.gemspec"]
14
14
  s.homepage = %q{http://github.com/chrisyoung/netrecorder}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netrecorder", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netrecorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Young
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files:
62
62
  - README.rdoc
63
63
  - lib/config.rb
64
+ - lib/fake.rb
64
65
  - lib/http.rb
65
66
  - lib/http_header.rb
66
67
  - lib/netrecorder.rb
@@ -72,6 +73,7 @@ files:
72
73
  - features/step_definitions/manage_cache_steps.rb
73
74
  - features/support/env.rb
74
75
  - lib/config.rb
76
+ - lib/fake.rb
75
77
  - lib/http.rb
76
78
  - lib/http_header.rb
77
79
  - lib/netrecorder.rb