remi-rackbox 0.0.6

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 (72) hide show
  1. data/README.markdown +77 -0
  2. data/examples/rack/config.ru +4 -0
  3. data/examples/rack/run-specs +2 -0
  4. data/examples/rack/spec/blackbox/home_page_spec.rb +14 -0
  5. data/examples/rack/spec/rcov.opts +2 -0
  6. data/examples/rack/spec/spec.opts +4 -0
  7. data/examples/rack/spec/spec_helper.rb +6 -0
  8. data/examples/rails/README +256 -0
  9. data/examples/rails/Rakefile +10 -0
  10. data/examples/rails/app/controllers/application.rb +15 -0
  11. data/examples/rails/app/controllers/welcome_controller.rb +5 -0
  12. data/examples/rails/app/helpers/application_helper.rb +3 -0
  13. data/examples/rails/app/helpers/welcome_helper.rb +2 -0
  14. data/examples/rails/config/boot.rb +109 -0
  15. data/examples/rails/config/environment.rb +75 -0
  16. data/examples/rails/config/environments/development.rb +17 -0
  17. data/examples/rails/config/environments/production.rb +24 -0
  18. data/examples/rails/config/environments/test.rb +22 -0
  19. data/examples/rails/config/initializers/inflections.rb +10 -0
  20. data/examples/rails/config/initializers/mime_types.rb +5 -0
  21. data/examples/rails/config/initializers/new_rails_defaults.rb +17 -0
  22. data/examples/rails/config/locales/en.yml +5 -0
  23. data/examples/rails/config/routes.rb +43 -0
  24. data/examples/rails/db/development.sqlite3 +0 -0
  25. data/examples/rails/db/schema.rb +14 -0
  26. data/examples/rails/db/test.sqlite3 +0 -0
  27. data/examples/rails/doc/README_FOR_APP +5 -0
  28. data/examples/rails/lib/tasks/rspec.rake +158 -0
  29. data/examples/rails/public/404.html +30 -0
  30. data/examples/rails/public/422.html +30 -0
  31. data/examples/rails/public/500.html +33 -0
  32. data/examples/rails/public/dispatch.cgi +10 -0
  33. data/examples/rails/public/dispatch.fcgi +24 -0
  34. data/examples/rails/public/dispatch.rb +10 -0
  35. data/examples/rails/public/favicon.ico +0 -0
  36. data/examples/rails/public/images/rails.png +0 -0
  37. data/examples/rails/public/javascripts/application.js +2 -0
  38. data/examples/rails/public/javascripts/controls.js +963 -0
  39. data/examples/rails/public/javascripts/dragdrop.js +973 -0
  40. data/examples/rails/public/javascripts/effects.js +1128 -0
  41. data/examples/rails/public/javascripts/prototype.js +4320 -0
  42. data/examples/rails/public/robots.txt +5 -0
  43. data/examples/rails/run-specs +2 -0
  44. data/examples/rails/script/about +4 -0
  45. data/examples/rails/script/autospec +5 -0
  46. data/examples/rails/script/console +3 -0
  47. data/examples/rails/script/dbconsole +3 -0
  48. data/examples/rails/script/destroy +3 -0
  49. data/examples/rails/script/generate +3 -0
  50. data/examples/rails/script/performance/benchmarker +3 -0
  51. data/examples/rails/script/performance/profiler +3 -0
  52. data/examples/rails/script/performance/request +3 -0
  53. data/examples/rails/script/plugin +3 -0
  54. data/examples/rails/script/process/inspector +3 -0
  55. data/examples/rails/script/process/reaper +3 -0
  56. data/examples/rails/script/process/spawner +3 -0
  57. data/examples/rails/script/runner +3 -0
  58. data/examples/rails/script/server +3 -0
  59. data/examples/rails/script/spec +5 -0
  60. data/examples/rails/script/spec_server +125 -0
  61. data/examples/rails/spec/blackbox/home_page_spec.rb +21 -0
  62. data/examples/rails/spec/rcov.opts +2 -0
  63. data/examples/rails/spec/spec.opts +4 -0
  64. data/examples/rails/spec/spec_helper.rb +11 -0
  65. data/examples/rails/test/functional/welcome_controller_test.rb +8 -0
  66. data/examples/rails/test/performance/browsing_test.rb +9 -0
  67. data/examples/rails/test/test_helper.rb +38 -0
  68. data/lib/rackbox.rb +105 -0
  69. data/lib/rackbox/rack_content_length_fix.rb +19 -0
  70. data/rackbox.gemspec +17 -0
  71. data/run-specs +11 -0
  72. metadata +136 -0
@@ -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,21 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe 'Home Page' do
4
+
5
+ it 'should say something by itself' do
6
+ req( '/' ).body.should include('You said nothing')
7
+
8
+ # this works, but you should probably be careful using
9
+ # 'request' and 'response' in Rails specs ... ?
10
+
11
+ request( '/' ).body.should include('You said nothing')
12
+
13
+ response = req( '/' )
14
+ response.body.should include('You said nothing')
15
+ end
16
+
17
+ it 'should say whatever I tell it to' do
18
+ req( '/', :method => :post, :params => { :say => 'hello' } ).body.should include('You said hello')
19
+ end
20
+
21
+ end
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,11 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] = "test"
4
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
5
+ require 'spec'
6
+ require 'spec/rails'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../../../lib/rackbox")
8
+
9
+ Spec::Runner.configure do |config|
10
+ config.use_blackbox = true
11
+ end
@@ -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
data/lib/rackbox.rb ADDED
@@ -0,0 +1,105 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'rubygems'
3
+ begin
4
+ require 'thin' # required for Rails pre Rails 2.3, as Thin has the Rack::Adapter::Rails
5
+ rescue LoadError
6
+ end
7
+ require 'rack'
8
+ require 'rackbox/rack_content_length_fix'
9
+
10
+ # To add blackbox testing to a Rails app,
11
+ # in your spec_helper.rb
12
+ #
13
+ # require 'rackbox'
14
+ #
15
+ # Spec::Runner.configure do |config|
16
+ # config.use_blackbox = true
17
+ # end
18
+ #
19
+ class RackBox
20
+ class << self
21
+ # the Rack appliction to do 'Black Box' testing against
22
+ #
23
+ # To set, in your spec_helper.rb or someplace:
24
+ # RackBox.app = Rack::Adapter::Rails.new :root => '/root/directory/of/rails/app', :environment => 'test'
25
+ #
26
+ # If not explicitly set, uses RAILS_ROOT (if defined?) and RAILS_ENV (if defined?)
27
+ attr_accessor :app
28
+
29
+ def app
30
+ unless @app and @app.respond_to?:call
31
+ if File.file? 'config.ru'
32
+ @app = Rack::Builder.new { eval(File.read('config.ru')) }
33
+ elsif defined?RAILS_ENV and defined?RAILS_ROOT
34
+ raise "You need the Rack::Adapter::Rails to run Rails apps with RackBox." +
35
+ " Try: sudo gem install thin" unless defined?Rack::Adapter::Rails
36
+ @app = Rack::Adapter::Rails.new :root => RAILS_ROOT, :environment => RAILS_ENV
37
+ else
38
+ raise "RackBox.app not configured."
39
+ end
40
+ end
41
+ @app
42
+ end
43
+ end
44
+ end
45
+
46
+ module RackBox::SpecHelpers
47
+ # A port of Merb's request() method, used in tests
48
+ #
49
+ # At the moment, we're using #req instead because #request conflicts
50
+ # with an existing RSpec-Rails method
51
+ #
52
+ # Usage:
53
+ #
54
+ # req '/'
55
+ # req login_path
56
+ # req url_for(:controller => 'login')
57
+ #
58
+ # req '/', :method => :post, :params => { 'chunky' => 'bacon' }
59
+ #
60
+ # TODO support inner hashes, so { :foo => { :chunky => :bacon } } becomes 'foo[chunky]=bacon'
61
+ #
62
+ # TODO take any additional options and pass them along to the environment, so we can say
63
+ # req '/', :user_agent => 'some custom user agent'
64
+ #
65
+ def req url, options = {}
66
+ options[:method] ||= :get
67
+ options[:params] ||= { }
68
+ Rack::MockRequest.new(RackBox.app).send options[:method], url, :input => Rack::Utils.build_query(options[:params])
69
+ end
70
+
71
+ alias request req unless defined? request
72
+ end
73
+
74
+ spec_configuration_class = nil
75
+ spec_configuration_class = Spec::Example::Configuration if defined? Spec::Example::Configuration
76
+ spec_configuration_class = Spec::Runner::Configuration if defined? Spec::Runner::Configuration
77
+
78
+ if spec_configuration_class
79
+ spec_configuration_class.class_eval do
80
+ # Adds blackbox testing to your Rails application using RackBox.
81
+ #
82
+ # To use, put your 'blackbox' specs into the spec/blackbox
83
+ # directory, eg. spec/blackbox/login_spec.rb
84
+ #
85
+ # In these specs, the RackBox::SpecHelpers#req method will be available to you
86
+ #
87
+ def use_blackbox= bool
88
+ if bool == true
89
+ before(:all, :type => :blackbox) do
90
+ self.class.instance_eval {
91
+ # include our own helpers, eg. RackBox::SpecHelpers#req
92
+ include RackBox::SpecHelpers
93
+
94
+ # include generated url methods, eg. login_path.
95
+ # default_url_options needs to have a host set for the Urls to work
96
+ if defined?ActionController::UrlWriter
97
+ include ActionController::UrlWriter
98
+ default_url_options[:host] = 'example.com'
99
+ end
100
+ }
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,19 @@
1
+ # An evil fix
2
+ #
3
+ # The actual fix
4
+ # has been pulled upstream into Rack
5
+ # but hasn't made it into the Rack gem yet, so we need this fix until the new gem is released
6
+ #
7
+ class Rack::MockRequest
8
+ class << self
9
+
10
+ alias env_for_without_content_length_fix env_for
11
+ def env_for_with_content_length_fix uri = '', opts = {}
12
+ env = env_for_without_content_length_fix uri, opts
13
+ env['CONTENT_LENGTH'] ||= env['rack.input'].length
14
+ env
15
+ end
16
+ alias env_for env_for_with_content_length_fix
17
+
18
+ end
19
+ end