typhoeus 1.3.1 → 1.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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -1
  3. data/CONTRIBUTING.md +4 -0
  4. data/README.md +13 -6
  5. data/lib/typhoeus/adapters/faraday.rb +2 -2
  6. data/lib/typhoeus/cache/dalli.rb +3 -1
  7. data/lib/typhoeus/cache/rails.rb +4 -2
  8. data/lib/typhoeus/cache/redis.rb +3 -1
  9. data/lib/typhoeus/config.rb +17 -1
  10. data/lib/typhoeus/easy_factory.rb +27 -1
  11. data/lib/typhoeus/expectation.rb +4 -2
  12. data/lib/typhoeus/hydra/cacheable.rb +1 -1
  13. data/lib/typhoeus/request/cacheable.rb +5 -1
  14. data/lib/typhoeus/request/responseable.rb +1 -1
  15. data/lib/typhoeus/request.rb +2 -0
  16. data/lib/typhoeus/response/informations.rb +57 -0
  17. data/lib/typhoeus/version.rb +1 -1
  18. data/lib/typhoeus.rb +4 -3
  19. data/typhoeus.gemspec +14 -4
  20. metadata +14 -99
  21. data/.gitignore +0 -8
  22. data/.rspec +0 -4
  23. data/.travis.yml +0 -22
  24. data/Gemfile +0 -32
  25. data/Guardfile +0 -9
  26. data/Rakefile +0 -38
  27. data/perf/profile.rb +0 -14
  28. data/perf/vs_nethttp.rb +0 -64
  29. data/spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb +0 -156
  30. data/spec/rack/typhoeus/middleware/params_decoder_spec.rb +0 -31
  31. data/spec/spec_helper.rb +0 -29
  32. data/spec/support/localhost_server.rb +0 -94
  33. data/spec/support/memory_cache.rb +0 -15
  34. data/spec/support/server.rb +0 -116
  35. data/spec/typhoeus/adapters/faraday_spec.rb +0 -339
  36. data/spec/typhoeus/cache/dalli_spec.rb +0 -41
  37. data/spec/typhoeus/cache/redis_spec.rb +0 -41
  38. data/spec/typhoeus/config_spec.rb +0 -15
  39. data/spec/typhoeus/easy_factory_spec.rb +0 -143
  40. data/spec/typhoeus/errors/no_stub_spec.rb +0 -13
  41. data/spec/typhoeus/expectation_spec.rb +0 -280
  42. data/spec/typhoeus/hydra/addable_spec.rb +0 -22
  43. data/spec/typhoeus/hydra/before_spec.rb +0 -98
  44. data/spec/typhoeus/hydra/block_connection_spec.rb +0 -18
  45. data/spec/typhoeus/hydra/cacheable_spec.rb +0 -58
  46. data/spec/typhoeus/hydra/memoizable_spec.rb +0 -53
  47. data/spec/typhoeus/hydra/queueable_spec.rb +0 -98
  48. data/spec/typhoeus/hydra/runnable_spec.rb +0 -137
  49. data/spec/typhoeus/hydra/stubbable_spec.rb +0 -48
  50. data/spec/typhoeus/hydra_spec.rb +0 -22
  51. data/spec/typhoeus/pool_spec.rb +0 -135
  52. data/spec/typhoeus/request/actions_spec.rb +0 -19
  53. data/spec/typhoeus/request/before_spec.rb +0 -93
  54. data/spec/typhoeus/request/block_connection_spec.rb +0 -75
  55. data/spec/typhoeus/request/cacheable_spec.rb +0 -94
  56. data/spec/typhoeus/request/callbacks_spec.rb +0 -91
  57. data/spec/typhoeus/request/marshal_spec.rb +0 -60
  58. data/spec/typhoeus/request/memoizable_spec.rb +0 -34
  59. data/spec/typhoeus/request/operations_spec.rb +0 -101
  60. data/spec/typhoeus/request/responseable_spec.rb +0 -13
  61. data/spec/typhoeus/request/stubbable_spec.rb +0 -45
  62. data/spec/typhoeus/request_spec.rb +0 -232
  63. data/spec/typhoeus/response/header_spec.rb +0 -147
  64. data/spec/typhoeus/response/informations_spec.rb +0 -283
  65. data/spec/typhoeus/response/status_spec.rb +0 -256
  66. data/spec/typhoeus/response_spec.rb +0 -100
  67. data/spec/typhoeus_spec.rb +0 -105
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Balatero
8
8
  - Paul Dix
9
9
  - Hans Hasselberg
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2018-11-06 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: ethon
@@ -18,14 +17,14 @@ dependencies:
18
17
  requirements:
19
18
  - - ">="
20
19
  - !ruby/object:Gem::Version
21
- version: 0.9.0
20
+ version: 0.18.0
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
- version: 0.9.0
27
+ version: 0.18.0
29
28
  description: Like a modern code version of the mythical beast with 100 serpent heads,
30
29
  Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
31
30
  email:
@@ -34,16 +33,10 @@ executables: []
34
33
  extensions: []
35
34
  extra_rdoc_files: []
36
35
  files:
37
- - ".gitignore"
38
- - ".rspec"
39
- - ".travis.yml"
40
36
  - CHANGELOG.md
41
37
  - CONTRIBUTING.md
42
- - Gemfile
43
- - Guardfile
44
38
  - LICENSE
45
39
  - README.md
46
- - Rakefile
47
40
  - UPGRADE.md
48
41
  - lib/rack/typhoeus.rb
49
42
  - lib/rack/typhoeus/middleware/params_decoder.rb
@@ -88,53 +81,16 @@ files:
88
81
  - lib/typhoeus/response/informations.rb
89
82
  - lib/typhoeus/response/status.rb
90
83
  - lib/typhoeus/version.rb
91
- - perf/profile.rb
92
- - perf/vs_nethttp.rb
93
- - spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb
94
- - spec/rack/typhoeus/middleware/params_decoder_spec.rb
95
- - spec/spec_helper.rb
96
- - spec/support/localhost_server.rb
97
- - spec/support/memory_cache.rb
98
- - spec/support/server.rb
99
- - spec/typhoeus/adapters/faraday_spec.rb
100
- - spec/typhoeus/cache/dalli_spec.rb
101
- - spec/typhoeus/cache/redis_spec.rb
102
- - spec/typhoeus/config_spec.rb
103
- - spec/typhoeus/easy_factory_spec.rb
104
- - spec/typhoeus/errors/no_stub_spec.rb
105
- - spec/typhoeus/expectation_spec.rb
106
- - spec/typhoeus/hydra/addable_spec.rb
107
- - spec/typhoeus/hydra/before_spec.rb
108
- - spec/typhoeus/hydra/block_connection_spec.rb
109
- - spec/typhoeus/hydra/cacheable_spec.rb
110
- - spec/typhoeus/hydra/memoizable_spec.rb
111
- - spec/typhoeus/hydra/queueable_spec.rb
112
- - spec/typhoeus/hydra/runnable_spec.rb
113
- - spec/typhoeus/hydra/stubbable_spec.rb
114
- - spec/typhoeus/hydra_spec.rb
115
- - spec/typhoeus/pool_spec.rb
116
- - spec/typhoeus/request/actions_spec.rb
117
- - spec/typhoeus/request/before_spec.rb
118
- - spec/typhoeus/request/block_connection_spec.rb
119
- - spec/typhoeus/request/cacheable_spec.rb
120
- - spec/typhoeus/request/callbacks_spec.rb
121
- - spec/typhoeus/request/marshal_spec.rb
122
- - spec/typhoeus/request/memoizable_spec.rb
123
- - spec/typhoeus/request/operations_spec.rb
124
- - spec/typhoeus/request/responseable_spec.rb
125
- - spec/typhoeus/request/stubbable_spec.rb
126
- - spec/typhoeus/request_spec.rb
127
- - spec/typhoeus/response/header_spec.rb
128
- - spec/typhoeus/response/informations_spec.rb
129
- - spec/typhoeus/response/status_spec.rb
130
- - spec/typhoeus/response_spec.rb
131
- - spec/typhoeus_spec.rb
132
84
  - typhoeus.gemspec
133
85
  homepage: https://github.com/typhoeus/typhoeus
134
86
  licenses:
135
87
  - MIT
136
- metadata: {}
137
- post_install_message:
88
+ metadata:
89
+ bug_tracker_uri: https://github.com/typhoeus/typhoeus/issues
90
+ changelog_uri: https://github.com/typhoeus/typhoeus/blob/v1.6.0/CHANGELOG.md
91
+ documentation_uri: https://www.rubydoc.info/gems/typhoeus/1.6.0
92
+ rubygems_mfa_required: 'true'
93
+ source_code_uri: https://github.com/typhoeus/typhoeus/tree/v1.6.0
138
94
  rdoc_options: []
139
95
  require_paths:
140
96
  - lib
@@ -142,55 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
98
  requirements:
143
99
  - - ">="
144
100
  - !ruby/object:Gem::Version
145
- version: '0'
101
+ version: '2.6'
146
102
  required_rubygems_version: !ruby/object:Gem::Requirement
147
103
  requirements:
148
104
  - - ">="
149
105
  - !ruby/object:Gem::Version
150
- version: 1.3.6
106
+ version: '0'
151
107
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.7.6
154
- signing_key:
108
+ rubygems_version: 4.0.3
155
109
  specification_version: 4
156
110
  summary: Parallel HTTP library on top of libcurl multi.
157
- test_files:
158
- - spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb
159
- - spec/rack/typhoeus/middleware/params_decoder_spec.rb
160
- - spec/spec_helper.rb
161
- - spec/support/localhost_server.rb
162
- - spec/support/memory_cache.rb
163
- - spec/support/server.rb
164
- - spec/typhoeus/adapters/faraday_spec.rb
165
- - spec/typhoeus/cache/dalli_spec.rb
166
- - spec/typhoeus/cache/redis_spec.rb
167
- - spec/typhoeus/config_spec.rb
168
- - spec/typhoeus/easy_factory_spec.rb
169
- - spec/typhoeus/errors/no_stub_spec.rb
170
- - spec/typhoeus/expectation_spec.rb
171
- - spec/typhoeus/hydra/addable_spec.rb
172
- - spec/typhoeus/hydra/before_spec.rb
173
- - spec/typhoeus/hydra/block_connection_spec.rb
174
- - spec/typhoeus/hydra/cacheable_spec.rb
175
- - spec/typhoeus/hydra/memoizable_spec.rb
176
- - spec/typhoeus/hydra/queueable_spec.rb
177
- - spec/typhoeus/hydra/runnable_spec.rb
178
- - spec/typhoeus/hydra/stubbable_spec.rb
179
- - spec/typhoeus/hydra_spec.rb
180
- - spec/typhoeus/pool_spec.rb
181
- - spec/typhoeus/request/actions_spec.rb
182
- - spec/typhoeus/request/before_spec.rb
183
- - spec/typhoeus/request/block_connection_spec.rb
184
- - spec/typhoeus/request/cacheable_spec.rb
185
- - spec/typhoeus/request/callbacks_spec.rb
186
- - spec/typhoeus/request/marshal_spec.rb
187
- - spec/typhoeus/request/memoizable_spec.rb
188
- - spec/typhoeus/request/operations_spec.rb
189
- - spec/typhoeus/request/responseable_spec.rb
190
- - spec/typhoeus/request/stubbable_spec.rb
191
- - spec/typhoeus/request_spec.rb
192
- - spec/typhoeus/response/header_spec.rb
193
- - spec/typhoeus/response/informations_spec.rb
194
- - spec/typhoeus/response/status_spec.rb
195
- - spec/typhoeus/response_spec.rb
196
- - spec/typhoeus_spec.rb
111
+ test_files: []
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- *.gem
2
- Gemfile.lock
3
- doc/
4
- .yardoc
5
- .rvmrc
6
- coverage
7
- check.sh
8
- tags
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --tty
2
- --color
3
- --format documentation
4
- --backtrace
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: ruby
2
- script: "bundle exec rake"
3
- sudo: false
4
- rvm:
5
- - 1.8.7
6
- - 1.9.2
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1.8
10
- - 2.2.4
11
- - 2.3.0
12
- - 2.4.1
13
- - ruby-head
14
- - jruby-head
15
- - jruby-18mode
16
- - jruby-19mode
17
- matrix:
18
- fast_finish: true
19
- allow_failures:
20
- - rvm: ruby-head
21
- - rvm: jruby-head
22
- - rvm: ree
data/Gemfile DELETED
@@ -1,32 +0,0 @@
1
- source "https://rubygems.org"
2
- gemspec
3
-
4
- if Gem.ruby_version < Gem::Version.new("2.0.0")
5
- gem "rake", "< 11"
6
- gem "json", "< 2"
7
- else
8
- gem "json"
9
- gem "rake"
10
- end
11
-
12
- group :development, :test do
13
- gem "rspec", "~> 3.0"
14
-
15
- gem "sinatra", "~> 1.3"
16
-
17
- if Gem.ruby_version >= Gem::Version.new("1.9.0")
18
- gem "faraday", ">= 0.9"
19
- gem "dalli", "~> 2.0"
20
- end
21
-
22
- gem "redis", "~> 3.0"
23
-
24
- if RUBY_PLATFORM == "java"
25
- gem "spoon"
26
- end
27
-
28
- unless ENV["CI"]
29
- gem "guard-rspec", "~> 0.7"
30
- gem 'rb-fsevent', '~> 0.9.1'
31
- end
32
- end
data/Guardfile DELETED
@@ -1,9 +0,0 @@
1
- # vim:set filetype=ruby:
2
- guard(
3
- "rspec",
4
- all_after_pass: false,
5
- cli: "--fail-fast --tty --format documentation --colour") do
6
-
7
- watch(%r{^spec/.+_spec\.rb$})
8
- watch(%r{^lib/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" }
9
- end
data/Rakefile DELETED
@@ -1,38 +0,0 @@
1
- require "bundler"
2
- Bundler.setup
3
-
4
- require "rake"
5
- require "rspec/core/rake_task"
6
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
7
- require "typhoeus/version"
8
-
9
- task :gem => :build
10
- task :build do
11
- system "gem build typhoeus.gemspec"
12
- end
13
-
14
- task :install => :build do
15
- system "gem install typhoeus-#{Typhoeus::VERSION}.gem"
16
- end
17
-
18
- task :release => :build do
19
- system "git tag -a v#{Typhoeus::VERSION} -m 'Tagging #{Typhoeus::VERSION}'"
20
- system "git push --tags"
21
- system "gem push typhoeus-#{Typhoeus::VERSION}.gem"
22
- end
23
-
24
- RSpec::Core::RakeTask.new(:spec) do |t|
25
- t.verbose = false
26
- t.ruby_opts = "-W -I./spec -rspec_helper"
27
- end
28
-
29
- desc "Start up the test servers"
30
- task :start do
31
- require_relative 'spec/support/boot'
32
- begin
33
- Boot.start_servers(:rake)
34
- rescue Exception
35
- end
36
- end
37
-
38
- task :default => :spec
data/perf/profile.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'typhoeus'
2
- require 'ruby-prof'
3
-
4
- calls = 50
5
- base_url = "http://127.0.0.1:3000/"
6
-
7
- RubyProf.start
8
- calls.times do |i|
9
- Typhoeus::Request.get(base_url+i.to_s)
10
- end
11
- result = RubyProf.stop
12
-
13
- printer = RubyProf::FlatPrinter.new(result)
14
- printer.print(STDOUT)
data/perf/vs_nethttp.rb DELETED
@@ -1,64 +0,0 @@
1
- require 'typhoeus'
2
- require 'net/http'
3
- require 'open-uri'
4
- require 'benchmark'
5
-
6
- URL = "http://localhost:300"
7
- hydra = Typhoeus::Hydra.new(max_concurrency: 3)
8
-
9
- if defined? require_relative
10
- require_relative '../spec/support/localhost_server.rb'
11
- require_relative '../spec/support/server.rb'
12
- else
13
- require '../spec/support/localhost_server.rb'
14
- require '../spec/support/server.rb'
15
- end
16
- LocalhostServer.new(TESTSERVER.new, 3000)
17
- LocalhostServer.new(TESTSERVER.new, 3001)
18
- LocalhostServer.new(TESTSERVER.new, 3002)
19
-
20
- def url_for(i)
21
- "#{URL}#{i%3}/"
22
- end
23
-
24
- Benchmark.bm do |bm|
25
-
26
- [1000].each do |calls|
27
- puts "[ #{calls} requests ]"
28
-
29
- bm.report("net/http ") do
30
- calls.times do |i|
31
- uri = URI.parse(url_for(i))
32
- Net::HTTP.get_response(uri)
33
- end
34
- end
35
-
36
- bm.report("open ") do
37
- calls.times do |i|
38
- open(url_for(i))
39
- end
40
- end
41
-
42
- bm.report("request ") do
43
- calls.times do |i|
44
- Typhoeus::Request.get(url_for(i))
45
- end
46
- end
47
-
48
- bm.report("hydra ") do
49
- calls.times do |i|
50
- hydra.queue(Typhoeus::Request.new(url_for(i)))
51
- end
52
- hydra.run
53
- end
54
-
55
- bm.report("hydra memoize ") do
56
- Typhoeus::Config.memoize = true
57
- calls.times do |i|
58
- hydra.queue(Typhoeus::Request.new(url_for(i)))
59
- end
60
- hydra.run
61
- Typhoeus::Config.memoize = false
62
- end
63
- end
64
- end
@@ -1,156 +0,0 @@
1
- require 'spec_helper'
2
- require "rack/typhoeus"
3
-
4
- describe "Rack::Typhoeus::Middleware::ParamsDecoder::Helper" do
5
-
6
- let(:klass) do
7
- Class.new do
8
- include Rack::Typhoeus::Middleware::ParamsDecoder::Helper
9
- end.new
10
- end
11
-
12
- describe "#decode" do
13
- let(:decoded) { klass.decode(params) }
14
- let(:params) { { :array => {'0' => :a, '1' => :b } } }
15
-
16
- it "decodes" do
17
- expect(decoded[:array]).to match_array([:a, :b])
18
- end
19
-
20
- it "doesn't modify" do
21
- expect(decoded).to_not be(params)
22
- end
23
- end
24
-
25
- describe "#decode!" do
26
- let(:decoded) { klass.decode!(params) }
27
-
28
- context "when hash" do
29
- context "when encoded" do
30
- context "when simple" do
31
- let(:params) { { :array => {'0' => :a, '1' => :b } } }
32
-
33
- it "decodes" do
34
- expect(decoded[:array]).to match_array([:a, :b])
35
- end
36
-
37
- it "modifies" do
38
- expect(decoded).to eq(params)
39
- end
40
- end
41
-
42
- context "when longer and more complex" do
43
- let(:params) do
44
- {
45
- :ids => {
46
- "0" => "407304",
47
- "1" => "407305",
48
- "2" => "407306",
49
- "3" => "407307",
50
- "4" => "407308",
51
- "5" => "407309",
52
- "6" => "407310",
53
- "7" => "407311",
54
- "8" => "407312",
55
- "9" => "407313",
56
- "10" => "327012"
57
- }
58
- }
59
- end
60
-
61
- it "decodes ensuring arrays maintain their original order" do
62
- expect(decoded[:ids]).to eq(["407304", "407305", "407306", "407307", "407308", "407309", "407310", "407311", "407312", "407313", "327012"])
63
- end
64
- end
65
-
66
- context "when nested" do
67
- let(:params) do
68
- { :array => { '0' => 0, '1' => { '0' => 'sub0', '1' => 'sub1' } } }
69
- end
70
-
71
- it "decodes" do
72
- expect(decoded[:array]).to include(0)
73
- expect(decoded[:array].find{|e| e.is_a?(Array)}).to(
74
- match_array(['sub0', 'sub1'])
75
- )
76
- end
77
-
78
- it "modifies" do
79
- expect(decoded).to eq(params)
80
- end
81
- end
82
- end
83
-
84
- context "when not encoded" do
85
- let(:params) { {:a => :a} }
86
-
87
- it "doesn't modify" do
88
- expect(decoded).to be(params)
89
- end
90
- end
91
- end
92
-
93
- context "when no hash" do
94
- let(:params) { "a" }
95
-
96
- it "returns self" do
97
- expect(decoded).to be(params)
98
- end
99
- end
100
- end
101
-
102
- describe "#encoded?" do
103
- let(:encoded) { klass.send(:encoded?, params) }
104
-
105
- context "when there is only one key" do
106
- context "and its 0" do
107
- let(:params){ {'0' => 1} }
108
- it 'returns true' do
109
- expect(encoded).to be_truthy
110
- end
111
- end
112
- context "and its not 0" do
113
- let(:params){ {'some-key' => 1}}
114
- it 'returns false' do
115
- expect(encoded).to be_falsey
116
- end
117
- end
118
- end
119
-
120
- context "when keys are ascending numbers starting with zero" do
121
- let(:params) { Hash[12.times.map {|i| [i, (i+65).chr]}] }
122
-
123
- it "returns true" do
124
- expect(encoded).to be_truthy
125
- end
126
- end
127
-
128
- context "when keys are not ascending numbers starting with zero" do
129
- let(:params) { {:a => 1} }
130
-
131
- it "returns false" do
132
- expect(encoded).to be_falsey
133
- end
134
- end
135
- end
136
-
137
- describe "#convert" do
138
- let(:converted) { klass.send(:convert, params) }
139
-
140
- context "when encoded" do
141
- let(:params) { {'0' => :a, '1' => :b} }
142
-
143
- it "returns values" do
144
- expect(converted).to match_array([:a, :b])
145
- end
146
- end
147
-
148
- context "when not encoded" do
149
- let(:params) { {:a => :a} }
150
-
151
- it "returns unmodified" do
152
- expect(converted).to be(params)
153
- end
154
- end
155
- end
156
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Rack::Typhoeus::Middleware::ParamsDecoder" do
4
-
5
- before(:all) do
6
- require "rack/typhoeus"
7
- end
8
-
9
- let(:app) do
10
- double
11
- end
12
-
13
- let(:env) do
14
- double
15
- end
16
-
17
- let(:klass) do
18
- Rack::Typhoeus::Middleware::ParamsDecoder
19
- end
20
-
21
- describe "#call" do
22
- end
23
-
24
- context "when requesting" do
25
- let(:response) { Typhoeus.get("localhost:3001", :params => {:x => [:a]}) }
26
-
27
- it "transforms parameters" do
28
- expect(response.body).to include("query_hash\":{\"x\":[\"a\"]}")
29
- end
30
- end
31
- end
data/spec/spec_helper.rb DELETED
@@ -1,29 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- require "bundler"
5
- Bundler.setup
6
- require "typhoeus"
7
- require "rspec"
8
-
9
- Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
10
-
11
- RSpec.configure do |config|
12
- config.order = :rand
13
-
14
- config.before(:suite) do
15
- LocalhostServer.new(TESTSERVER.new, 3001)
16
- end
17
-
18
- config.after do
19
- Typhoeus::Pool.clear
20
- Typhoeus::Expectation.clear
21
- Typhoeus.before.clear
22
- Typhoeus.on_complete.clear
23
- Typhoeus.on_success.clear
24
- Typhoeus.on_failure.clear
25
- Typhoeus::Config.verbose = false
26
- Typhoeus::Config.block_connection = false
27
- Typhoeus::Config.memoize = false
28
- end
29
- end
@@ -1,94 +0,0 @@
1
- require 'rack'
2
- require 'rack/handler/webrick'
3
- require 'net/http'
4
-
5
- # The code for this is inspired by Capybara's server:
6
- # http://github.com/jnicklas/capybara/blob/0.3.9/lib/capybara/server.rb
7
- class LocalhostServer
8
- READY_MESSAGE = "Server ready"
9
-
10
- class Identify
11
- def initialize(app)
12
- @app = app
13
- end
14
-
15
- def call(env)
16
- if env["PATH_INFO"] == "/__identify__"
17
- [200, {}, [LocalhostServer::READY_MESSAGE]]
18
- else
19
- @app.call(env)
20
- end
21
- end
22
- end
23
-
24
- attr_reader :port
25
-
26
- def initialize(rack_app, port = nil)
27
- @port = port || find_available_port
28
- @rack_app = rack_app
29
- concurrently { boot }
30
- wait_until(10, "Boot failed.") { booted? }
31
- end
32
-
33
- private
34
-
35
- def find_available_port
36
- server = TCPServer.new('127.0.0.1', 0)
37
- server.addr[1]
38
- ensure
39
- server.close if server
40
- end
41
-
42
- def boot
43
- # Use WEBrick since it's part of the ruby standard library and is available on all ruby interpreters.
44
- options = { :Port => port }
45
- options.merge!(:AccessLog => [], :Logger => WEBrick::BasicLog.new(StringIO.new)) unless ENV['VERBOSE_SERVER']
46
- Rack::Handler::WEBrick.run(Identify.new(@rack_app), options)
47
- end
48
-
49
- def booted?
50
- res = ::Net::HTTP.get_response("localhost", '/__identify__', port)
51
- if res.is_a?(::Net::HTTPSuccess) or res.is_a?(::Net::HTTPRedirection)
52
- return res.body == READY_MESSAGE
53
- end
54
- rescue Errno::ECONNREFUSED, Errno::EBADF
55
- return false
56
- end
57
-
58
- def concurrently
59
- if should_use_subprocess?
60
- pid = Process.fork do
61
- trap(:INT) { ::Rack::Handler::WEBrick.shutdown }
62
- yield
63
- exit # manually exit; otherwise this sub-process will re-run the specs that haven't run yet.
64
- end
65
-
66
- at_exit do
67
- Process.kill('INT', pid)
68
- begin
69
- Process.wait(pid)
70
- rescue Errno::ECHILD
71
- # ignore this error...I think it means the child process has already exited.
72
- end
73
- end
74
- else
75
- Thread.new { yield }
76
- end
77
- end
78
-
79
- def should_use_subprocess?
80
- # !ENV['THREADED']
81
- false
82
- end
83
-
84
- def wait_until(timeout, error_message, &block)
85
- start_time = Time.now
86
-
87
- while true
88
- return if yield
89
- raise TimeoutError.new(error_message) if (Time.now - start_time) > timeout
90
- sleep(0.05)
91
- end
92
- end
93
- end
94
-
@@ -1,15 +0,0 @@
1
- class MemoryCache
2
- attr_reader :memory
3
-
4
- def initialize
5
- @memory = {}
6
- end
7
-
8
- def get(request)
9
- memory[request]
10
- end
11
-
12
- def set(request, response)
13
- memory[request] = response
14
- end
15
- end