remi-rackbox 1.1.3 → 1.1.4
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/README.markdown +1 -0
- data/Rakefile +3 -2
- data/VERSION.yml +1 -1
- data/bin/rackbox +4 -0
- data/lib/rackbox/bin.rb +126 -0
- data/lib/rackbox/rackbox.rb +9 -0
- data/lib/rackbox/spec/configuration.rb +1 -0
- metadata +17 -5
data/README.markdown
CHANGED
@@ -100,6 +100,7 @@ TODO
|
|
100
100
|
- get usage documentation working for `./script/generate blackbox_spec`
|
101
101
|
- refactor all specs ... an app should implement a simple API that we can spec against ... some URIs should return session vars, some request vars, etc
|
102
102
|
- add a rackbox script for helping to quickly run requests against apps!
|
103
|
+
- add a Rackbox Webrat backend so we can use the helpers to browse around and click buttons and whatnot? could be yummy!
|
103
104
|
|
104
105
|
|
105
106
|
|
data/Rakefile
CHANGED
@@ -12,10 +12,11 @@ begin
|
|
12
12
|
s.homepage = "http://github.com/remi/rackbox"
|
13
13
|
s.description = "Merb-like BlackBox testing for Rack apps, including Rails"
|
14
14
|
s.authors = %w( remi )
|
15
|
-
s.files = FileList["[A-Z]*", "{lib,spec,examples,rails_generators}/**/*"]
|
15
|
+
s.files = FileList["[A-Z]*", "{bin,lib,spec,examples,rails_generators}/**/*"]
|
16
16
|
s.add_dependency 'remi-rails-rack-adapter'
|
17
|
+
s.add_dependency 'remi-simplecli'
|
17
18
|
# s.add_dependency 'remi-rspec-custom-matchers'
|
18
|
-
|
19
|
+
s.executables = "rackbox"
|
19
20
|
end
|
20
21
|
rescue LoadError
|
21
22
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
data/bin/rackbox
ADDED
data/lib/rackbox/bin.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'simplecli'
|
3
|
+
|
4
|
+
class String
|
5
|
+
def indent number_of_spaces = 1
|
6
|
+
self.gsub(/^(.*)$/, (' ' * number_of_spaces) + '\1')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class RackBox::Bin
|
11
|
+
include SimpleCLI
|
12
|
+
|
13
|
+
def initialize *args
|
14
|
+
@default_command = :request
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def usage *args
|
19
|
+
puts <<doco
|
20
|
+
|
21
|
+
rackbox == %{ For hitting your Rack applications }
|
22
|
+
|
23
|
+
Usage:
|
24
|
+
rackbox command [options]
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
rackbox info # prints app info
|
28
|
+
|
29
|
+
Further help:
|
30
|
+
rackbox commands # list all available commands
|
31
|
+
rackbox help <COMMAND> # show help for COMMAND
|
32
|
+
rackbox help # show this help message
|
33
|
+
|
34
|
+
doco
|
35
|
+
end
|
36
|
+
|
37
|
+
%w( get post put delete ).each do |http_method|
|
38
|
+
define_method(http_method) do |*args|
|
39
|
+
request *( ['-m', http_method] + args )
|
40
|
+
end
|
41
|
+
define_method("#{http_method}_help") do
|
42
|
+
<<doco
|
43
|
+
Usage: #{ script_name } #{ http_method } '/some/path'
|
44
|
+
|
45
|
+
Summary:
|
46
|
+
Run a #{ http_method.upcase } request against a Rack app
|
47
|
+
end
|
48
|
+
doco
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def request_help
|
53
|
+
<<doco
|
54
|
+
Usage: #{ script_name } request '/some/path'
|
55
|
+
|
56
|
+
Options:
|
57
|
+
-m, --method The HTTP method to use, default: get
|
58
|
+
-d, --data Data to that you can PUT/POST, eg. -d '<XML>'
|
59
|
+
-s, --show What to show, eg. -s body,headers,status or
|
60
|
+
call multiple times, eg. -s body -s headers
|
61
|
+
-h, --header Add header to request, eg. -h accept=text/plain
|
62
|
+
-j, --json Sets 'Accept' header to 'application/json'
|
63
|
+
-x, --xml Sets 'Accept' header to 'application/xml'
|
64
|
+
|
65
|
+
Summary:
|
66
|
+
Run a request against a Rack app
|
67
|
+
end
|
68
|
+
doco
|
69
|
+
end
|
70
|
+
def request *args
|
71
|
+
options = {
|
72
|
+
:show => [],
|
73
|
+
:headers => {}
|
74
|
+
}
|
75
|
+
opts = OptionParser.new do |opts|
|
76
|
+
opts.on('-j', '--json'){ options[:headers]['Accept'] = 'application/json' }
|
77
|
+
opts.on('-x', '--xml'){ options[:headers]['Accept'] = 'application/xml' }
|
78
|
+
opts.on('-m','--method [m]'){|m| options[:method] = m }
|
79
|
+
opts.on('-d','--data [d]'){|d| options[:data] = d }
|
80
|
+
opts.on('-s','--show [s]'){|s| options[:show] += s.split(',') }
|
81
|
+
opts.on('-h','--header [h]'){|h|
|
82
|
+
name,value = h.split('=')
|
83
|
+
options[:headers][name] = value
|
84
|
+
}
|
85
|
+
end
|
86
|
+
opts.parse! args
|
87
|
+
|
88
|
+
rackbox_options = { }
|
89
|
+
rackbox_options[:method] = options[:method] if options[:method]
|
90
|
+
rackbox_options[:data] = options[:data] if options[:data]
|
91
|
+
|
92
|
+
options[:headers].each do |name, value|
|
93
|
+
rackbox_options[name] = value
|
94
|
+
end
|
95
|
+
|
96
|
+
url = args.pop
|
97
|
+
response = RackBox.request url, rackbox_options
|
98
|
+
options[:show] = %w( body headers status ) if options[:show].empty?
|
99
|
+
|
100
|
+
if options[:show].include? 'body'
|
101
|
+
body_text = ''
|
102
|
+
response.body.each {|str| body_text << str }
|
103
|
+
end
|
104
|
+
|
105
|
+
output = "Response:\n"
|
106
|
+
output << " Status: #{ response.status }\n" if options[:show].include? 'status'
|
107
|
+
output << " Headers: \n#{ response.headers.to_yaml.strip.indent(4) }\n" if options[:show].include? 'headers'
|
108
|
+
output << " Body: \n#{ body_text.indent(4) }\n" if options[:show].include? 'body'
|
109
|
+
|
110
|
+
puts output
|
111
|
+
end
|
112
|
+
|
113
|
+
def info_help
|
114
|
+
<<doco
|
115
|
+
Usage: #{ script_name } info
|
116
|
+
|
117
|
+
Summary:
|
118
|
+
Display information about the current Rack application
|
119
|
+
end
|
120
|
+
doco
|
121
|
+
end
|
122
|
+
def info
|
123
|
+
puts "RackBox.app => #{ RackBox.app.inspect }"
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
data/lib/rackbox/rackbox.rb
CHANGED
@@ -96,14 +96,23 @@ class RackBox
|
|
96
96
|
|
97
97
|
def app
|
98
98
|
unless @app and @app.respond_to?:call
|
99
|
+
|
99
100
|
if File.file? 'config.ru'
|
100
101
|
@app = Rack::Builder.new { eval(File.read('config.ru')) }
|
102
|
+
|
101
103
|
elsif defined?RAILS_ENV and defined?RAILS_ROOT
|
102
104
|
raise "You need the Rack::Adapter::Rails to run Rails apps with RackBox." +
|
103
105
|
" Try: sudo gem install thin" unless defined?Rack::Adapter::Rails
|
104
106
|
@app = Rack::Adapter::Rails.new :root => RAILS_ROOT, :environment => RAILS_ENV
|
107
|
+
|
108
|
+
elsif File.file?('config/routes.rb') && File.file?('config/environment.rb')
|
109
|
+
raise "You need the Rack::Adapter::Rails to run Rails apps with RackBox." +
|
110
|
+
" Try: sudo gem install thin" unless defined?Rack::Adapter::Rails
|
111
|
+
@app = Rack::Adapter::Rails.new :root => '.', :environment => 'development'
|
112
|
+
|
105
113
|
else
|
106
114
|
raise "RackBox.app not configured."
|
115
|
+
|
107
116
|
end
|
108
117
|
end
|
109
118
|
@app
|
@@ -45,6 +45,7 @@ if spec_configuration_class
|
|
45
45
|
require 'webrat'
|
46
46
|
require 'webrat/core/matchers'
|
47
47
|
include Webrat::HaveTagMatcher
|
48
|
+
# include Webrat::HasContent
|
48
49
|
rescue LoadError
|
49
50
|
puts "Webrat not available. have_tag & other matchers won't be available. to install, sudo gem install webrat"
|
50
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remi-rackbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- remi
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
13
|
-
default_executable:
|
12
|
+
date: 2009-03-14 00:00:00 -07:00
|
13
|
+
default_executable: rackbox
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: remi-rails-rack-adapter
|
@@ -22,10 +22,20 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: remi-simplecli
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
25
35
|
description: Merb-like BlackBox testing for Rack apps, including Rails
|
26
36
|
email: remi@remitaylor.com
|
27
|
-
executables:
|
28
|
-
|
37
|
+
executables:
|
38
|
+
- rackbox
|
29
39
|
extensions: []
|
30
40
|
|
31
41
|
extra_rdoc_files: []
|
@@ -36,6 +46,7 @@ files:
|
|
36
46
|
- README.markdown
|
37
47
|
- LICENSE
|
38
48
|
- RDOC_README.rdoc
|
49
|
+
- bin/rackbox
|
39
50
|
- lib/rackbox.rb
|
40
51
|
- lib/rspec
|
41
52
|
- lib/rspec/custom_matcher.rb
|
@@ -45,6 +56,7 @@ files:
|
|
45
56
|
- lib/rackbox/rack/sticky_sessions.rb
|
46
57
|
- lib/rackbox/rack/content_length_fix.rb
|
47
58
|
- lib/rackbox/spec.rb
|
59
|
+
- lib/rackbox/bin.rb
|
48
60
|
- lib/rackbox/spec
|
49
61
|
- lib/rackbox/spec/configuration.rb
|
50
62
|
- lib/rackbox/spec/helpers.rb
|