schmurfy-bacon 1.3.5 → 1.4.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/examples/http_spec.rb +48 -0
- data/lib/bacon/ext/em.rb +1 -1
- data/lib/bacon/ext/http.rb +64 -0
- data/lib/bacon/ext/mocha.rb +1 -0
- data/lib/bacon/version.rb +1 -1
- metadata +6 -4
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift << File.expand_path('../../lib/', __FILE__)
|
4
|
+
|
5
|
+
require 'bacon'
|
6
|
+
require 'bacon/ext/em'
|
7
|
+
require 'bacon/ext/http'
|
8
|
+
|
9
|
+
Bacon.summary_on_exit
|
10
|
+
|
11
|
+
class App
|
12
|
+
def call(env)
|
13
|
+
[200, {}, [env['REQUEST_PATH']]]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'Rack app 1' do
|
18
|
+
before do
|
19
|
+
start_server(App.new)
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'respond to http requests' do
|
23
|
+
answer = nil
|
24
|
+
http_request(:get, '/something') do |r|
|
25
|
+
answer = r.response[1..-1]
|
26
|
+
end
|
27
|
+
|
28
|
+
answer.should == 'something'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
describe 'Rack app 2' do
|
34
|
+
before do
|
35
|
+
start_server do
|
36
|
+
run App.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'respond to http requests' do
|
41
|
+
answer = nil
|
42
|
+
http_request(:get, '/something') do |r|
|
43
|
+
answer = r.response[1..-1]
|
44
|
+
end
|
45
|
+
|
46
|
+
answer.should == 'something'
|
47
|
+
end
|
48
|
+
end
|
data/lib/bacon/ext/em.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
gem 'em-http-request', '~> 1.0.0'
|
3
|
+
gem 'thin'
|
4
|
+
require 'em-http-request'
|
5
|
+
require 'thin'
|
6
|
+
|
7
|
+
require 'em-synchrony'
|
8
|
+
require 'em-synchrony/em-http'
|
9
|
+
|
10
|
+
module Bacon
|
11
|
+
module HTTPHelpers
|
12
|
+
def start_server(rack_app = nil, &block)
|
13
|
+
@http_port ||= 11000
|
14
|
+
@http_port+= 1
|
15
|
+
|
16
|
+
if rack_app && rack_app.respond_to?(:call)
|
17
|
+
block = proc{
|
18
|
+
run rack_app
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
Thin::Logging.silent = true
|
23
|
+
Thin::Server.start('127.0.0.1', @http_port, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def http_request(method, path, args = {}, &block)
|
27
|
+
headers = args.delete(:headers) || {}
|
28
|
+
body = args.delete(:body)
|
29
|
+
params = args.delete(:params) || {}
|
30
|
+
|
31
|
+
request_data = {:path => path, :query => params, :head => headers, :body => body}
|
32
|
+
|
33
|
+
req = EM::HttpRequest.new("http://127.0.0.1:#{@http_port}#{path}").send(method, request_data)
|
34
|
+
req.callback(&block)
|
35
|
+
req
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_http_response_status(req, expected, body_regexp = nil)
|
39
|
+
status = req.response_header.status
|
40
|
+
unless status == expected
|
41
|
+
raise Bacon::Error.new(:failed, "expected status was #{expected}, got #{status} : #{req.response}")
|
42
|
+
end
|
43
|
+
|
44
|
+
if body_regexp
|
45
|
+
body_ok = false
|
46
|
+
if body_regexp.is_a?(Regexp)
|
47
|
+
body_ok = (req.response =~ body_regexp)
|
48
|
+
else
|
49
|
+
body_ok = (req.response == body_regexp)
|
50
|
+
end
|
51
|
+
|
52
|
+
unless body_ok
|
53
|
+
raise Bacon::Error.new(:failed, "body does not match\n\texpected\t\"#{body_regexp}\"\n\tgot\t\t\"#{req.response}\"")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# just to avoid empty specification error
|
58
|
+
status.should == expected
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
Context.send(:include, HTTPHelpers)
|
64
|
+
end
|
data/lib/bacon/ext/mocha.rb
CHANGED
data/lib/bacon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schmurfy-bacon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- bin/bacon
|
51
51
|
- examples/em_spec.rb
|
52
52
|
- examples/focus_spec.rb
|
53
|
+
- examples/http_spec.rb
|
53
54
|
- examples/mocha_spec.rb
|
54
55
|
- examples/nested_contexts_spec.rb
|
55
56
|
- lib/autotest/bacon.rb
|
@@ -57,6 +58,7 @@ files:
|
|
57
58
|
- lib/autotest/discover.rb
|
58
59
|
- lib/bacon.rb
|
59
60
|
- lib/bacon/ext/em.rb
|
61
|
+
- lib/bacon/ext/http.rb
|
60
62
|
- lib/bacon/ext/mocha.rb
|
61
63
|
- lib/bacon/version.rb
|
62
64
|
- lib/output/better_output.rb
|
@@ -82,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
84
|
version: '0'
|
83
85
|
segments:
|
84
86
|
- 0
|
85
|
-
hash:
|
87
|
+
hash: -3016209986274602744
|
86
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
89
|
none: false
|
88
90
|
requirements:
|
@@ -91,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
93
|
version: '0'
|
92
94
|
segments:
|
93
95
|
- 0
|
94
|
-
hash:
|
96
|
+
hash: -3016209986274602744
|
95
97
|
requirements: []
|
96
98
|
rubyforge_project:
|
97
99
|
rubygems_version: 1.8.22
|