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.
Files changed (80) hide show
  1. data/README.markdown +6 -0
  2. data/Rakefile +57 -0
  3. data/VERSION.yml +2 -2
  4. data/examples/rack/config.ru +53 -0
  5. data/examples/rack/run-specs +2 -0
  6. data/examples/rack/spec +1 -0
  7. data/examples/rails/README +256 -0
  8. data/examples/rails/Rakefile +10 -0
  9. data/examples/rails/app/controllers/application.rb +15 -0
  10. data/examples/rails/app/controllers/welcome_controller.rb +32 -0
  11. data/examples/rails/app/helpers/application_helper.rb +3 -0
  12. data/examples/rails/app/helpers/welcome_helper.rb +2 -0
  13. data/examples/rails/app/views/layouts/application.html.erb +7 -0
  14. data/examples/rails/app/views/welcome/some_html.html.erb +20 -0
  15. data/examples/rails/config/boot.rb +109 -0
  16. data/examples/rails/config/database.yml +22 -0
  17. data/examples/rails/config/environment.rb +75 -0
  18. data/examples/rails/config/environments/development.rb +17 -0
  19. data/examples/rails/config/environments/production.rb +24 -0
  20. data/examples/rails/config/environments/test.rb +22 -0
  21. data/examples/rails/config/initializers/inflections.rb +10 -0
  22. data/examples/rails/config/initializers/mime_types.rb +5 -0
  23. data/examples/rails/config/initializers/new_rails_defaults.rb +17 -0
  24. data/examples/rails/config/locales/en.yml +5 -0
  25. data/examples/rails/config/routes.rb +12 -0
  26. data/examples/rails/db/development.sqlite3 +0 -0
  27. data/examples/rails/db/schema.rb +14 -0
  28. data/examples/rails/db/test.sqlite3 +0 -0
  29. data/examples/rails/doc/README_FOR_APP +5 -0
  30. data/examples/rails/lib/tasks/rspec.rake +158 -0
  31. data/examples/rails/public/404.html +30 -0
  32. data/examples/rails/public/422.html +30 -0
  33. data/examples/rails/public/500.html +33 -0
  34. data/examples/rails/public/dispatch.cgi +10 -0
  35. data/examples/rails/public/dispatch.fcgi +24 -0
  36. data/examples/rails/public/dispatch.rb +10 -0
  37. data/examples/rails/public/favicon.ico +0 -0
  38. data/examples/rails/public/images/rails.png +0 -0
  39. data/examples/rails/public/javascripts/application.js +2 -0
  40. data/examples/rails/public/javascripts/controls.js +963 -0
  41. data/examples/rails/public/javascripts/dragdrop.js +973 -0
  42. data/examples/rails/public/javascripts/effects.js +1128 -0
  43. data/examples/rails/public/javascripts/prototype.js +4320 -0
  44. data/examples/rails/public/robots.txt +5 -0
  45. data/examples/rails/run-specs +2 -0
  46. data/examples/rails/script/about +4 -0
  47. data/examples/rails/script/autospec +5 -0
  48. data/examples/rails/script/console +3 -0
  49. data/examples/rails/script/dbconsole +3 -0
  50. data/examples/rails/script/destroy +3 -0
  51. data/examples/rails/script/generate +3 -0
  52. data/examples/rails/script/performance/benchmarker +3 -0
  53. data/examples/rails/script/performance/profiler +3 -0
  54. data/examples/rails/script/performance/request +3 -0
  55. data/examples/rails/script/plugin +3 -0
  56. data/examples/rails/script/process/inspector +3 -0
  57. data/examples/rails/script/process/reaper +3 -0
  58. data/examples/rails/script/process/spawner +3 -0
  59. data/examples/rails/script/runner +3 -0
  60. data/examples/rails/script/server +3 -0
  61. data/examples/rails/script/spec +5 -0
  62. data/examples/rails/script/spec_server +125 -0
  63. data/examples/rails/spec +1 -0
  64. data/examples/rails/test/functional/welcome_controller_test.rb +8 -0
  65. data/examples/rails/test/performance/browsing_test.rb +9 -0
  66. data/examples/rails/test/test_helper.rb +38 -0
  67. data/examples/sinatra/config.ru +11 -0
  68. data/examples/sinatra/run-specs +2 -0
  69. data/examples/sinatra/sinatra_app.rb +58 -0
  70. data/examples/sinatra/spec +1 -0
  71. data/lib/rackbox/rack/extensions_for_rspec.rb +2 -0
  72. data/lib/rackbox/rackbox.rb +32 -0
  73. data/lib/rackbox/spec/configuration.rb +11 -0
  74. data/lib/rackbox/spec/helpers.rb +1 -1
  75. data/rails_generators/blackbox_spec/USAGE +5 -0
  76. data/rails_generators/blackbox_spec/blackbox_spec_generator.rb +56 -0
  77. data/rails_generators/blackbox_spec/templates/spec.erb +9 -0
  78. data/spec/rackbox_spec.rb +35 -0
  79. data/spec/spec_helper.rb +1 -0
  80. metadata +106 -2
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,2 @@
1
+ #! /bin/bash
2
+ rake spec
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -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,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/request'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/inspector'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/reaper'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/spawner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/server'
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
3
+ require 'rubygems'
4
+ require 'spec'
5
+ exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
@@ -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
@@ -0,0 +1 @@
1
+ ../.shared_specs
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class WelcomeControllerTest < ActionController::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -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,11 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+
4
+ Sinatra::Application.default_options.merge!(
5
+ :run => false,
6
+ :env => :production
7
+ )
8
+
9
+ require 'sinatra_app'
10
+ use Rack::Session::Cookie
11
+ run Sinatra.application
@@ -0,0 +1,2 @@
1
+ #! /bin/bash
2
+ spec --color spec/*/*_spec.rb
@@ -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
@@ -1,6 +1,8 @@
1
1
  # some more Rack extensions to help when testing
2
2
  class Rack::MockResponse
3
3
 
4
+ # TODO checkout Rack::Response::Helpers which implements many of these!
5
+
4
6
  # these methods help with RSpec specs so we can ask things like:
5
7
  #
6
8
  # request('/').should be_successful
@@ -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
@@ -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 => Rack::Utils.build_query(options[:params])
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
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Creates a new blackbox spec (using RackBox)
3
+
4
+ Examples:
5
+ `./script/generate blackbox_spec`