netrecorder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
Binary file
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ gem-public_cert.pem
5
+ lib/http.rb
6
+ lib/http_header.rb
7
+ lib/netrecorder.rb
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ == NetRecorder
2
+
3
+ Record network responses for easy stubbing of external calls.
4
+
5
+ Net recorder hooks into NetHTTP to record the outgoing request path and method and caches the response. Then you can switch on fakeweb and it will use the cache from the recording.
6
+
7
+ == Requirements
8
+
9
+ gem install fakeweb
10
+
11
+ == Install
12
+
13
+ gem install netrecorder
14
+
15
+ == Usage
16
+
17
+ Anywhere you use fakeweb, you can use net recorder.
18
+
19
+ Record all responses:
20
+
21
+ NetRecorder.config do |config|
22
+ config.cache_file = File.join(RAILS_ROOT, 'fakeweb')
23
+ config.record_net_calls = true
24
+ end
25
+
26
+ Use recorded cache with fakeweb:
27
+
28
+ NetRecorder.config do |config|
29
+ config.cache_file = File.join(RAILS_ROOT, 'features', 'support', 'fakeweb')
30
+ config.fakeweb = true
31
+ end
32
+
33
+ == Cucumber Example
34
+
35
+ see http://cukes.info for more info on testing with Cucumber
36
+
37
+ # features/support/env.rb
38
+ NetRecorder.config do |config|
39
+ config.cache_file = File.join(RAILS_ROOT, 'features', 'support', 'fakeweb')
40
+
41
+ if ENV['RECORD_NET_CALLS']
42
+ config.record_net_calls = true
43
+ else
44
+ FakeWeb.allow_net_connect = false
45
+ config.fakeweb = true
46
+ end
47
+ end
48
+
49
+ # features/support/hooks.rb
50
+ at_exit do
51
+ NetRecorder.cache! if NetRecorder.recording?
52
+ end
53
+
54
+ record mode
55
+ >> rake features RECORD_NET_CALLS=true
56
+
57
+ cache mode
58
+ >> rake features
59
+
60
+ == Todo
61
+
62
+ * RDocs
63
+ * Tests
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('netrecorder', '0.1.0') do |p|
6
+ p.description = "Record network responses for easy stubbing of external calls"
7
+ p.url = "http://github.com/tombombadil/netrecorder"
8
+ p.author = "Chris Young"
9
+ p.email = "beesucker@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApjaHJp
3
+ c3lvdW5nMRUwEwYKCZImiZPyLGQBGRYFYnV6YXoxEzARBgoJkiaJk/IsZAEZFgNj
4
+ b20wHhcNMTAwMTAxMDE0MTA2WhcNMTEwMTAxMDE0MTA2WjBBMRMwEQYDVQQDDApj
5
+ aHJpc3lvdW5nMRUwEwYKCZImiZPyLGQBGRYFYnV6YXoxEzARBgoJkiaJk/IsZAEZ
6
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDu37vOHls+p6xf
7
+ vzazqbwWkjZhh+p6t8cMhDKzMD2O+ITMSIouKg8z2DkIDtvSnkZb3pfWEC/YkZu1
8
+ 79RahOE79mSC4IB1gLeyEMmTg1TPJkNxIuoG632Sp09j2Eg8EUW1EToSFsh+gIwz
9
+ FcCBFWQ1yq0IgfQZ9+RM8a8Ei6uKfQXmm4wK6vZT5Lxp8Dv0nELoO1dkYV1WXkGh
10
+ AAFhUMX2Y9tp0x2XZztO2Z+AUL4GYD1PyU2Afh7qp/qQJZMVS0YJjulB2bnW2yn/
11
+ 7vlBadeBo3Ohp1J+OJuMUtmnuOAcKo+4cbj3HT4xTyuUa+V3izENJKX3qWCTk1D+
12
+ mU8TzNlzAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
13
+ BBSTLbhEokEPfV+oVZKmXVmGucmgljANBgkqhkiG9w0BAQUFAAOCAQEAQqRkDRig
14
+ aHqxsoqnJjG9FgZCIidnYhLNj7c3hXy8OQKJMZYau5VSDZb8dS4hC+jxQuyXiRJr
15
+ z5E16Gbqkb2fRC/YU63FnfIg2ce7PlGTp8yw0Xypn3QBYywDAWWJS4TdguikEDOM
16
+ e8IOmSKyOVJ7Zn6DIC0qyVtdcacXuKXWqqYQaWNwFwlaSlud5mQlyB77lcj5E5Lc
17
+ 2mBFwT18jFQay2vOU/lgBDXBQ/VmrgL22gnhLL2nSf++CHM8miqa39Jk2MPaTbMs
18
+ tMtvELogNijvQYORkxU83coIjJ0bIsxgbjeBoFEcWCKkq/e8uSLULcJR4nULhvR3
19
+ bIN1xy1IiuNcvw==
20
+ -----END CERTIFICATE-----
data/lib/http.rb ADDED
@@ -0,0 +1,24 @@
1
+ module NetRecorder
2
+ module NetHTTP
3
+ def self.extended(base)
4
+ base.class_eval do
5
+ alias :alias_for_request :request
6
+ @@fakes = {'GET' => {}, 'POST' => {}, 'DELETE' => {}, 'PUT' => {}}
7
+ def request(req, body = nil, &block)
8
+ response = alias_for_request(req, body)
9
+ path = "http://#{req.bauth if req.bauth}#{req['host']}#{req.path}"
10
+ if @@fakes[req.method][path]
11
+ @@fakes[req.method][path] << {:body => response.body.to_s}
12
+ else
13
+ @@fakes[req.method][path] = [:body => response.body.to_s]
14
+ end
15
+ return response
16
+ end
17
+
18
+ def self.fakes
19
+ @@fakes
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module NetRecorder
2
+ module NetHTTPHeader
3
+ def self.extended(base)
4
+ base.class_eval do
5
+ alias :alias_for_basic_auth :basic_auth
6
+ attr_accessor :bauth
7
+ def basic_auth(account, password)
8
+ @bauth = "#{account}:#{password}@"
9
+ alias_for_basic_auth(account, password)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ require 'fakeweb'
2
+ require "#{File.dirname(__FILE__)}/http"
3
+ require "#{File.dirname(__FILE__)}/http_header"
4
+
5
+ module NetRecorder
6
+ class Config
7
+ attr_accessor :record_net_calls, :fakeweb, :cache_file
8
+ end
9
+
10
+ def self.config
11
+ @@config = Config.new
12
+ yield @@config
13
+ fakeweb if @@config.fakeweb
14
+ record_net_calls if @@config.record_net_calls
15
+ end
16
+
17
+ def self.recording?
18
+ @@config.record_net_calls
19
+ end
20
+
21
+ def self.cache!
22
+ File.open(@@config.cache_file, 'w') {|f| f.write Net::HTTP.fakes.to_yaml}
23
+ end
24
+
25
+ private
26
+ def self.fakeweb
27
+ fakes = File.open(@@config.cache_file, "r") do |f|
28
+ YAML.load(f.read)
29
+ end
30
+
31
+ fakes.each do |method, value|
32
+ value.each do |url, body|
33
+ path = url
34
+ FakeWeb.register_uri(method.downcase.to_sym, url, body)
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.record_net_calls
40
+ Net::HTTP.extend(NetHTTP)
41
+ Net::HTTPHeader.extend(NetHTTPHeader)
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{netrecorder}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Chris Young"]
9
+ s.cert_chain = ["/Users/chrisyoung/Documents/certificates/gem-public_cert.pem"]
10
+ s.date = %q{2010-01-03}
11
+ s.description = %q{Record network responses for easy stubbing of external calls}
12
+ s.email = %q{beesucker@gmail.com}
13
+ s.extra_rdoc_files = ["README.rdoc", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb"]
14
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "gem-public_cert.pem", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb", "netrecorder.gemspec"]
15
+ s.homepage = %q{http://github.com/tombombadil/netrecorder}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netrecorder", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{netrecorder}
19
+ s.rubygems_version = %q{1.3.5}
20
+ s.signing_key = %q{/Volumes/Secure/Certificates/gem-private_key.pem}
21
+ s.summary = %q{Record network responses for easy stubbing of external calls}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netrecorder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Young
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApjaHJp
14
+ c3lvdW5nMRUwEwYKCZImiZPyLGQBGRYFYnV6YXoxEzARBgoJkiaJk/IsZAEZFgNj
15
+ b20wHhcNMTAwMTAxMDE0MTA2WhcNMTEwMTAxMDE0MTA2WjBBMRMwEQYDVQQDDApj
16
+ aHJpc3lvdW5nMRUwEwYKCZImiZPyLGQBGRYFYnV6YXoxEzARBgoJkiaJk/IsZAEZ
17
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDu37vOHls+p6xf
18
+ vzazqbwWkjZhh+p6t8cMhDKzMD2O+ITMSIouKg8z2DkIDtvSnkZb3pfWEC/YkZu1
19
+ 79RahOE79mSC4IB1gLeyEMmTg1TPJkNxIuoG632Sp09j2Eg8EUW1EToSFsh+gIwz
20
+ FcCBFWQ1yq0IgfQZ9+RM8a8Ei6uKfQXmm4wK6vZT5Lxp8Dv0nELoO1dkYV1WXkGh
21
+ AAFhUMX2Y9tp0x2XZztO2Z+AUL4GYD1PyU2Afh7qp/qQJZMVS0YJjulB2bnW2yn/
22
+ 7vlBadeBo3Ohp1J+OJuMUtmnuOAcKo+4cbj3HT4xTyuUa+V3izENJKX3qWCTk1D+
23
+ mU8TzNlzAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
24
+ BBSTLbhEokEPfV+oVZKmXVmGucmgljANBgkqhkiG9w0BAQUFAAOCAQEAQqRkDRig
25
+ aHqxsoqnJjG9FgZCIidnYhLNj7c3hXy8OQKJMZYau5VSDZb8dS4hC+jxQuyXiRJr
26
+ z5E16Gbqkb2fRC/YU63FnfIg2ce7PlGTp8yw0Xypn3QBYywDAWWJS4TdguikEDOM
27
+ e8IOmSKyOVJ7Zn6DIC0qyVtdcacXuKXWqqYQaWNwFwlaSlud5mQlyB77lcj5E5Lc
28
+ 2mBFwT18jFQay2vOU/lgBDXBQ/VmrgL22gnhLL2nSf++CHM8miqa39Jk2MPaTbMs
29
+ tMtvELogNijvQYORkxU83coIjJ0bIsxgbjeBoFEcWCKkq/e8uSLULcJR4nULhvR3
30
+ bIN1xy1IiuNcvw==
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2010-01-03 00:00:00 -07:00
34
+ default_executable:
35
+ dependencies: []
36
+
37
+ description: Record network responses for easy stubbing of external calls
38
+ email: beesucker@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README.rdoc
45
+ - lib/http.rb
46
+ - lib/http_header.rb
47
+ - lib/netrecorder.rb
48
+ files:
49
+ - Manifest
50
+ - README.rdoc
51
+ - Rakefile
52
+ - gem-public_cert.pem
53
+ - lib/http.rb
54
+ - lib/http_header.rb
55
+ - lib/netrecorder.rb
56
+ - netrecorder.gemspec
57
+ has_rdoc: true
58
+ homepage: http://github.com/tombombadil/netrecorder
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --line-numbers
64
+ - --inline-source
65
+ - --title
66
+ - Netrecorder
67
+ - --main
68
+ - README.rdoc
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "1.2"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: netrecorder
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Record network responses for easy stubbing of external calls
90
+ test_files: []
91
+
metadata.gz.sig ADDED
Binary file