request-replay 0.5.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fed9befd2767e2187ba5c002096edc93bdf56ba4
4
- data.tar.gz: 692df92970d3270b99ab777169ac8ed3c745061d
3
+ metadata.gz: 74c29ee7f631fdfaaddd0bcde2083d204a7123b9
4
+ data.tar.gz: 9ea9ce6b5e376a5fb7ea32a898b996aed9696b73
5
5
  SHA512:
6
- metadata.gz: 201f1958a8a731326adf374bb76c5e73224bb1192b3b48a894b451ba12b26da28b7a286b980578ec393dcda494248239b1d78f07a190912c0940296a59acfb7b
7
- data.tar.gz: 4be362294e1bb716f8c39e712f892720159279e98a32c1905454c60a61a96a3e4d45582f6d5f3549ac831ac8f8b3c914be2f1834cabb83d8c9e2235d1ee4130e
6
+ metadata.gz: 29ee655a7da33ac820fa14fe8e7af2f517135ff500790437b7cbfb2d2f4f71c188943e73ad834cfdcb723467bd91d56294d075df454b7c8744487c257202dc9b
7
+ data.tar.gz: 2de2ed416688b4b8d2cbc3a368cabf1b7b7f9587ee736b1ae0b2725bbcd4af4a0dc46059b1b595d7978ea97bcc0222631f7926072ce6e50fdf02a26c5bd6bba9
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
- pkg
1
+ /pkg/
2
2
  *.rbc
data/CHANGES.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGES
2
2
 
3
+ ## request-replay 0.6.0 -- 2013-10-01
4
+
5
+ * Added :read_wait option for waiting for the remote server responding.
6
+ * Changed the API a bit. Now pass :add_headers for adding some extra
7
+ headers to the replaying request. Useful for passing another Host or
8
+ a special User-Agent.
9
+
3
10
  ## request-replay 0.5.0 -- 2013-09-04
4
11
 
5
12
  * Birthday!
data/README.md CHANGED
@@ -30,7 +30,9 @@ overwrite in the original request.
30
30
 
31
31
  ``` ruby
32
32
  require 'request-replay'
33
- use RequestReplay::Middleware, 'localhost:8080', 'Host' => 'example.com'
33
+ use RequestReplay::Middleware, 'localhost:8080',
34
+ :add_headers => {'Host' => 'example.com'},
35
+ :read_wait => 5
34
36
  run lambda{ |env| [200, {}, [env.inspect]] }
35
37
  ```
36
38
 
@@ -39,17 +41,18 @@ It's effectively the same as:
39
41
  ``` ruby
40
42
  require 'request-replay'
41
43
  use Class.new{
42
- def initialize app, host, headers={}
43
- @app, @host, @headers = app, host, headers
44
+ def initialize app, host, options={}
45
+ @app, @host, @options = app, host, options
44
46
  end
45
47
 
46
48
  def call env
47
49
  # We don't want to read the socket in a thread, so create it in main
48
50
  # thread, and send the data in a thread as we don't care the responses
49
- Thread.new(RequestReplay.new(env, @host, @headers), &:start)
51
+ Thread.new(RequestReplay.new(env, @host, @options), &:start)
50
52
  @app.call(env)
51
53
  end
52
- }, 'localhost:8080', 'Host' => 'example.com'
54
+ }, 'localhost:8080', :add_headers => {'Host' => 'example.com'},
55
+ :read_wait => 5
53
56
  run lambda{ |env| [200, {}, [env.inspect]] }
54
57
  ```
55
58
 
data/Rakefile CHANGED
@@ -3,20 +3,11 @@ begin
3
3
  require "#{dir = File.dirname(__FILE__)}/task/gemgem"
4
4
  rescue LoadError
5
5
  sh 'git submodule update --init'
6
- exec Gem.ruby, '-S', 'rake', *ARGV
6
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
7
  end
8
8
 
9
- Gemgem.dir = dir
10
- ($LOAD_PATH << File.expand_path("#{Gemgem.dir}/lib")).uniq!
11
-
12
- desc 'Generate gemspec'
13
- task 'gem:spec' do
14
- Gemgem.spec = Gemgem.create do |s|
15
- s.name = 'request-replay'
16
- s.version = '0.5.0'
17
-
18
- %w[bacon rack].each{ |g| s.add_development_dependency(g) }
19
- end
20
-
21
- Gemgem.write
9
+ Gemgem.init(dir) do |s|
10
+ s.name = 'request-replay'
11
+ s.version = '0.6.0'
12
+ %w[bacon muack rack].each{ |g| s.add_development_dependency(g) }
22
13
  end
@@ -2,14 +2,14 @@
2
2
  require 'request-replay'
3
3
 
4
4
  class RequestReplay::Middleware
5
- def initialize app, host, headers={}
6
- @app, @host, @headers = app, host, headers
5
+ def initialize app, host, options={}
6
+ @app, @host, @options = app, host, options
7
7
  end
8
8
 
9
9
  def call env
10
10
  # We don't want to read the socket in a thread, so create it in main
11
11
  # thread, and send the data in a thread as we don't care the responses
12
- Thread.new(RequestReplay.new(env, @host, @headers), &:start)
12
+ Thread.new(RequestReplay.new(env, @host, @options), &:start)
13
13
  @app.call(env)
14
14
  end
15
15
  end
@@ -9,8 +9,8 @@ class RequestReplay
9
9
  HTTP_VERSION = 'HTTP/1.1'
10
10
  RACK_INPUT = 'rack.input'
11
11
 
12
- def initialize env, host, addhead={}
13
- @env, (@host, @port), @addhead = env, host.split(':', 2), addhead
12
+ def initialize env, host, options={}
13
+ @env, (@host, @port), @options = env, host.split(':', 2), options
14
14
  if env[RACK_INPUT]
15
15
  env[RACK_INPUT].rewind
16
16
  @buf = StringIO.new
@@ -19,10 +19,20 @@ class RequestReplay
19
19
  end
20
20
  end
21
21
 
22
+ def add_headers
23
+ @options[:add_headers] || {}
24
+ end
25
+
26
+ def read_wait
27
+ @options[:read_wait] && Float(@options[:read_wait])
28
+ end
29
+
22
30
  def start
23
31
  write_request
24
32
  write_headers
25
33
  write_payload
34
+ sock.close_write
35
+ IO.select([sock], [], [], read_wait) if read_wait
26
36
  yield(sock) if block_given?
27
37
  ensure
28
38
  sock.close
@@ -42,7 +52,7 @@ class RequestReplay
42
52
  end
43
53
 
44
54
  def request
45
- "#{@env['REQUEST_METHOD']} #{request_path} #{HTTP_VERSION}"
55
+ "#{@env['REQUEST_METHOD'] || 'GET'} #{request_path} #{HTTP_VERSION}"
46
56
  end
47
57
 
48
58
  def headers
@@ -61,8 +71,7 @@ class RequestReplay
61
71
  r
62
72
  }.merge('Content-Type' => @env['CONTENT_TYPE' ],
63
73
  'Content-Length' => @env['CONTENT_LENGTH']).
64
- merge(@addhead).
65
- select{ |_, v| v }
74
+ merge(add_headers).select{ |_, v| v }
66
75
  end
67
76
 
68
77
  def capitalize_headers header
@@ -1,12 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: request-replay 0.6.0 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "request-replay"
5
- s.version = "0.5.0"
6
+ s.version = "0.6.0"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
9
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2013-09-04"
10
+ s.date = "2013-10-01"
10
11
  s.description = "Replay the request via Rack env"
11
12
  s.email = ["godfat (XD) godfat.org"]
12
13
  s.files = [
@@ -27,7 +28,7 @@ Gem::Specification.new do |s|
27
28
  s.homepage = "https://github.com/godfat/request-replay"
28
29
  s.licenses = ["Apache License 2.0"]
29
30
  s.require_paths = ["lib"]
30
- s.rubygems_version = "2.0.7"
31
+ s.rubygems_version = "2.1.5"
31
32
  s.summary = "Replay the request via Rack env"
32
33
  s.test_files = ["test/test_basic.rb"]
33
34
 
@@ -36,13 +37,16 @@ Gem::Specification.new do |s|
36
37
 
37
38
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
39
  s.add_development_dependency(%q<bacon>, [">= 0"])
40
+ s.add_development_dependency(%q<muack>, [">= 0"])
39
41
  s.add_development_dependency(%q<rack>, [">= 0"])
40
42
  else
41
43
  s.add_dependency(%q<bacon>, [">= 0"])
44
+ s.add_dependency(%q<muack>, [">= 0"])
42
45
  s.add_dependency(%q<rack>, [">= 0"])
43
46
  end
44
47
  else
45
48
  s.add_dependency(%q<bacon>, [">= 0"])
49
+ s.add_dependency(%q<muack>, [">= 0"])
46
50
  s.add_dependency(%q<rack>, [">= 0"])
47
51
  end
48
52
  end
data/task/gemgem.rb CHANGED
@@ -1,14 +1,26 @@
1
1
 
2
- require 'pathname'
3
-
4
2
  module Gemgem
5
3
  class << self
6
- attr_accessor :dir, :spec
4
+ attr_accessor :dir, :spec, :spec_create
7
5
  end
8
6
 
9
7
  module_function
8
+ def gem_tag ; "#{spec.name}-#{spec.version}" ; end
9
+ def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
10
+ def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
11
+ def pkg_dir ; "#{dir}/pkg" ; end
12
+ def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
+
14
+ def init dir, &block
15
+ self.dir = dir
16
+ $LOAD_PATH.unshift("#{dir}/lib")
17
+ ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
+ ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
19
+ self.spec_create = block
20
+ end
21
+
10
22
  def create
11
- yield(spec = Gem::Specification.new{ |s|
23
+ spec = Gem::Specification.new do |s|
12
24
  s.authors = ['Lin Jen-Shin (godfat)']
13
25
  s.email = ['godfat (XD) godfat.org']
14
26
 
@@ -16,163 +28,146 @@ module Gemgem
16
28
  s.summary = description.first
17
29
  s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
18
30
 
19
- s.rubygems_version = Gem::VERSION
20
- s.date = Time.now.strftime('%Y-%m-%d')
21
- s.files = gem_files
22
- s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
23
- s.executables = Dir['bin/*'].map{ |f| File.basename(f) }
24
- s.require_paths = %w[lib]
25
- })
26
- spec.homepage ||= "https://github.com/godfat/#{spec.name}"
27
- spec
31
+ s.date = Time.now.strftime('%Y-%m-%d')
32
+ s.files = gem_files
33
+ s.test_files = test_files
34
+ s.executables = bin_files
35
+ end
36
+ spec_create.call(spec)
37
+ spec.homepage = "https://github.com/godfat/#{spec.name}"
38
+ self.spec = spec
28
39
  end
29
40
 
30
- def readme
31
- path = %w[README.md README].find{ |name|
32
- File.exist?("#{Gemgem.dir}/#{name}")
33
- }
34
- @readme ||=
35
- if path
36
- ps = "##{File.read(path)}".
37
- scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
38
- ps.inject('HEADER' => ps.first){ |r, s, i|
39
- r[s[/\w+/]] = s
40
- r
41
- }
41
+ def write
42
+ File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
43
+ end
44
+
45
+ def split_lines ruby
46
+ ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
47
+ if $2.index(',')
48
+ "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
42
49
  else
43
- {}
50
+ s
44
51
  end
52
+ }
45
53
  end
46
54
 
47
- def description
48
- @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines
55
+ def strip_path path
56
+ strip_home_path(strip_cwd_path(path))
49
57
  end
50
58
 
51
- def changes
52
- path = %w[CHANGES.md CHANGES].find{ |name|
53
- File.exist?("#{Gemgem.dir}/#{name}")
54
- }
55
- @changes ||=
56
- if path
57
- date = '\d+{4}\-\d+{2}\-\d{2}'
58
- File.read(path).match(
59
- /([^\n]+#{date}\n\n(.+?))(?=\n\n[^\n]+#{date}\n|\Z)/m)[1]
60
- else
61
- ''
62
- end
59
+ def strip_home_path path
60
+ path.sub(ENV['HOME'], '~')
63
61
  end
64
62
 
65
- def ann_md
66
- "#{readme['HEADER'].sub(/([\w\-]+)/, "[\\1](#{spec.homepage})")}\n\n" \
67
- "##{readme['DESCRIPTION'][/[^\n]+\n\n[^\n]+/]}\n\n" \
68
- "### CHANGES:\n\n" \
69
- "###{changes}\n\n" \
70
- "##{readme['INSTALLATION']}\n\n" +
71
- if readme['SYNOPSIS'] then "##{readme['SYNOPSIS'][/[^\n]+\n\n[^\n]+/]}"
72
- else '' end
63
+ def strip_cwd_path path
64
+ path.sub(Dir.pwd, '.')
73
65
  end
74
66
 
75
- def ann_html
76
- gem 'nokogiri'
77
- gem 'kramdown'
78
-
79
- IO.popen('kramdown', 'r+') do |md|
80
- md.puts Gemgem.ann_md
81
- md.close_write
82
- require 'nokogiri'
83
- html = Nokogiri::XML.parse("<gemgem>#{md.read}</gemgem>")
84
- html.css('*').each{ |n| n.delete('id') }
85
- html.root.children.to_html
86
- end
67
+ def git *args
68
+ `git --git-dir=#{dir}/.git #{args.join(' ')}`
87
69
  end
88
70
 
89
- def ann_email
90
- "#{readme['HEADER'].sub(/([\w\-]+)/, "\\1 <#{spec.homepage}>")}\n\n" \
91
- "#{readme['DESCRIPTION']}\n\n" \
92
- "#{readme['INSTALLATION']}\n\n" +
93
- if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}\n\n" else '' end +
94
- "## CHANGES:\n\n" \
95
- "##{changes}\n\n"
71
+ def sh_git *args
72
+ Rake.sh('git', "--git-dir=#{dir}/.git", *args)
96
73
  end
97
74
 
98
- def gem_tag
99
- "#{spec.name}-#{spec.version}"
75
+ def sh_gem *args
76
+ Rake.sh(Gem.ruby, '-S', 'gem', *args)
100
77
  end
101
78
 
102
- def write
103
- File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
104
- f << split_lines(spec.to_ruby) }
79
+ def glob path=dir
80
+ Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
105
81
  end
106
82
 
107
- def split_lines ruby
108
- ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
109
- if $2.index(',')
110
- "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
83
+ def readme
84
+ @readme ||=
85
+ if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
86
+ ps = "##{File.read(path)}".
87
+ scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
88
+ ps.inject('HEADER' => ps.first){ |r, s, i|
89
+ r[s[/\w+/]] = s
90
+ r
91
+ }
111
92
  else
112
- s
93
+ {}
113
94
  end
114
- }
95
+ end
96
+
97
+ def description
98
+ # JRuby String#lines is returning an enumerator
99
+ @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
115
100
  end
116
101
 
117
102
  def all_files
118
- @all_files ||= find_files(Pathname.new(dir)).map{ |file|
119
- if file.to_s =~ %r{\.git/|\.git$}
120
- nil
103
+ @all_files ||= fold_files(glob).sort
104
+ end
105
+
106
+ def fold_files files
107
+ files.inject([]){ |r, path|
108
+ if File.file?(path) && path !~ %r{/\.git(/|$)} &&
109
+ (rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
110
+ r << rpath
111
+ elsif File.symlink?(path) # walk into symlinks...
112
+ r.concat(fold_files(glob(File.expand_path(path,
113
+ File.readlink(path)))))
121
114
  else
122
- file.to_s
115
+ r
123
116
  end
124
- }.compact.sort
117
+ }
125
118
  end
126
119
 
127
120
  def gem_files
128
- @gem_files ||= all_files - ignored_files
121
+ @gem_files ||= all_files.reject{ |f|
122
+ f =~ ignored_pattern && !git_files.include?(f)
123
+ }
129
124
  end
130
125
 
131
- def ignored_files
132
- @ignored_file ||= all_files.select{ |path| ignore_patterns.find{ |ignore|
133
- path =~ ignore && !git_files.include?(path)}}
126
+ def test_files
127
+ @test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
128
+ end
129
+
130
+ def bin_files
131
+ @bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
134
132
  end
135
133
 
136
134
  def git_files
137
135
  @git_files ||= if File.exist?("#{dir}/.git")
138
- `git ls-files`.split("\n")
136
+ git('ls-files').split("\n")
139
137
  else
140
138
  []
141
139
  end
142
140
  end
143
141
 
144
- # protected
145
- def find_files path
146
- path.children.select(&:file?).map{|file| file.to_s[(dir.size+1)..-1]} +
147
- path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten
142
+ def ignored_files
143
+ @ignored_files ||= all_files.grep(ignored_pattern)
148
144
  end
149
145
 
150
- def ignore_patterns
151
- @ignore_files ||= expand_patterns(
152
- gitignore.split("\n").reject{ |pattern|
153
- pattern.strip == ''
154
- }).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} }
146
+ def ignored_pattern
147
+ @ignored_pattern ||= Regexp.new(expand_patterns(gitignore).join('|'))
155
148
  end
156
149
 
157
150
  def expand_patterns pathes
158
- pathes.map{ |path|
159
- if path !~ /\*/
160
- path
161
- else
162
- expand_patterns(
163
- Dir[path] +
164
- Pathname.new(File.dirname(path)).children.select(&:directory?).
165
- map{ |prefix| "#{prefix}/#{File.basename(path)}" })
151
+ # http://git-scm.com/docs/gitignore
152
+ pathes.flat_map{ |path|
153
+ case path
154
+ when %r{\*}
155
+ Regexp.escape(path).gsub(/\\\*/, '[^/]*')
156
+ when %r{^/}
157
+ "^#{Regexp.escape(path[1..-1])}"
158
+ else # we didn't implement negative pattern for now
159
+ Regexp.escape(path)
166
160
  end
167
- }.flatten
161
+ }
168
162
  end
169
163
 
170
164
  def gitignore
171
- if File.exist?(path = "#{dir}/.gitignore")
172
- File.read(path)
173
- else
174
- ''
175
- end
165
+ @gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
166
+ File.read(path).lines.
167
+ reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
168
+ else
169
+ []
170
+ end
176
171
  end
177
172
  end
178
173
 
@@ -180,22 +175,37 @@ namespace :gem do
180
175
 
181
176
  desc 'Install gem'
182
177
  task :install => [:build] do
183
- sh("#{Gem.ruby} -S gem install pkg/#{Gemgem.gem_tag}.gem")
178
+ Gemgem.sh_gem('install', Gemgem.gem_path)
184
179
  end
185
180
 
186
181
  desc 'Build gem'
187
182
  task :build => [:spec] do
188
- sh("#{Gem.ruby} -S gem build #{Gemgem.spec.name}.gemspec")
189
- sh("mkdir -p pkg")
190
- sh("mv #{Gemgem.gem_tag}.gem pkg/")
183
+ require 'fileutils'
184
+ require 'rubygems/package'
185
+ gem = nil
186
+ Dir.chdir(Gemgem.dir) do
187
+ gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
188
+ FileUtils.mkdir_p(Gemgem.pkg_dir)
189
+ FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
190
+ end
191
+ puts "\e[35mGem built: \e[33m" \
192
+ "#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
193
+ end
194
+
195
+ desc 'Generate gemspec'
196
+ task :spec do
197
+ Gemgem.create
198
+ Gemgem.write
191
199
  end
192
200
 
193
201
  desc 'Release gem'
194
202
  task :release => [:spec, :check, :build] do
195
- sh("git tag #{Gemgem.gem_tag}")
196
- sh("git push")
197
- sh("git push --tags")
198
- sh("#{Gem.ruby} -S gem push pkg/#{Gemgem.gem_tag}.gem")
203
+ Gemgem.module_eval do
204
+ sh_git('tag', Gemgem.gem_tag)
205
+ sh_git('push')
206
+ sh_git('push', '--tags')
207
+ sh_gem('push', Gemgem.gem_path)
208
+ end
199
209
  end
200
210
 
201
211
  task :check do
@@ -218,51 +228,37 @@ end # of gem namespace
218
228
 
219
229
  desc 'Run tests in memory'
220
230
  task :test do
231
+ next if Gemgem.test_files.empty?
232
+
221
233
  require 'bacon'
222
234
  Bacon.extend(Bacon::TestUnitOutput)
223
235
  Bacon.summary_on_exit
224
- $LOAD_PATH.unshift('lib')
225
- Dir['./test/**/test_*.rb'].each{ |file| require file[0..-4] }
226
- end
227
-
228
- desc 'Run tests with shell'
229
- task 'test:shell', :RUBY_OPTS do |t, args|
230
- files = Dir['test/**/test_*.rb'].join(' ')
231
-
232
- cmd = [Gem.ruby, args[:RUBY_OPTS],
233
- '-I', 'lib', '-S', 'bacon', '--quiet', files]
234
-
235
- sh(cmd.compact.join(' '))
236
+ Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
236
237
  end
237
238
 
238
- desc 'Generate ann markdown'
239
- task 'ann:md' => ['gem:spec'] do
240
- puts Gemgem.ann_md
241
- end
239
+ desc 'Remove ignored files'
240
+ task :clean => ['gem:spec'] do
241
+ next if Gemgem.ignored_files.empty?
242
242
 
243
- desc 'Generate ann html'
244
- task 'ann:html' => ['gem:spec'] do
245
- puts Gemgem.ann_html
246
- end
243
+ require 'fileutils'
244
+ trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
245
+ puts "Move the following files into:" \
246
+ " \e[35m#{Gemgem.strip_path(trash)}\e[33m"
247
247
 
248
- desc 'Generate ann email'
249
- task 'ann:email' => ['gem:spec'] do
250
- puts Gemgem.ann_email
251
- end
248
+ Gemgem.ignored_files.each do |file|
249
+ from = "#{Gemgem.dir}/#{file}"
250
+ to = "#{trash}/#{File.dirname(file)}"
251
+ puts Gemgem.strip_path(from)
252
252
 
253
- desc 'Generate rdoc'
254
- task :doc => ['gem:spec'] do
255
- sh("yardoc -o rdoc --main README.md" \
256
- " --files #{Gemgem.spec.extra_rdoc_files.join(',')}")
257
- end
253
+ FileUtils.mkdir_p(to)
254
+ FileUtils.mv(from, to)
255
+ end
258
256
 
259
- desc 'Remove ignored files'
260
- task :clean => ['gem:spec'] do
261
- trash = "~/.Trash/#{Gemgem.spec.name}/"
262
- sh "mkdir -p #{trash}" unless File.exist?(File.expand_path(trash))
263
- Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" }
257
+ print "\e[0m"
264
258
  end
265
259
 
266
260
  task :default do
267
- puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
261
+ # Is there a reliable way to do this in the current process?
262
+ # It failed miserably before between Rake versions...
263
+ exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
268
264
  end
data/test/test_basic.rb CHANGED
@@ -1,7 +1,9 @@
1
1
 
2
2
  require 'bacon'
3
+ require 'muack'
3
4
 
4
5
  Bacon.summary_on_exit
6
+ include Muack::API
5
7
 
6
8
  module Kernel
7
9
  def eq? rhs
@@ -17,7 +19,8 @@ describe RequestReplay do
17
19
  port = 1024 + rand(2**16 - 1024)
18
20
  serv = TCPServer.new('localhost', port)
19
21
  hopt = "#{host}:#{port}"
20
- env = {'PATH_INFO' => '/', 'QUERY_STRING' => 'q=1',
22
+ env = {'REQUEST_METHOD' => 'GET',
23
+ 'PATH_INFO' => '/', 'QUERY_STRING' => 'q=1',
21
24
  'HTTP_HOST' => 'localhost',
22
25
  'HTTP_PORK' => 'BEEF' }
23
26
 
@@ -29,10 +32,11 @@ describe RequestReplay do
29
32
  response.value.should.eq(expected)
30
33
  end
31
34
 
32
- request = lambda do |env1, headers={}|
33
- Thread.new(RequestReplay.new(
34
- env.merge(env1), hopt, headers)) do |replay|
35
- replay.start{ |sock| sock.close_write; sock.read }
35
+ request = lambda do |env1, headers={}, read_wait=nil|
36
+ Thread.new(RequestReplay.new(env.merge(env1), hopt,
37
+ :add_headers => headers,
38
+ :read_wait => read_wait)) do |replay|
39
+ replay.start(&:read)
36
40
  end
37
41
  end
38
42
 
@@ -59,6 +63,20 @@ PAYLOAD\r
59
63
  HTTP
60
64
  end
61
65
 
66
+ should 'read_wait' do
67
+ read_wait = 5
68
+ mock(IO).select(satisfy{ |rs| rs.size == 1 &&
69
+ rs[0].kind_of?(IO) },
70
+ [], [], read_wait)
71
+
72
+ verify[request[{}, {}, read_wait], <<-HTTP]
73
+ GET /?q=1 HTTP/1.1\r
74
+ Host: localhost\r
75
+ Pork: BEEF\r
76
+ \r
77
+ HTTP
78
+ end
79
+
62
80
  describe RequestReplay::Middleware do
63
81
  app = Rack::Builder.app do
64
82
  use RequestReplay::Middleware, hopt
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request-replay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bacon
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: muack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rack
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
93
  version: '0'
80
94
  requirements: []
81
95
  rubyforge_project:
82
- rubygems_version: 2.0.7
96
+ rubygems_version: 2.1.5
83
97
  signing_key:
84
98
  specification_version: 4
85
99
  summary: Replay the request via Rack env