rack-recorder 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rack/recorder.rb +11 -2
- data/rack-recorder.gemspec +2 -2
- data/spec/rack-recorder_spec.rb +35 -28
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
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
|
-
|
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
|
-
|
26
|
+
[status,ctype,body]
|
18
27
|
end
|
19
28
|
|
20
29
|
def self.revive(test_file)
|
data/rack-recorder.gemspec
CHANGED
@@ -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
|
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-
|
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 = [
|
data/spec/rack-recorder_spec.rb
CHANGED
@@ -12,38 +12,45 @@ describe "RackRecorder" do
|
|
12
12
|
TESTFILE = '/tmp/record_test.bin'
|
13
13
|
include Rack::Test::Methods
|
14
14
|
|
15
|
-
|
16
|
-
|
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
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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-
|
17
|
+
date: 2010-09-07 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|