remi-rackbox 1.0.1 → 1.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/README.markdown +6 -0
- data/Rakefile +57 -0
- data/VERSION.yml +2 -2
- data/examples/rack/config.ru +53 -0
- data/examples/rack/run-specs +2 -0
- data/examples/rack/spec +1 -0
- data/examples/rails/README +256 -0
- data/examples/rails/Rakefile +10 -0
- data/examples/rails/app/controllers/application.rb +15 -0
- data/examples/rails/app/controllers/welcome_controller.rb +32 -0
- data/examples/rails/app/helpers/application_helper.rb +3 -0
- data/examples/rails/app/helpers/welcome_helper.rb +2 -0
- data/examples/rails/app/views/layouts/application.html.erb +7 -0
- data/examples/rails/app/views/welcome/some_html.html.erb +20 -0
- data/examples/rails/config/boot.rb +109 -0
- data/examples/rails/config/database.yml +22 -0
- data/examples/rails/config/environment.rb +75 -0
- data/examples/rails/config/environments/development.rb +17 -0
- data/examples/rails/config/environments/production.rb +24 -0
- data/examples/rails/config/environments/test.rb +22 -0
- data/examples/rails/config/initializers/inflections.rb +10 -0
- data/examples/rails/config/initializers/mime_types.rb +5 -0
- data/examples/rails/config/initializers/new_rails_defaults.rb +17 -0
- data/examples/rails/config/locales/en.yml +5 -0
- data/examples/rails/config/routes.rb +12 -0
- data/examples/rails/db/development.sqlite3 +0 -0
- data/examples/rails/db/schema.rb +14 -0
- data/examples/rails/db/test.sqlite3 +0 -0
- data/examples/rails/doc/README_FOR_APP +5 -0
- data/examples/rails/lib/tasks/rspec.rake +158 -0
- data/examples/rails/public/404.html +30 -0
- data/examples/rails/public/422.html +30 -0
- data/examples/rails/public/500.html +33 -0
- data/examples/rails/public/dispatch.cgi +10 -0
- data/examples/rails/public/dispatch.fcgi +24 -0
- data/examples/rails/public/dispatch.rb +10 -0
- data/examples/rails/public/favicon.ico +0 -0
- data/examples/rails/public/images/rails.png +0 -0
- data/examples/rails/public/javascripts/application.js +2 -0
- data/examples/rails/public/javascripts/controls.js +963 -0
- data/examples/rails/public/javascripts/dragdrop.js +973 -0
- data/examples/rails/public/javascripts/effects.js +1128 -0
- data/examples/rails/public/javascripts/prototype.js +4320 -0
- data/examples/rails/public/robots.txt +5 -0
- data/examples/rails/run-specs +2 -0
- data/examples/rails/script/about +4 -0
- data/examples/rails/script/autospec +5 -0
- data/examples/rails/script/console +3 -0
- data/examples/rails/script/dbconsole +3 -0
- data/examples/rails/script/destroy +3 -0
- data/examples/rails/script/generate +3 -0
- data/examples/rails/script/performance/benchmarker +3 -0
- data/examples/rails/script/performance/profiler +3 -0
- data/examples/rails/script/performance/request +3 -0
- data/examples/rails/script/plugin +3 -0
- data/examples/rails/script/process/inspector +3 -0
- data/examples/rails/script/process/reaper +3 -0
- data/examples/rails/script/process/spawner +3 -0
- data/examples/rails/script/runner +3 -0
- data/examples/rails/script/server +3 -0
- data/examples/rails/script/spec +5 -0
- data/examples/rails/script/spec_server +125 -0
- data/examples/rails/spec +1 -0
- data/examples/rails/test/functional/welcome_controller_test.rb +8 -0
- data/examples/rails/test/performance/browsing_test.rb +9 -0
- data/examples/rails/test/test_helper.rb +38 -0
- data/examples/sinatra/config.ru +11 -0
- data/examples/sinatra/run-specs +2 -0
- data/examples/sinatra/sinatra_app.rb +58 -0
- data/examples/sinatra/spec +1 -0
- data/lib/rackbox/rack/extensions_for_rspec.rb +2 -0
- data/lib/rackbox/rackbox.rb +32 -0
- data/lib/rackbox/spec/configuration.rb +11 -0
- data/lib/rackbox/spec/helpers.rb +1 -1
- 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/rackbox_spec.rb +35 -0
- data/spec/spec_helper.rb +1 -0
- metadata +106 -2
@@ -0,0 +1,5 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
|
3
|
+
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
|
4
|
+
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
|
5
|
+
$stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
|
3
|
+
require 'rubygems'
|
4
|
+
require 'drb/drb'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'spec'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
# This is based on Florian Weber's TDDMate
|
10
|
+
module Spec
|
11
|
+
module Runner
|
12
|
+
class RailsSpecServer
|
13
|
+
def run(argv, stderr, stdout)
|
14
|
+
$stdout = stdout
|
15
|
+
$stderr = stderr
|
16
|
+
|
17
|
+
unless ActiveRecord::Base.respond_to?(:clear_reloadable_connections!)
|
18
|
+
base = ActiveRecord::Base
|
19
|
+
def base.clear_reloadable_connections!
|
20
|
+
active_connections.each do |name, conn|
|
21
|
+
if conn.requires_reloading?
|
22
|
+
conn.disconnect!
|
23
|
+
active_connections.delete(name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveRecord::Base.clear_reloadable_connections!
|
30
|
+
|
31
|
+
if ActionController.const_defined?(:Dispatcher)
|
32
|
+
dispatcher = ::ActionController::Dispatcher.new($stdout)
|
33
|
+
dispatcher.cleanup_application
|
34
|
+
elsif ::Dispatcher.respond_to?(:reset_application!)
|
35
|
+
::Dispatcher.reset_application!
|
36
|
+
else
|
37
|
+
raise "Application reloading failed"
|
38
|
+
end
|
39
|
+
if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
|
40
|
+
Fixtures.reset_cache
|
41
|
+
end
|
42
|
+
|
43
|
+
if ::ActiveSupport.const_defined?(:Dependencies)
|
44
|
+
::ActiveSupport::Dependencies.mechanism = :load
|
45
|
+
else
|
46
|
+
::Dependencies.mechanism = :load
|
47
|
+
end
|
48
|
+
|
49
|
+
require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
|
50
|
+
load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
|
51
|
+
|
52
|
+
if in_memory_database?
|
53
|
+
load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
|
54
|
+
ActiveRecord::Migrator.up('db/migrate') # use migrations
|
55
|
+
end
|
56
|
+
|
57
|
+
::Spec::Runner::CommandLine.run(
|
58
|
+
::Spec::Runner::OptionParser.parse(
|
59
|
+
argv,
|
60
|
+
$stderr,
|
61
|
+
$stdout
|
62
|
+
)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def in_memory_database?
|
67
|
+
ENV["RAILS_ENV"] == "test" and
|
68
|
+
::ActiveRecord::Base.connection.class.to_s == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" and
|
69
|
+
::Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
puts "Loading Rails environment"
|
75
|
+
|
76
|
+
ENV["RAILS_ENV"] = "test"
|
77
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
78
|
+
require 'dispatcher'
|
79
|
+
|
80
|
+
def restart_test_server
|
81
|
+
puts "restarting"
|
82
|
+
config = ::Config::CONFIG
|
83
|
+
ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
|
84
|
+
command_line = [ruby, $0, ARGV].flatten.join(' ')
|
85
|
+
exec(command_line)
|
86
|
+
end
|
87
|
+
|
88
|
+
def daemonize(pid_file = nil)
|
89
|
+
return yield if $DEBUG
|
90
|
+
pid = Process.fork{
|
91
|
+
Process.setsid
|
92
|
+
Dir.chdir(RAILS_ROOT)
|
93
|
+
trap("SIGINT"){ exit! 0 }
|
94
|
+
trap("SIGTERM"){ exit! 0 }
|
95
|
+
trap("SIGHUP"){ restart_test_server }
|
96
|
+
File.open("/dev/null"){|f|
|
97
|
+
STDERR.reopen f
|
98
|
+
STDIN.reopen f
|
99
|
+
STDOUT.reopen f
|
100
|
+
}
|
101
|
+
yield
|
102
|
+
}
|
103
|
+
puts "spec_server launched. (PID: %d)" % pid
|
104
|
+
File.open(pid_file,"w"){|f| f.puts pid } if pid_file
|
105
|
+
exit! 0
|
106
|
+
end
|
107
|
+
|
108
|
+
options = Hash.new
|
109
|
+
opts = OptionParser.new
|
110
|
+
opts.on("-d", "--daemon"){|v| options[:daemon] = true }
|
111
|
+
opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
|
112
|
+
opts.parse!(ARGV)
|
113
|
+
|
114
|
+
puts "Ready"
|
115
|
+
exec_server = lambda {
|
116
|
+
trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
|
117
|
+
DRb.start_service("druby://127.0.0.1:8989", Spec::Runner::RailsSpecServer.new)
|
118
|
+
DRb.thread.join
|
119
|
+
}
|
120
|
+
|
121
|
+
if options[:daemon]
|
122
|
+
daemonize(options[:pid], &exec_server)
|
123
|
+
else
|
124
|
+
exec_server.call
|
125
|
+
end
|
data/examples/rails/spec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
../.shared_specs
|
@@ -0,0 +1,38 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class Test::Unit::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
#
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
22
|
+
self.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
28
|
+
# then set this back to true.
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
+
#
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
+
# -- they do not yet inherit this setting
|
35
|
+
fixtures :all
|
36
|
+
|
37
|
+
# Add more helper methods to be used by all tests here...
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
get '/' do
|
2
|
+
"You said #{ params[:say] || 'nothing' }"
|
3
|
+
end
|
4
|
+
post '/' do
|
5
|
+
"You said #{ params[:say] || 'nothing' }"
|
6
|
+
end
|
7
|
+
|
8
|
+
# can i roll these into 1?
|
9
|
+
get '/print-method' do
|
10
|
+
request.request_method.downcase
|
11
|
+
end
|
12
|
+
put '/print-method' do
|
13
|
+
request.request_method.downcase
|
14
|
+
end
|
15
|
+
post '/print-method' do
|
16
|
+
request.request_method.downcase
|
17
|
+
end
|
18
|
+
|
19
|
+
get '/print-session' do
|
20
|
+
session[:session_variable] = params[:session_variable] if params[:session_variable]
|
21
|
+
session[:session_variable].to_s
|
22
|
+
end
|
23
|
+
post '/print-session' do
|
24
|
+
session[:session_variable] = params[:session_variable] if params[:session_variable]
|
25
|
+
session[:session_variable].to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
get '/redirect' do
|
29
|
+
redirect params[:to]
|
30
|
+
end
|
31
|
+
|
32
|
+
get '/relative' do
|
33
|
+
redirect '/i_am_relative'
|
34
|
+
end
|
35
|
+
|
36
|
+
get '/some_text' do
|
37
|
+
'hello there, how goes it?'
|
38
|
+
end
|
39
|
+
|
40
|
+
get '/some_html' do
|
41
|
+
haml :some_html
|
42
|
+
end
|
43
|
+
|
44
|
+
use_in_file_templates!
|
45
|
+
|
46
|
+
__END__
|
47
|
+
|
48
|
+
@@ layout
|
49
|
+
%html
|
50
|
+
%body
|
51
|
+
= yield
|
52
|
+
|
53
|
+
@@ some_html
|
54
|
+
%p#this-one
|
55
|
+
%p#bacon-one
|
56
|
+
#chunky-one
|
57
|
+
%b chunky one
|
58
|
+
%div
|
@@ -0,0 +1 @@
|
|
1
|
+
../.shared_specs
|
data/lib/rackbox/rackbox.rb
CHANGED
@@ -31,5 +31,37 @@ class RackBox
|
|
31
31
|
end
|
32
32
|
@app
|
33
33
|
end
|
34
|
+
|
35
|
+
# helper method for taking a Hash of params and turning them into POST params
|
36
|
+
#
|
37
|
+
# >> RackBox.build_query :hello => 'there'
|
38
|
+
# => 'hello=there'
|
39
|
+
#
|
40
|
+
# >> RackBox.build_query :hello => 'there', :foo => 'bar'
|
41
|
+
# => 'hello=there&foo=bar'
|
42
|
+
#
|
43
|
+
# >> RackBox.build_query :user => { :name => 'bob', :password => 'secret' }
|
44
|
+
# => 'user[name]=bob&user[password]=secret'
|
45
|
+
#
|
46
|
+
def build_query params_hash = { }
|
47
|
+
# check to make sure no values are Hashes ...
|
48
|
+
# if they are, we need to flatten them!
|
49
|
+
params_hash.each do |key, value|
|
50
|
+
# params_hash :a => { :b => X, :c => Y }
|
51
|
+
# needs to be 'a[b]' => X, 'a[b]' => Y
|
52
|
+
if value.is_a? Hash
|
53
|
+
inner_hash = params_hash.delete key # { :b => X, :c => Y }
|
54
|
+
inner_hash.each do |subkey, subvalue|
|
55
|
+
new_key = "#{ key }[#{ subkey }]" # a[b] or a[c]
|
56
|
+
puts "warning: overwriting query parameter #{ new_key }" if params_hash[new_key]
|
57
|
+
params_hash[new_key] = subvalue # 'a[b]' => X or a[c] => Y
|
58
|
+
end
|
59
|
+
# we really shouldn't keep going thru the #each now that we've altered data!
|
60
|
+
return build_query(params_hash)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
Rack::Utils.build_query params_hash
|
64
|
+
end
|
65
|
+
|
34
66
|
end
|
35
67
|
end
|
@@ -39,6 +39,17 @@ if spec_configuration_class
|
|
39
39
|
default_url_options[:host] = 'example.com'
|
40
40
|
end
|
41
41
|
|
42
|
+
# if we're not in a Rails app, let's try to load matchers from Webrat
|
43
|
+
unless defined?RAILS_ENV
|
44
|
+
begin
|
45
|
+
require 'webrat'
|
46
|
+
require 'webrat/core/matchers'
|
47
|
+
include Webrat::HaveTagMatcher
|
48
|
+
rescue LoadError
|
49
|
+
puts "Webrat not available. have_tag & other matchers won't be available. to install, sudo gem install webrat"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
42
53
|
attr_accessor :rackbox_request
|
43
54
|
}
|
44
55
|
end
|
data/lib/rackbox/spec/helpers.rb
CHANGED
@@ -26,7 +26,7 @@ module RackBox::SpecHelpers
|
|
26
26
|
def req url, options = {}
|
27
27
|
options[:method] ||= (options[:params]) ? :post : :get # if params, default to POST, else default to GET
|
28
28
|
options[:params] ||= { }
|
29
|
-
@rackbox_request.send options[:method], url, :input =>
|
29
|
+
@rackbox_request.send options[:method], url, :input => RackBox.build_query(options[:params])
|
30
30
|
end
|
31
31
|
|
32
32
|
alias request req unless defined? request
|