netrecorder 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/Manifest +3 -0
- data/README.rdoc +1 -4
- data/Rakefile +1 -1
- data/features/manage_cache.feature +33 -0
- data/features/step_definitions/manage_cache_steps.rb +66 -0
- data/features/support/env.rb +1 -0
- data/lib/http.rb +12 -3
- data/lib/netrecorder.rb +10 -4
- data/netrecorder.gemspec +3 -3
- metadata +5 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/Manifest
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('netrecorder', '0.1.
|
5
|
+
Echoe.new('netrecorder', '0.1.2') do |p|
|
6
6
|
p.description = "Record network responses for easy stubbing of external calls"
|
7
7
|
p.url = "http://github.com/tombombadil/netrecorder"
|
8
8
|
p.author = "Chris Young"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Feature: Manage cache
|
2
|
+
In order to speed up my testing and avoid network calls
|
3
|
+
As a user
|
4
|
+
I want to be able to manage the cache
|
5
|
+
|
6
|
+
Scenario: Cache a page
|
7
|
+
Given caching is turned on
|
8
|
+
And a clear cache
|
9
|
+
When I visit "http://www.example.com"
|
10
|
+
And I save the cache
|
11
|
+
Then the cache should contain the example body
|
12
|
+
|
13
|
+
Scenario: Clear the cache
|
14
|
+
Given caching is turned on
|
15
|
+
Given a clear cache
|
16
|
+
And a cached example page
|
17
|
+
When I delete the cache
|
18
|
+
Then the cache should be empty
|
19
|
+
|
20
|
+
Scenario: Cache the same page twice
|
21
|
+
Given caching is turned on
|
22
|
+
And a clear cache
|
23
|
+
When I visit "http://www.example.com"
|
24
|
+
When I visit "http://www.example.com"
|
25
|
+
And I save the cache
|
26
|
+
Then the example entry should have 2 responses
|
27
|
+
|
28
|
+
Scenario: Load from a cache
|
29
|
+
Given caching is turned on
|
30
|
+
Given a clear cache
|
31
|
+
And a cached example page
|
32
|
+
And I have turned on fakeweb
|
33
|
+
Then I should not hit the web if i visit the example page
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fakeweb'
|
3
|
+
require "#{File.dirname(__FILE__)}/../../lib/netrecorder"
|
4
|
+
|
5
|
+
Then "caching is turned on" do
|
6
|
+
NetRecorder.config do |config|
|
7
|
+
config.cache_file = File.join(File.dirname(__FILE__), '..', 'support', 'cache')
|
8
|
+
config.record_net_calls = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
And /^I save the cache$/ do
|
13
|
+
NetRecorder.cache!
|
14
|
+
end
|
15
|
+
|
16
|
+
And /^I visit "([^\"]*)"$/ do |arg1|
|
17
|
+
Net::HTTP.get URI.parse('http://www.example.com/')
|
18
|
+
end
|
19
|
+
|
20
|
+
Given /^(?:a clear cache|I delete the cache)$/ do
|
21
|
+
NetRecorder.clear_cache!
|
22
|
+
end
|
23
|
+
|
24
|
+
Then /^the cache should contain the example body$/ do
|
25
|
+
NetRecorder.fakes['GET']['http://www.example.com/'].first[:body].should ==
|
26
|
+
%Q{<HTML>
|
27
|
+
<HEAD>
|
28
|
+
<TITLE>Example Web Page</TITLE>
|
29
|
+
</HEAD>
|
30
|
+
<body>
|
31
|
+
<p>You have reached this web page by typing "example.com",
|
32
|
+
"example.net",
|
33
|
+
or "example.org" into your web browser.</p>
|
34
|
+
<p>These domain names are reserved for use in documentation and are not available
|
35
|
+
for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
|
36
|
+
2606</a>, Section 3.</p>
|
37
|
+
</BODY>
|
38
|
+
</HTML>
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
Given /^a cached example page$/ do
|
43
|
+
Given "caching is turned on"
|
44
|
+
When %Q{I visit "http://www.example.com"}
|
45
|
+
And "I save the cache"
|
46
|
+
end
|
47
|
+
|
48
|
+
Then /^the cache should be empty$/ do
|
49
|
+
NetRecorder.fakes.should == nil
|
50
|
+
end
|
51
|
+
|
52
|
+
Then /^the example entry should have (.+) responses$/ do |count|
|
53
|
+
NetRecorder.fakes['GET']['http://www.example.com/'].length.should == count.to_i
|
54
|
+
end
|
55
|
+
|
56
|
+
Given /^I have turned on fakeweb$/ do
|
57
|
+
NetRecorder.config do |config|
|
58
|
+
config.cache_file = File.join(File.dirname(__FILE__), '..', 'support', 'cache')
|
59
|
+
config.fakeweb = true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Then /^I should not hit the web if i visit the example page$/ do
|
64
|
+
FakeWeb.allow_net_connect = false
|
65
|
+
Proc.new{Net::HTTP.get URI.parse('http://www.example.com/')}.should_not raise_error
|
66
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Empty for now
|
data/lib/http.rb
CHANGED
@@ -4,7 +4,7 @@ module NetRecorder
|
|
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
|
+
@@fakes = fakes_cache || init_netrecorder_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)
|
@@ -22,13 +22,17 @@ module NetRecorder
|
|
22
22
|
def self.fakes
|
23
23
|
@@fakes
|
24
24
|
end
|
25
|
+
|
26
|
+
def self.clear_netrecorder_cache! #:nodoc:
|
27
|
+
@@fakes = init_netrecorder_cache
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
|
-
|
31
|
-
def fakes_cache
|
34
|
+
|
35
|
+
def fakes_cache #:nodoc:
|
32
36
|
fakes =
|
33
37
|
if File.exist?(NetRecorder.cache_file)
|
34
38
|
File.open(NetRecorder.cache_file, "r") do |f|
|
@@ -39,3 +43,8 @@ def fakes_cache
|
|
39
43
|
return fakes if fakes.class == Hash
|
40
44
|
nil
|
41
45
|
end
|
46
|
+
|
47
|
+
|
48
|
+
def init_netrecorder_cache #:nodoc:
|
49
|
+
{'GET' => {}, 'POST' => {}, 'DELETE' => {}, 'PUT' => {}}
|
50
|
+
end
|
data/lib/netrecorder.rb
CHANGED
@@ -13,8 +13,15 @@ module NetRecorder
|
|
13
13
|
@@config.cache_file
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.fakes
|
17
|
+
File.open(@@config.cache_file, "r") do |f|
|
18
|
+
YAML.load(f.read)
|
19
|
+
end if File.exist?(@@config.cache_file)
|
20
|
+
end
|
21
|
+
|
16
22
|
# configure netrecorder
|
17
23
|
def self.config
|
24
|
+
@@configured ||= nil
|
18
25
|
@@config = Config.new
|
19
26
|
yield @@config
|
20
27
|
clear_cache! if @@config.clear_cache
|
@@ -37,15 +44,12 @@ module NetRecorder
|
|
37
44
|
if File.exist?(@@config.cache_file)
|
38
45
|
File.delete(@@config.cache_file)
|
39
46
|
end
|
47
|
+
Net::HTTP.clear_netrecorder_cache!
|
40
48
|
end
|
41
49
|
|
42
50
|
private
|
43
51
|
# load the cache and register all of the urls with fakeweb
|
44
52
|
def self.fakeweb
|
45
|
-
fakes = File.open(@@config.cache_file, "r") do |f|
|
46
|
-
YAML.load(f.read)
|
47
|
-
end
|
48
|
-
|
49
53
|
fakes.each do |method, value|
|
50
54
|
value.each do |url, body|
|
51
55
|
path = url
|
@@ -56,7 +60,9 @@ private
|
|
56
60
|
|
57
61
|
# extend NET library to record requests and responses
|
58
62
|
def self.record_net_calls
|
63
|
+
return if @@configured
|
59
64
|
Net::HTTP.extend(NetHTTP)
|
60
65
|
Net::HTTPHeader.extend(NetHTTPHeader)
|
66
|
+
@@configured = true
|
61
67
|
end
|
62
68
|
end
|
data/netrecorder.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{netrecorder}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.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.cert_chain = ["/Users/chrisyoung/Documents/certificates/gem-public_cert.pem"]
|
10
|
-
s.date = %q{2010-01-
|
10
|
+
s.date = %q{2010-01-05}
|
11
11
|
s.description = %q{Record network responses for easy stubbing of external calls}
|
12
12
|
s.email = %q{beesucker@gmail.com}
|
13
13
|
s.extra_rdoc_files = ["README.rdoc", "lib/config.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb"]
|
14
|
-
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/config.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb", "netrecorder.gemspec"]
|
14
|
+
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"]
|
15
15
|
s.homepage = %q{http://github.com/tombombadil/netrecorder}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netrecorder", "--main", "README.rdoc"]
|
17
17
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Young
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
bIN1xy1IiuNcvw==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2010-01-
|
33
|
+
date: 2010-01-05 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
35
|
dependencies: []
|
36
36
|
|
@@ -50,6 +50,9 @@ files:
|
|
50
50
|
- Manifest
|
51
51
|
- README.rdoc
|
52
52
|
- Rakefile
|
53
|
+
- features/manage_cache.feature
|
54
|
+
- features/step_definitions/manage_cache_steps.rb
|
55
|
+
- features/support/env.rb
|
53
56
|
- lib/config.rb
|
54
57
|
- lib/http.rb
|
55
58
|
- lib/http_header.rb
|
metadata.gz.sig
CHANGED
Binary file
|