remi-rackbox 1.1.4 → 1.1.5

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 CHANGED
@@ -87,21 +87,27 @@ on how things work in [Merb][] so I can duplicate any functionality I'm missing.
87
87
  `request` gives you a [`Rack::Response`](http://rack.rubyforge.org/doc/classes/Rack/Response.html) which has
88
88
  `body`, `headers`, `status` methods ([and more](http://rack.rubyforge.org/doc/classes/Rack/Response.html))
89
89
 
90
+ Script
91
+ ------
92
+
93
+ [RackBox][] also comes with a `rackbox` script.
94
+
95
+ # prints usage ... this is all you really need :)
96
+ $ rackbox
97
+
98
+ # prints out information about the app in the current directory (if found).
99
+ # this looks like a config.ru or a Rails environment
100
+ $ rackbox info
101
+
102
+ # prints out the response for a call to GET '/' on your application
103
+ $ rackbox request --method get /foo
104
+ $ rackbox get /foo
105
+ $ rackbox /foo
106
+
90
107
  TODO
91
108
  ----
92
109
 
93
- - recreate examples so they all follow a SIMPLE spec ... eg. they should all return request headers if you call `/request_headers`
94
- - get rid of Thin as a dependency! use rails-rack-adapter
95
- - get rid of including custom rpsec matchers, use rspec-custom-matchers
96
- - make the spec module inclusion less magical! refactor the spec helpers out ... make it more explicit to include the spec helpers?
97
- - add test/unit support (the above'll be helpful for this)
98
- - bugfix: 'request' method makes spec helpers angry!
99
- - request('/', :format => :json) # simple helpers for content type request accepts
100
- - get usage documentation working for `./script/generate blackbox_spec`
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
- - 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!
104
-
110
+ see [RackBox][]'s [Lighthouse Tickets](http://remitaylor.lighthouseapp.com/projects/27570-rackbox)
105
111
 
106
112
 
107
113
  [rackbox]: http://github.com/remi/rackbox
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 1
4
- :patch: 4
4
+ :patch: 5
data/lib/rackbox/bin.rb CHANGED
@@ -24,7 +24,17 @@ class RackBox::Bin
24
24
  rackbox command [options]
25
25
 
26
26
  Examples:
27
- rackbox info # prints app info
27
+ rackbox info # prints app info
28
+ rackbox commands # list commands
29
+ rackbox get / # request / path
30
+ rackbox post -d '<XML>' / # POST data to / path
31
+ rackbox / # GET /
32
+ rackbox --data '<XML>' # POST data to / path
33
+ rackbox /dogs --xml # get /dogs, accepting xml
34
+
35
+ Options:
36
+ -a, --app "MyApp.new" # ruby to eval to get Rack app
37
+ -r, --require file[.rb] # ruby file(s) to require
28
38
 
29
39
  Further help:
30
40
  rackbox commands # list all available commands
@@ -68,6 +78,17 @@ Usage: #{ script_name } request '/some/path'
68
78
  doco
69
79
  end
70
80
  def request *args
81
+
82
+ # if args is ampty, we likely just called: $ rackbox
83
+ # which came to #request because it's the default command,
84
+ # so we should print out the usage for rackbox and exit
85
+ if args.empty?
86
+ usage
87
+ exit
88
+ end
89
+
90
+ set_rackbox_app args
91
+
71
92
  options = {
72
93
  :show => [],
73
94
  :headers => {}
@@ -87,13 +108,14 @@ doco
87
108
 
88
109
  rackbox_options = { }
89
110
  rackbox_options[:method] = options[:method] if options[:method]
90
- rackbox_options[:data] = options[:data] if options[:data]
111
+ rackbox_options[:data] = options[:data] if options[:data]
91
112
 
92
113
  options[:headers].each do |name, value|
93
114
  rackbox_options[name] = value
94
115
  end
95
116
 
96
117
  url = args.pop
118
+
97
119
  response = RackBox.request url, rackbox_options
98
120
  options[:show] = %w( body headers status ) if options[:show].empty?
99
121
 
@@ -119,8 +141,43 @@ Usage: #{ script_name } info
119
141
  end
120
142
  doco
121
143
  end
122
- def info
123
- puts "RackBox.app => #{ RackBox.app.inspect }"
144
+ def info *args
145
+ set_rackbox_app args
146
+ puts "RackBox.app => #{ RackBox.app( :silent => true ).inspect }"
147
+ end
148
+
149
+ private
150
+
151
+ #
152
+ # we let users pass a ruby string that will return
153
+ # the rack app to be used, eg.
154
+ #
155
+ # you can also set files to be required ( -r )
156
+ #
157
+ # $ rackbox -r myapp.rb --app 'lambda {|env| [200, {}, "hi!"] }' info
158
+ # $ rackbox -r myapp.rb,another-file.rb --app 'Sinatra::Application' get '/'
159
+ # $ rackbox -r myapp --app 'MyApp.new' '/'
160
+ #
161
+ def set_rackbox_app args
162
+ files_to_require = []
163
+ ruby_to_run = nil
164
+
165
+ opts = OptionParser.new do |opts|
166
+ opts.on('-r', '--require [file]') {|x| files_to_require << x }
167
+ opts.on('-a', '--app [ruby]') {|x| ruby_to_run = x }
168
+ end
169
+ opts.parse! args
170
+
171
+ files_to_require.each {|file| require file }
172
+
173
+ if ruby_to_run
174
+ begin
175
+ RackBox.app = eval(ruby_to_run)
176
+ rescue Exception => ex
177
+ puts "tried running Ruby code to set RackBox app: #{ ruby_to_run.inspect }"
178
+ raise ex
179
+ end
180
+ end
124
181
  end
125
182
 
126
183
  end
@@ -94,27 +94,39 @@ class RackBox
94
94
  # If not explicitly set, uses RAILS_ROOT (if defined?) and RAILS_ENV (if defined?)
95
95
  attr_accessor :app
96
96
 
97
- def app
97
+ def app options = { }
98
98
  unless @app and @app.respond_to?:call
99
-
99
+
100
+ options = {
101
+ :silent => false
102
+ }.merge(options)
103
+
100
104
  if File.file? 'config.ru'
101
105
  @app = Rack::Builder.new { eval(File.read('config.ru')) }
102
106
 
103
107
  elsif defined?RAILS_ENV and defined?RAILS_ROOT
104
- raise "You need the Rack::Adapter::Rails to run Rails apps with RackBox." +
105
- " Try: sudo gem install thin" unless defined?Rack::Adapter::Rails
106
- @app = Rack::Adapter::Rails.new :root => RAILS_ROOT, :environment => RAILS_ENV
108
+ unless defined?Rack::Adapter::Rails
109
+ # TODO this is no longer true ... right? does rails < 2.3 work without Thin
110
+ puts "You need the Rack::Adapter::Rails to run Rails apps with RackBox." +
111
+ " Try: sudo gem install thin" unless options[:silent]
112
+ else
113
+ @app = Rack::Adapter::Rails.new :root => RAILS_ROOT, :environment => RAILS_ENV
114
+ end
107
115
 
108
116
  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'
117
+ unless defined?Rack::Adapter::Rails
118
+ puts "You need the Rack::Adapter::Rails to run Rails apps with RackBox." +
119
+ " Try: sudo gem install thin" unless options[:silent]
120
+ else
121
+ @app = Rack::Adapter::Rails.new :root => '.', :environment => 'development'
122
+ end
112
123
 
113
124
  else
114
- raise "RackBox.app not configured."
125
+ puts "RackBox.app not configured." unless options[:silent]
115
126
 
116
127
  end
117
128
  end
129
+
118
130
  @app
119
131
  end
120
132
 
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
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - remi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-14 00:00:00 -07:00
12
+ date: 2009-04-01 00:00:00 -07:00
13
13
  default_executable: rackbox
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency