Permalink
Browse files

explicit require form to support 1.8 and newer rubies, fixes #23

  • Loading branch information...
1 parent 829aa8c commit ea4dbcb2ce04d754c9a0f8a5ea3e6d562de22567 @zzak zzak committed Mar 16, 2013
@@ -52,7 +52,7 @@ rackup file, `config.ru`.
require 'rubygems'
require 'sinatra'
- require 'app.rb'
+ require File.expand_path '../app.rb', __FILE__
run Sinatra::Application
@@ -24,7 +24,7 @@ via Passenger with relative ease. Here's how.
`myapp.rb`. Second, run your application. If you're subclassing, use the
subclass's name, otherwise use Sinatra::Application.
- require "myapp"
+ require File.expand_path '../myapp.rb', __FILE__
run Sinatra::Application
View
@@ -53,7 +53,7 @@ Of course, you can use a config.ru and rackup as well:
cat <<EOF>config.ru
require 'rubygems'
require 'sinatra'
- require 'hello'
+ require File.expand_path '../hello.rb', __FILE__
run Sinatra::Application
EOF
@@ -145,4 +145,4 @@ craft it to suit your fancy. Read up on TorqueBox's benchmarking efforts at
[trinidad]: http://thinkincode.net/trinidad/
[glassfish]: http://glassfish.java.net/
[jetty]: http://jetty.codehaus.org/jetty/
-[jetty-rackup]: https://github.com/geekq/jetty-rackup
+[jetty-rackup]: https://github.com/geekq/jetty-rackup
@@ -18,7 +18,7 @@ proxy setup using Lighttpd and Thin.
## This is not needed for Thin > 1.0.0
ENV['RACK_ENV'] = "production"
- require 'app'
+ require File.expand_path '../app.rb', __FILE__
run Sinatra::Application
@@ -26,7 +26,7 @@ application root.
require "rubygems"
require "sinatra"
- require 'myapp.rb'
+ require File.expand_path '../myapp.rb', __FILE__
run MyApp
View
@@ -15,7 +15,7 @@ Usage is rather simple:
If you want to run a modular application, create a file named `config.ru` with
similar content:
- require 'my_app'
+ require File.expand_path '../my_app.rb', __FILE__
run MyApp
And run it by calling `shotgun` without arguments.
@@ -69,7 +69,7 @@ For classic applications:
#config.ru
- require './main'
+ require File.expand_path '../main.rb', __FILE__
app = Rack::Auth::Digest::MD5.new(Sinatra::Application) do |username|
{'foo' => 'bar'}[username]
@@ -106,7 +106,7 @@ For modular applications:
#config.ru
- require './main'
+ require File.expand_path '../main.rb', __FILE__
run Protected
@@ -157,7 +157,7 @@ And the `config.ru`
#config.ru
- require './main'
+ require File.expand_path '../main.rb', __FILE__
run Rack::URLMap.new({
"/" => Public,
@@ -209,7 +209,7 @@ And the `config.ru`
#config.ru
- require './main'
+ require File.expand_path '../main.rb', __FILE__
run Rack::URLMap.new({
"/" => Public,
View
@@ -7,11 +7,7 @@ After installing [Bacon][bc], setting it up works similar to `Test::Unit`:
require 'bacon'
require 'rack/test'
- begin
- require_relative 'my-app.rb'
- rescue NameError
- require File.expand_path('my-app.rb', __FILE__)
- end
+ require File.expand_path '../my-app.rb', __FILE__
module TestMixin
include Rack::Test::Methods
@@ -16,21 +16,13 @@ Using Capybara
config.include Capybara
end
- begin
- require_relative '../../my-app.rb'
- rescue NameError
- require File.expand_path('../../my-app.rb', __FILE__)
- end
+ require File.expand_path '../../../my-app.rb', __FILE__
Capybara.app = Sinatra::Application
**My Page Acceptance Spec**
- begin
- require_relative 'acceptance_helper'
- rescue NameError
- require File.expand_path('acceptance_helper', __FILE__)
- end
+ require File.expand_path '../acceptance_helper.rb', __FILE__
feature "My Page" do
View
@@ -15,20 +15,12 @@ all the setup in there:
require 'minitest/autorun'
require 'rack/test'
- begin
- require_relative 'my-app'
- rescue NameError
- require File.expand_path('my-app', __FILE__)
- end
+ require File.expand_path '../my-app.rb', __FILE__
In your test files you only have to require that helper:
# test.rb
- begin
- require_relative 'test_helper'
- rescue NameError
- require File.expand_path('test_helper', __FILE__)
- end
+ require File.expand_path '../test_helper.rb', __FILE__
class MyTest < MiniTest::Unit::TestCase
@@ -61,11 +53,7 @@ instead of
**Specs**
- begin
- require_relative 'test_helper'
- rescue NameError
- require File.expand_path('test_helper', __FILE__)
- end
+ require File.expand_path '../test_helper.rb', __FILE__
include Rack::Test::Methods
@@ -82,11 +70,7 @@ instead of
**Benchmarks**
- begin
- require_relative 'test_helper'
- rescue NameError
- require File.expand_path('test_helper', __FILE__)
- end
+ require File.expand_path '../test_helper.rb', __FILE__
require 'minitest/benchmark'
View
@@ -7,11 +7,7 @@ After installing [MSpec][ms], you set it up like this:
require 'mspec'
require 'rack/test'
- begin
- require_relative 'my-app.rb'
- rescue NameError
- require File.expand_path('my-app.rb', __FILE__)
- end
+ require File.expand_path '../my-app.rb', __FILE__
include Rack::Test::Methods
def app() Sinatra::Application end
View
@@ -7,11 +7,7 @@ After installing [Protest][pt], setting it up works similar to `Test::Unit`:
require 'protest'
require 'rack/test'
- begin
- require_relative 'my-app.rb'
- rescue NameError
- require File.expand_path('my-app.rb', __FILE__)
- end
+ require File.expand_path '../my-app.rb', __FILE__
module TestMixin
include Rack::Test::Methods
View
@@ -14,11 +14,7 @@ In your spec file or your spec helper, you can setup `Rack::Test` like this:
require 'test/unit'
require 'rack/test'
- begin
- require_relative 'my-app'
- rescue NameError
- require File.expand_path('my-app', __FILE__)
- end
+ require File.expand_path '../my-app.rb', __FILE__
module TestMixin
include Rack::Test::Methods
@@ -29,11 +25,8 @@ In your spec file or your spec helper, you can setup `Rack::Test` like this:
And use it in your specs:
- begin
- require_relative '../spec_helper'
- rescue NameError
- require File.expand_path('../spec_helper', __FILE__)
- end
+ # spec/app/app_spec.rb
+ require File.expand_path '../../spec_helper.rb', __FILE__
describe "My Sinatra Application" do
it "should allow accessing the home page" do
View
@@ -5,11 +5,7 @@ RSpec 2.x
require 'rack/test'
- begin
- require_relative '../my-app.rb'
- rescue NameError
- require File.expand_path('../my-app.rb', __FILE__)
- end
+ require File.expand_path '../../my-app.rb', __FILE__
module RSpecMixin
include Rack::Test::Methods
@@ -30,11 +26,7 @@ instead of
[Shared Example Groups](http://relishapp.com/rspec/rspec-core/v/2-3/dir/example-groups/shared-example-group)
- begin
- require_relative 'spec_helper'
- rescue NameError
- require File.expand_path('spec_helper', __FILE__)
- end
+ File.expand_path '../spec_helper.rb', __FILE__
shared_examples_for "my example app" do
before(:each) do
View
@@ -12,11 +12,8 @@ defining `app`:
require 'test/unit'
require 'rack/test'
- begin
- require_relative 'my-app.rb'
- rescue NameError
- require File.expand_path('my-app.rb', __FILE__)
- end
+
+ require File.expand_path '../my-app.rb', __FILE__
class HomepageTest < Test::Unit::TestCase
include Rack::Test:Methods
@@ -34,11 +31,7 @@ all you have to do is install them and add a `require 'contest'` or `require
**Shoulda**
- begin
- require_relative 'test_helper'
- rescue NameError
- require File.expand_path('test_helper', __FILE__)
- end
+ require File.expand_path '../test_helper.rb', __FILE__
class ExampleUnitTest < Test::Unit::TestCase
@@ -23,7 +23,7 @@ Features from Cucumber and Webrat
last_response.body.should match(/#{text}/m)
end
-**env.rb**
+**features/support/env.rb**
ENV['RACK_ENV'] = 'test'
@@ -32,11 +32,7 @@ Features from Cucumber and Webrat
require 'rspec/expectations'
require 'webrat'
- begin
- require_relative '../../my-app.rb'
- rescue NameError
- require File.expand_path('../../my-app.rb', __FILE__)
- end
+ require File.expand_path '../../../my-app.rb', __FILE__
Webrat.configure do |config|
config.mode = :rack

0 comments on commit ea4dbcb

Please sign in to comment.