rack-recorder 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.1.0
data/lib/rack/recorder.rb CHANGED
@@ -11,10 +11,19 @@ module Rack
11
11
 
12
12
  def call env
13
13
  req = Rack::Request.new(env)
14
- @all_requests << {:method => req.request_method, :body => req.body.read, :url => req.url }
14
+ request = {:method => req.request_method, :body => req.body.read, :url => req.url }
15
15
  req.body.rewind if req.body
16
+ status, ctype, body = @app.call env
17
+
18
+ response = {:status => status, :content_type => ctype['Content-Type']}
19
+ if body
20
+ response[:body] = body.read
21
+ body.rewind
22
+ end
23
+
24
+ @all_requests << { :request => request, :response => response }
16
25
  ::File.open(@file, "w") { |f| Marshal.dump(@all_requests , f) }
17
- @app.call env
26
+ [status,ctype,body]
18
27
  end
19
28
 
20
29
  def self.revive(test_file)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-recorder}
8
- s.version = "1.0.2"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Wotton"]
12
- s.date = %q{2010-09-06}
12
+ s.date = %q{2010-09-07}
13
13
  s.description = %q{a recorder AND a replayer for client actions}
14
14
  s.email = %q{mwotton@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -12,38 +12,45 @@ describe "RackRecorder" do
12
12
  TESTFILE = '/tmp/record_test.bin'
13
13
  include Rack::Test::Methods
14
14
 
15
-
16
- def app
17
- @app ||= Rack::Recorder.new(method(:parrot), :file => TESTFILE)
18
- end
19
-
15
+ let :app do Rack::Recorder.new(method(:parrot), :file => TESTFILE) end
16
+
20
17
  after { File.delete TESTFILE }
21
18
 
22
- it 'should handle binary gracefully' do
23
- bin = [1,2,3].pack('c*')
24
- post "/binary", bin
25
- Rack::Recorder.revive(TESTFILE).should ==
26
- [{ :url => 'http://example.org/binary', :method => 'POST', :body => bin } ]
19
+ context 'it should handle binary gracefully' do
20
+ before do
21
+ @bin = [1,2,3].pack('c*')
22
+ post "/binary", @bin
23
+ end
24
+
25
+ specify do
26
+ Rack::Recorder.revive(TESTFILE).should ==
27
+ [ { :request => { :url => 'http://example.org/binary', :method => 'POST', :body => @bin},
28
+ :response => { :status => 200, :body => @bin, :content_type => 'text/plain' } }]
29
+ end
30
+
27
31
  end
28
32
 
29
- it 'should preserve the body' do
30
- post "/botulism", "foo"
31
- last_response.should be_ok
32
- last_response.body.should == "foo"
33
+ context 'should preserve the body' do
34
+ before do post "/botulism", "foo" end
35
+ specify { last_response.should be_ok }
36
+ specify { last_response.body.should == "foo" }
33
37
  end
34
-
35
- it 'should record a sequence' do
36
- get "/"
37
- get "/fooo/bar?baz=quux"
38
- post "/botulism", "foo"
39
-
40
- Rack::Recorder.revive(TESTFILE).should ==
41
- [ { :url => 'http://example.org/', :method => 'GET', :body => ''},
42
- { :url => 'http://example.org/fooo/bar?baz=quux', :method => 'GET', :body => ''},
43
- { :url => 'http://example.org/botulism', :method => 'POST', :body => 'foo' } ]
38
+
39
+ context 'should record a sequence' do
40
+ before do
41
+ get "/"
42
+ get "/fooo/bar?baz=quux"
43
+ post "/botulism", "foo"
44
+ end
45
+
46
+ specify do
47
+ Rack::Recorder.revive(TESTFILE).should ==
48
+ [ { :request => { :url => 'http://example.org/', :method => 'GET', :body => ''},
49
+ :response => { :status => 200, :body => '', :content_type => 'text/plain' } },
50
+ { :request => { :url => 'http://example.org/fooo/bar?baz=quux', :method => 'GET', :body => ''},
51
+ :response => { :status => 200, :body => '', :content_type => 'text/plain' } },
52
+ { :request => { :url => 'http://example.org/botulism', :method => 'POST', :body => 'foo' },
53
+ :response => { :status => 200, :body => 'foo', :content_type => 'text/plain' } }]
54
+ end
44
55
  end
45
56
  end
46
-
47
-
48
-
49
-
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 2
9
- version: 1.0.2
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Wotton
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-06 00:00:00 +10:00
17
+ date: 2010-09-07 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency