netrecorder 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -8,4 +8,3 @@ lib/config.rb
8
8
  lib/http.rb
9
9
  lib/http_header.rb
10
10
  lib/netrecorder.rb
11
- netrecorder.gemspec
data/README.rdoc CHANGED
@@ -23,6 +23,10 @@ Record all responses:
23
23
  config.record_net_calls = true
24
24
  end
25
25
 
26
+ Save recorded responses:
27
+
28
+ NetRecorder.cache!
29
+
26
30
  Use recorded cache with fakeweb:
27
31
 
28
32
  NetRecorder.config do |config|
data/Rakefile CHANGED
@@ -2,13 +2,14 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('netrecorder', '0.1.2') do |p|
5
+ Echoe.new('netrecorder', '0.1.3') do |p|
6
6
  p.description = "Record network responses for easy stubbing of external calls"
7
- p.url = "http://github.com/tombombadil/netrecorder"
7
+ p.url = "http://github.com/chrisyoung/netrecorder"
8
8
  p.author = "Chris Young"
9
9
  p.email = "beesucker@gmail.com"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = []
11
+ p.development_dependencies = %w(echoe cucumber rspec)
12
+ p.runtime_dependencies = %w(fakeweb)
12
13
  end
13
14
 
14
15
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -9,7 +9,15 @@ Scenario: Cache a page
9
9
  When I visit "http://www.example.com"
10
10
  And I save the cache
11
11
  Then the cache should contain the example body
12
-
12
+
13
+ Scenario: Cache a page with a Net::HTTP request with a block
14
+ Given caching is turned on
15
+ And a clear cache
16
+ When I visit "http://www.example.com" using a Net::HTTP request with a block
17
+ And I save the cache
18
+ Then the cache should contain the example body
19
+ And the Net::HTTP request should return the response
20
+
13
21
  Scenario: Clear the cache
14
22
  Given caching is turned on
15
23
  Given a clear cache
@@ -2,6 +2,16 @@ require 'rubygems'
2
2
  require 'fakeweb'
3
3
  require "#{File.dirname(__FILE__)}/../../lib/netrecorder"
4
4
 
5
+ module NetRecorderMatchers
6
+ def be_the_example_dot_com_response
7
+ simple_matcher("the example.com response") do |given|
8
+ given =~ /You have reached this web page by typing.*example\.com/
9
+ end
10
+ end
11
+ end
12
+
13
+ World(NetRecorderMatchers)
14
+
5
15
  Then "caching is turned on" do
6
16
  NetRecorder.config do |config|
7
17
  config.cache_file = File.join(File.dirname(__FILE__), '..', 'support', 'cache')
@@ -13,8 +23,20 @@ And /^I save the cache$/ do
13
23
  NetRecorder.cache!
14
24
  end
15
25
 
16
- And /^I visit "([^\"]*)"$/ do |arg1|
17
- Net::HTTP.get URI.parse('http://www.example.com/')
26
+ And /^I visit "([^\"]*)"$/ do |url|
27
+ Net::HTTP.get URI.parse(url)
28
+ end
29
+
30
+ When /^I visit "([^\"]*)" using a Net::HTTP request with a block$/ do |url|
31
+ uri = URI.parse(url)
32
+ @last_response = Net::HTTP.new(uri.host, uri.port).start do |http|
33
+ http.get(uri.path.empty? ? '/' : uri.path)
34
+ end
35
+ end
36
+
37
+ Then /^the Net::HTTP request should return the response$/ do
38
+ @last_response.should_not be_nil
39
+ @last_response.body.should be_the_example_dot_com_response
18
40
  end
19
41
 
20
42
  Given /^(?:a clear cache|I delete the cache)$/ do
@@ -22,21 +44,7 @@ Given /^(?:a clear cache|I delete the cache)$/ do
22
44
  end
23
45
 
24
46
  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 &quot;example.com&quot;,
32
- &quot;example.net&quot;,
33
- or &quot;example.org&quot; 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
- }
47
+ NetRecorder.fakes.first[1][:body].first[:body].should be_the_example_dot_com_response
40
48
  end
41
49
 
42
50
  Given /^a cached example page$/ do
@@ -50,7 +58,7 @@ Then /^the cache should be empty$/ do
50
58
  end
51
59
 
52
60
  Then /^the example entry should have (.+) responses$/ do |count|
53
- NetRecorder.fakes['GET']['http://www.example.com/'].length.should == count.to_i
61
+ NetRecorder.fakes.first[1][:body].length.should == count.to_i
54
62
  end
55
63
 
56
64
  Given /^I have turned on fakeweb$/ do
data/lib/http.rb CHANGED
@@ -4,18 +4,17 @@ 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 || init_netrecorder_cache
7
+ @@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)
11
11
  response = alias_for_request(req, body)
12
12
  path = "http://#{req.bauth if req.bauth}#{req['host']}#{req.path}"
13
- if @@fakes[req.method][path]
14
- @@fakes[req.method][path] << {:body => response.body.to_s}
15
- else
16
- @@fakes[req.method][path] = [:body => response.body.to_s]
17
- end
18
- return response
13
+ existing_fake = @@fakes.select {|fake| fake[0] == path && fake[1][:method] == req.method}.first
14
+ existing_fake[1][:body] << {:body => response.body.to_s} and return response if existing_fake
15
+ @@fakes << [path, {:method => req.method, :body => [{:body => response.body.to_s}]}]
16
+ yield response if block
17
+ response
19
18
  end
20
19
 
21
20
  # returns the fakes hash
@@ -24,7 +23,7 @@ module NetRecorder
24
23
  end
25
24
 
26
25
  def self.clear_netrecorder_cache! #:nodoc:
27
- @@fakes = init_netrecorder_cache
26
+ @@fakes = []
28
27
  end
29
28
  end
30
29
  end
@@ -42,9 +41,4 @@ def fakes_cache #:nodoc:
42
41
 
43
42
  return fakes if fakes.class == Hash
44
43
  nil
45
- end
46
-
47
-
48
- def init_netrecorder_cache #:nodoc:
49
- {'GET' => {}, 'POST' => {}, 'DELETE' => {}, 'PUT' => {}}
50
- end
44
+ end
data/lib/netrecorder.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # NetRecorder allows you to record requests and responses from the web
2
2
 
3
3
  require 'fakeweb'
4
+ require 'yaml'
4
5
  require "#{File.dirname(__FILE__)}/http"
5
6
  require "#{File.dirname(__FILE__)}/http_header"
6
7
  require "#{File.dirname(__FILE__)}/config"
@@ -14,9 +15,11 @@ module NetRecorder
14
15
  end
15
16
 
16
17
  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)
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 || []
20
23
  end
21
24
 
22
25
  # configure netrecorder
@@ -24,9 +27,9 @@ module NetRecorder
24
27
  @@configured ||= nil
25
28
  @@config = Config.new
26
29
  yield @@config
30
+ record_net_calls
27
31
  clear_cache! if @@config.clear_cache
28
32
  fakeweb if @@config.fakeweb
29
- record_net_calls if @@config.record_net_calls
30
33
  end
31
34
 
32
35
  # returns true if record_net_calls is set to true in the config
@@ -50,11 +53,8 @@ module NetRecorder
50
53
  private
51
54
  # load the cache and register all of the urls with fakeweb
52
55
  def self.fakeweb
53
- fakes.each do |method, value|
54
- value.each do |url, body|
55
- path = url
56
- FakeWeb.register_uri(method.downcase.to_sym, url, body)
57
- end
56
+ fakes.each do |fake|
57
+ FakeWeb.register_uri(fake[1][:method].downcase.to_sym, fake[0], fake[1][:body])
58
58
  end
59
59
  end
60
60
 
data/netrecorder.gemspec CHANGED
@@ -2,22 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{netrecorder}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
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
- s.cert_chain = ["/Users/chrisyoung/Documents/certificates/gem-public_cert.pem"]
10
- s.date = %q{2010-01-05}
9
+ s.date = %q{2010-01-21}
11
10
  s.description = %q{Record network responses for easy stubbing of external calls}
12
11
  s.email = %q{beesucker@gmail.com}
13
12
  s.extra_rdoc_files = ["README.rdoc", "lib/config.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb"]
14
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"]
15
- s.homepage = %q{http://github.com/tombombadil/netrecorder}
14
+ s.homepage = %q{http://github.com/chrisyoung/netrecorder}
16
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netrecorder", "--main", "README.rdoc"]
17
16
  s.require_paths = ["lib"]
18
17
  s.rubyforge_project = %q{netrecorder}
19
18
  s.rubygems_version = %q{1.3.5}
20
- s.signing_key = %q{/Volumes/Secure/Certificates/gem-private_key.pem}
21
19
  s.summary = %q{Record network responses for easy stubbing of external calls}
22
20
 
23
21
  if s.respond_to? :specification_version then
@@ -25,8 +23,20 @@ Gem::Specification.new do |s|
25
23
  s.specification_version = 3
26
24
 
27
25
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<fakeweb>, [">= 0"])
27
+ s.add_development_dependency(%q<echoe>, [">= 0"])
28
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
29
+ s.add_development_dependency(%q<rspec>, [">= 0"])
28
30
  else
31
+ s.add_dependency(%q<fakeweb>, [">= 0"])
32
+ s.add_dependency(%q<echoe>, [">= 0"])
33
+ s.add_dependency(%q<cucumber>, [">= 0"])
34
+ s.add_dependency(%q<rspec>, [">= 0"])
29
35
  end
30
36
  else
37
+ s.add_dependency(%q<fakeweb>, [">= 0"])
38
+ s.add_dependency(%q<echoe>, [">= 0"])
39
+ s.add_dependency(%q<cucumber>, [">= 0"])
40
+ s.add_dependency(%q<rspec>, [">= 0"])
31
41
  end
32
42
  end
metadata CHANGED
@@ -1,39 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netrecorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Young
8
8
  autorequire:
9
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-----
10
+ cert_chain: []
32
11
 
33
- date: 2010-01-05 00:00:00 -07:00
12
+ date: 2010-01-21 00:00:00 -07:00
34
13
  default_executable:
35
- dependencies: []
36
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: fakeweb
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: cucumber
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rspec
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
37
55
  description: Record network responses for easy stubbing of external calls
38
56
  email: beesucker@gmail.com
39
57
  executables: []
@@ -59,7 +77,7 @@ files:
59
77
  - lib/netrecorder.rb
60
78
  - netrecorder.gemspec
61
79
  has_rdoc: true
62
- homepage: http://github.com/tombombadil/netrecorder
80
+ homepage: http://github.com/chrisyoung/netrecorder
63
81
  licenses: []
64
82
 
65
83
  post_install_message:
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- >ϊ�^�êƸʶ.�����n�y]��� B�)̸���=7b�J�垉=�4
metadata.gz.sig DELETED
Binary file