Permalink
Browse files

Encourage `RACK_ENV=test` environment variable setup instead of `set …

…:environment`

In order to avoid these kind of issues sinatra/sinatra#741
  • Loading branch information...
1 parent cf47cb6 commit 783c236612e544d9ef2d1a9ddd2854495d79cd3a Francesco Rodríguez committed Aug 11, 2013
Showing with 13 additions and 10 deletions.
  1. +13 −10 testing.markdown
View
23 testing.markdown
@@ -38,12 +38,12 @@ makes a few helper methods and attributes available.
The following is a simple example that ensures the hello world app functions
properly:
+ ENV['RACK_ENV'] = 'test'
+
require 'hello_world'
require 'test/unit'
require 'rack/test'
- ENV['RACK_ENV'] = 'test'
-
class HelloWorldTest < Test::Unit::TestCase
include Rack::Test::Methods
@@ -69,13 +69,12 @@ For a variety of reasons you may not want to include `Rack::Test::Methods`
into your own classes. `Rack::Test` supports this style of testing as well,
here is the above example without using Mixin.
+ ENV['RACK_ENV'] = 'test'
require 'hello_world'
require 'test/unit'
require 'rack/test'
- set :environment, :test
-
class HelloWorldTest < Test::Unit::TestCase
def test_it_says_hello_world
@@ -183,12 +182,12 @@ removed in Sinatra `1.0`.
Sinatra can be tested under plain RSpec. The `Rack::Test` module should be
included within the `describe` block:
+ ENV['RACK_ENV'] = 'test'
+
require 'hello_world' # <-- your sinatra app
require 'rspec'
require 'rack/test'
- set :environment, :test
-
describe 'The HelloWorld App' do
include Rack::Test::Methods
@@ -217,12 +216,12 @@ Make `Rack::Test` available to all spec contexts by including it via
Testing with Bacon is similar to `test/unit` and RSpec:
+ ENV['RACK_ENV'] = 'test'
+
require 'hello_world' # <-- your sinatra app
require 'bacon'
require 'rack/test'
- set :environment, :test
-
describe 'The HelloWorld App' do
extend Rack::Test::Methods
@@ -249,12 +248,12 @@ Make `Rack::Test` available to all spec contexts by including it in
The `Rack::Test` module should be included within the context of the
`describe` block:
+ ENV['RACK_ENV'] = 'test'
+
require 'hello_world' # <-- your sinatra app
require 'test/spec'
require 'rack/test'
- set :environment, :test
-
describe 'The HelloWorld App' do
include Rack::Test::Methods
@@ -281,6 +280,8 @@ Make `Rack::Test` available to all spec contexts by including it in
From `Webrat`'s wiki where you'll find more [examples][].
+ ENV['RACK_ENV'] = 'test'
+
require 'hello_world' # <-- your sinatra app
require 'rack/test'
require 'test/unit'
@@ -309,6 +310,8 @@ From `Webrat`'s wiki where you'll find more [examples][].
`Capybara` will use `Rack::Test` by default. You can use another driver, like
`Selenium`, by setting the default_driver.
+ ENV['RACK_ENV'] = 'test'
+
require 'hello_world' # <-- your sinatra app
require 'capybara'
require 'capybara/dsl'

0 comments on commit 783c236

Please sign in to comment.