eol_rackbox 1.1.7
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/LICENSE +22 -0
- data/RDOC_README.rdoc +88 -0
- data/README.markdown +134 -0
- data/README.rdoc +17 -0
- data/Rakefile +59 -0
- data/VERSION.yml +5 -0
- data/bin/rackbox +4 -0
- data/lib/eol_rackbox.rb +18 -0
- data/lib/rackbox/app.rb +30 -0
- data/lib/rackbox/bacon.rb +1 -0
- data/lib/rackbox/bin.rb +183 -0
- data/lib/rackbox/matchers.rb +30 -0
- data/lib/rackbox/rack/content_length_fix.rb +19 -0
- data/lib/rackbox/rack/extensions_for_rspec.rb +33 -0
- data/lib/rackbox/rack/sticky_sessions.rb +54 -0
- data/lib/rackbox/rackbox.rb +186 -0
- data/lib/rackbox/spec.rb +10 -0
- data/lib/rackbox/spec/configuration.rb +75 -0
- data/lib/rackbox/spec/helpers.rb +23 -0
- data/lib/rackbox/test.rb +1 -0
- data/lib/rspec/custom_matcher.rb +52 -0
- data/rails_generators/blackbox_spec/USAGE +5 -0
- data/rails_generators/blackbox_spec/blackbox_spec_generator.rb +56 -0
- data/rails_generators/blackbox_spec/templates/spec.erb +9 -0
- data/spec/basic_auth_spec.rb +29 -0
- data/spec/custom_request_header_specs.rb +14 -0
- data/spec/posting_data_spec.rb +33 -0
- data/spec/rackbox_build_query_spec.rb +35 -0
- data/spec/request_method_spec.rb +23 -0
- data/spec/spec_helper.rb +1 -0
- metadata +103 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
# This generator creates a new 'blackbox' spec, using RackBox
|
2
|
+
class BlackboxSpecGenerator < Rails::Generator::Base
|
3
|
+
|
4
|
+
attr_accessor :name_of_spec_to_create, :name_of_spec_file_to_create
|
5
|
+
|
6
|
+
# `./script/generate blackbox_spec foo` will result in:
|
7
|
+
#
|
8
|
+
# runtime_args: ['foo']
|
9
|
+
# runtime_options: {:quiet=>false, :generator=>"blackbox_spec", :command=>:create, :collision=>:ask}
|
10
|
+
#
|
11
|
+
def initialize(runtime_args, runtime_options = {})
|
12
|
+
setup_rails_to_run_blackbox_specs
|
13
|
+
@name_of_spec_to_create = runtime_args.join(' ')
|
14
|
+
@name_of_spec_file_to_create = runtime_args.join('_').downcase
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
# this should be done by ./script/generate blackbox
|
19
|
+
def setup_rails_to_run_blackbox_specs
|
20
|
+
spec_helper = File.join RAILS_ROOT, 'spec', 'spec_helper.rb'
|
21
|
+
updated = false
|
22
|
+
if File.file? spec_helper
|
23
|
+
source = File.read spec_helper
|
24
|
+
unless source =~ /require .rackbox./
|
25
|
+
if source =~ /require .spec\/rails./
|
26
|
+
source.sub!(/require .spec\/rails./, "\\0\nrequire 'rackbox'") # inject a "require 'rackbox'" statement
|
27
|
+
updated = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
unless source =~ /config.use_blackbox/
|
31
|
+
if source =~ /.configure do \|config\|/
|
32
|
+
source.sub!(/.configure do \|config\|/, "\\0\n config.use_blackbox = true") # inject config.use_blackbox
|
33
|
+
updated = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
if updated
|
37
|
+
File.open(spec_helper, 'w'){|f| f << source }
|
38
|
+
puts " updated spec/spec_helper.rb"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def manifest
|
44
|
+
record do |m|
|
45
|
+
m.directory 'spec/blackbox'
|
46
|
+
m.template 'spec.erb', "spec/blackbox/#{ name_of_spec_file_to_create }_spec.rb" # what can i call to get args???
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def banner
|
53
|
+
"Usage: #{$0} blackbox_spec Name of Spec to Create"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe RackBox, 'basic auth' do
|
4
|
+
|
5
|
+
it 'should be able to add HTTP BASIC AUTH to a request' do
|
6
|
+
app = lambda {|env| [200, {}, "i require http basic auth"] }
|
7
|
+
app = Rack::Auth::Basic.new(app){|u,p| u == 'remi' && p == 'testing' }
|
8
|
+
|
9
|
+
RackBox.request( app, '/' ).status.should == 401
|
10
|
+
RackBox.request( app, '/' ).headers.should == { 'WWW-Authenticate' => 'Basic realm=""' }
|
11
|
+
|
12
|
+
# response = RackBox.request( app, '/', 'Authentication' => 'Basic: ^' )
|
13
|
+
|
14
|
+
response = RackBox.request( app, '/', :http_basic_authentication => %w( remi testing ) )
|
15
|
+
response.status.should == 200
|
16
|
+
response.body.should == "i require http basic auth"
|
17
|
+
|
18
|
+
# :basic_auth shortcut
|
19
|
+
response = RackBox.request( app, '/', :basic_auth => %w( remi testing ) )
|
20
|
+
response.status.should == 200
|
21
|
+
response.body.should == "i require http basic auth"
|
22
|
+
|
23
|
+
# :auth shortcut
|
24
|
+
response = RackBox.request( app, '/', :auth => %w( remi testing ) )
|
25
|
+
response.status.should == 200
|
26
|
+
response.body.should == "i require http basic auth"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe RackBox, 'custom request headers' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@rack_app = lambda {|env| [ 200, { }, env.inspect ] }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "#request should take any non-special options and assume they're request headers" do
|
10
|
+
RackBox.request(@rack_app, '/').body.should_not include('"HTTP_ACCEPT"=>"application/json"')
|
11
|
+
RackBox.request(@rack_app, '/', 'HTTP_ACCEPT' => 'application/json').body.should include('"HTTP_ACCEPT"=>"application/json"')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe RackBox, 'POSTing data' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@rack_app1 = lambda {|env| [ 200, { }, "you POSTed data: #{ env['rack.input'].read }" ] }
|
7
|
+
@rack_app2 = lambda {|env|
|
8
|
+
req = Rack::Request.new env
|
9
|
+
[ 200, { }, "you POSTed data: #{ req.body.read }" ]
|
10
|
+
}
|
11
|
+
@method_app = lambda {|env| [ 200, { }, "method: #{ env['REQUEST_METHOD'] }" ] }
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should make it easy to POST data, eg. curl -D "XML"' do
|
15
|
+
RackBox.request(@rack_app1, '/', :data => 'hi there').body.should include('you POSTed data: hi there')
|
16
|
+
RackBox.request(@rack_app2, '/', :data => 'hi there').body.should include('you POSTed data: hi there')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should default to POST if method isn't explicitly set and we set :data" do
|
20
|
+
RackBox.request(@method_app, '/').body.should include('method: GET')
|
21
|
+
RackBox.request(@method_app, '/', :method => :put).body.should include('method: PUT')
|
22
|
+
RackBox.request(@method_app, '/', :data => 'hi').body.should include('method: POST')
|
23
|
+
RackBox.request(@method_app, '/', :data => 'hi', :method => :put).body.should include('method: PUT')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should default to POST if method isn't explicitly set and we set :params" do
|
27
|
+
RackBox.request(@method_app, '/').body.should include('method: GET')
|
28
|
+
RackBox.request(@method_app, '/', :method => :put).body.should include('method: PUT')
|
29
|
+
RackBox.request(@method_app, '/', :params => { :x => 5 }).body.should include('method: POST')
|
30
|
+
RackBox.request(@method_app, '/', :params => { :x => 5 }, :method => :put).body.should include('method: PUT')
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
# add String#unescape to make spec more readable
|
4
|
+
# 'user[name]=bob' is more readable than 'user%5Bname%5D=bob'
|
5
|
+
class String
|
6
|
+
def unescape
|
7
|
+
Rack::Utils.unescape self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe RackBox, 'build_query' do
|
12
|
+
|
13
|
+
it 'should support single variable' do
|
14
|
+
RackBox.build_query( :hello => 'there' ).unescape.should =='hello=there'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should support multiple variables' do
|
18
|
+
result = RackBox.build_query( :hello => 'there', :foo => :bar ).unescape
|
19
|
+
['hello=there&foo=bar', 'foo=bar&hello=there'].should include(result) # could come in any order!
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should support inner hashes' do
|
23
|
+
result = RackBox.build_query( :user => { :name => 'bob', :password => 'secret' } ).unescape
|
24
|
+
result.should include('user[name]=bob')
|
25
|
+
result.should include('user[password]=secret')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should support inner inner inner ... hashes' do
|
29
|
+
result = RackBox.build_query( :a => { :b => { :c => 'IamC' }, :x => 'xXx' }, :y => 'x' ).unescape
|
30
|
+
result.should include('a[b][c]=IamC')
|
31
|
+
result.should include('a[x]=xXx')
|
32
|
+
result.should include('y=x')
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe RackBox, '#request' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@rack_app = lambda {|env| [ 200, { }, "you requested path #{ env['PATH_INFO'] }" ] }
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should be easy to run the #request method against any Rack app' do
|
10
|
+
RackBox::App.new(@rack_app).request('/hello').body.should include('you requested path /hello')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should be even easier to run the #request method against any Rack app' do
|
14
|
+
RackBox.request(@rack_app, '/hello').body.should include('you requested path /hello')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should default to using RackBox.app if an app isn't passed" do
|
18
|
+
lambda { RackBox.request('/hello') }.should raise_error
|
19
|
+
RackBox.app = @rack_app
|
20
|
+
RackBox.request('/hello').body.should include('you requested path /hello')
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/rackbox'
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eol_rackbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 7
|
10
|
+
version: 1.1.7
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeremy Rice
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-18 00:00:00 -06:00
|
19
|
+
default_executable: rackbox
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "Merb-like BlackBox testing for Rack apps, including Rails; requires two rare dependencies: remi-rails-rack-adapter and remi-simplecli, which we available on github"
|
23
|
+
email: jrice.blue@gmail.com
|
24
|
+
executables:
|
25
|
+
- rackbox
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.markdown
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- LICENSE
|
34
|
+
- RDOC_README.rdoc
|
35
|
+
- README.markdown
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION.yml
|
39
|
+
- bin/rackbox
|
40
|
+
- lib/eol_rackbox.rb
|
41
|
+
- lib/rackbox/app.rb
|
42
|
+
- lib/rackbox/bacon.rb
|
43
|
+
- lib/rackbox/bin.rb
|
44
|
+
- lib/rackbox/matchers.rb
|
45
|
+
- lib/rackbox/rack/content_length_fix.rb
|
46
|
+
- lib/rackbox/rack/extensions_for_rspec.rb
|
47
|
+
- lib/rackbox/rack/sticky_sessions.rb
|
48
|
+
- lib/rackbox/rackbox.rb
|
49
|
+
- lib/rackbox/spec.rb
|
50
|
+
- lib/rackbox/spec/configuration.rb
|
51
|
+
- lib/rackbox/spec/helpers.rb
|
52
|
+
- lib/rackbox/test.rb
|
53
|
+
- lib/rspec/custom_matcher.rb
|
54
|
+
- rails_generators/blackbox_spec/USAGE
|
55
|
+
- rails_generators/blackbox_spec/blackbox_spec_generator.rb
|
56
|
+
- rails_generators/blackbox_spec/templates/spec.erb
|
57
|
+
- spec/basic_auth_spec.rb
|
58
|
+
- spec/custom_request_header_specs.rb
|
59
|
+
- spec/posting_data_spec.rb
|
60
|
+
- spec/rackbox_build_query_spec.rb
|
61
|
+
- spec/request_method_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: http://github.com/JRice/eol_rackbox
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --charset=UTF-8
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.7
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Merb-like BlackBox testing for Rack apps, including Rails
|
97
|
+
test_files:
|
98
|
+
- spec/basic_auth_spec.rb
|
99
|
+
- spec/custom_request_header_specs.rb
|
100
|
+
- spec/posting_data_spec.rb
|
101
|
+
- spec/rackbox_build_query_spec.rb
|
102
|
+
- spec/request_method_spec.rb
|
103
|
+
- spec/spec_helper.rb
|