http-testing 0.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/.gitignore +3 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +19 -0
- data/README.rdoc +5 -0
- data/http-testing.gemspec +20 -0
- data/lib/http_testing/context.rb +59 -0
- data/lib/http_testing/version.rb +3 -0
- data/lib/http_testing.rb +4 -0
- metadata +83 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by Evgeny Myasishchev
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../lib/http_testing/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'http-testing'
|
5
|
+
s.version = HttpTesting::VERSION
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ['Evgeny Myasishchev']
|
8
|
+
s.email = ['evgeny.myasishchev@gmail.com']
|
9
|
+
s.homepage = 'http://github.com/evgeny-myasishchev/http-testing'
|
10
|
+
s.summary = %q{Library for testing HTTP requests in Ruby.}
|
11
|
+
s.description = %q{HttpTesting allows testing HTTP requests.}
|
12
|
+
|
13
|
+
s.rubyforge_project = 'http-testing'
|
14
|
+
|
15
|
+
s.add_development_dependency 'rspec', '>= 2.0.0'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'monitor'
|
3
|
+
|
4
|
+
class HttpTesting::Context
|
5
|
+
include WEBrick
|
6
|
+
|
7
|
+
WAIT_TIMEOUT = 0 #Works with no timeout :)
|
8
|
+
|
9
|
+
def initialize(port)
|
10
|
+
@port = port
|
11
|
+
|
12
|
+
@monitor = Monitor.new
|
13
|
+
@completed_cond = @monitor.new_cond
|
14
|
+
@started_cond = @monitor.new_cond
|
15
|
+
|
16
|
+
@completed = false
|
17
|
+
@error = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def start(&block)
|
21
|
+
@completed = false
|
22
|
+
@error = nil
|
23
|
+
|
24
|
+
#Starting separate thread for the server
|
25
|
+
@main = Thread.start do
|
26
|
+
@server = HTTPServer.new( :Port => @port, :Logger => Log.new(nil, BasicLog::ERROR), :AccessLog => [])
|
27
|
+
@server.mount_proc("/", nil) do |request, response|
|
28
|
+
begin
|
29
|
+
yield(request, response)
|
30
|
+
rescue
|
31
|
+
@error = $!
|
32
|
+
end
|
33
|
+
|
34
|
+
@completed = true
|
35
|
+
@monitor.synchronize do
|
36
|
+
@completed_cond.signal
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@server.start
|
41
|
+
end
|
42
|
+
|
43
|
+
#Waiting for server to start
|
44
|
+
@monitor.synchronize do
|
45
|
+
@started_cond.wait(WAIT_TIMEOUT)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def wait
|
50
|
+
@monitor.synchronize do
|
51
|
+
@completed_cond.wait(WAIT_TIMEOUT)
|
52
|
+
end
|
53
|
+
|
54
|
+
@server.shutdown
|
55
|
+
|
56
|
+
raise "HTTP Connection was not completed within #{WAIT_TIMEOUT} seconds" unless @completed
|
57
|
+
raise @error if @error
|
58
|
+
end
|
59
|
+
end
|
data/lib/http_testing.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-testing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Evgeny Myasishchev
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-09-11 00:00:00 +03: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
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 2.0.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: HttpTesting allows testing HTTP requests.
|
35
|
+
email:
|
36
|
+
- evgeny.myasishchev@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- MIT-LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
- http-testing.gemspec
|
49
|
+
- lib/http_testing.rb
|
50
|
+
- lib/http_testing/context.rb
|
51
|
+
- lib/http_testing/version.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/evgeny-myasishchev/http-testing
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: http-testing
|
78
|
+
rubygems_version: 1.3.6
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Library for testing HTTP requests in Ruby.
|
82
|
+
test_files: []
|
83
|
+
|