rack-recorder 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mark Wotton
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,34 @@
1
+ = rack-recorder
2
+
3
+ This is a middleware for recording client interactions with a Rack app.
4
+ In my case, this was useful because I wanted to capture the payloads
5
+ going back and forth from an iPhone app to which I didn't have the source
6
+ in order to create a regression test.
7
+
8
+ This is almost the dual of the VCR project at http://github.com/myronmarston/vcr -
9
+ instead of recording outgoing requests, we record incoming ones.
10
+
11
+
12
+ == Usage
13
+
14
+ use Rack::Recorder, :file => "/tmp/my_requests.bin"
15
+
16
+
17
+ you can recover the information from the binary with Marshal.load - next addition
18
+ will be some integration with Rack::Test
19
+
20
+ Description goes here.
21
+
22
+ == Note on Patches/Pull Requests
23
+
24
+ * Fork the project.
25
+ * Make your feature addition or bug fix.
26
+ * Add tests for it. This is important so I don't break it in a
27
+ future version unintentionally.
28
+ * Commit, do not mess with rakefile, version, or history.
29
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
30
+ * Send me a pull request. Bonus points for topic branches.
31
+
32
+ == Copyright
33
+
34
+ Copyright (c) 2010 Mark Wotton. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rack-recorder"
8
+ gem.summary = %Q{a recorder for client actions}
9
+ gem.description = %Q{a recorder AND a replayer for client actions}
10
+ gem.email = "mwotton@gmail.com"
11
+ gem.homepage = "http://github.com/kodev/rack-recorder"
12
+ gem.authors = ["Mark Wotton"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "rack-test"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "rack-recorder #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,25 @@
1
+
2
+ module Rack
3
+
4
+ class Recorder
5
+
6
+ def initialize(app, options)
7
+ @app = app
8
+ @file = options[:file] or raise "must pass :file argument to Rack::Recorder"
9
+ @all_requests = []
10
+ end
11
+
12
+ def call env
13
+ req = Rack::Request.new(env)
14
+ @all_requests << {:method => req.request_method, :body => req.body.read, :url => req.url }
15
+ req.body.rewind if req.body
16
+ ::File.open(@file, "w") { |f| Marshal.dump(@all_requests , f) }
17
+ @app.call env
18
+ end
19
+
20
+ def self.revive(test_file)
21
+ ::File.open(test_file, 'r') { |f| Marshal.load(f) }
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ require 'rack/recorder'
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack-recorder}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mark Wotton"]
12
+ s.date = %q{2010-09-06}
13
+ s.description = %q{a recorder AND a replayer for client actions}
14
+ s.email = %q{mwotton@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rack-recorder.rb",
27
+ "lib/rack/recorder.rb",
28
+ "rack-recorder.gemspec",
29
+ "spec/rack-recorder_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/kodev/rack-recorder}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{a recorder for client actions}
38
+ s.test_files = [
39
+ "spec/rack-recorder_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
49
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
+ s.add_dependency(%q<rack-test>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ s.add_dependency(%q<rack-test>, [">= 0"])
57
+ end
58
+ end
59
+
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'rack-recorder'
4
+ require 'rack/test'
5
+
6
+ # stolen from rack-cache
7
+ def parrot(env)
8
+ [ 200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).body]
9
+ end
10
+
11
+ describe "RackRecorder" do
12
+ TESTFILE = '/tmp/record_test.bin'
13
+ include Rack::Test::Methods
14
+
15
+
16
+ def app
17
+ @app ||= Rack::Recorder.new(method(:parrot), :file => TESTFILE)
18
+ end
19
+
20
+ after { File.delete TESTFILE }
21
+
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 } ]
27
+ end
28
+
29
+ it 'should preserve the body' do
30
+ post "/botulism", "foo"
31
+ last_response.should be_ok
32
+ last_response.body.should == "foo"
33
+ 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' } ]
44
+ end
45
+ end
46
+
47
+
48
+
49
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rack-recorder'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-recorder
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Mark Wotton
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-06 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack-test
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: a recorder AND a replayer for client actions
49
+ email: mwotton@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.rdoc
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - lib/rack-recorder.rb
65
+ - lib/rack/recorder.rb
66
+ - rack-recorder.gemspec
67
+ - spec/rack-recorder_spec.rb
68
+ - spec/spec.opts
69
+ - spec/spec_helper.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/kodev/rack-recorder
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.7
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: a recorder for client actions
102
+ test_files:
103
+ - spec/rack-recorder_spec.rb
104
+ - spec/spec_helper.rb