Skip to content

Commit

Permalink
Encourage RACK_ENV=test environment variable setup instead of `set …
Browse files Browse the repository at this point in the history
…:environment`

In order to avoid these kind of issues sinatra/sinatra#741
  • Loading branch information
Francesco Rodríguez committed Aug 11, 2013
1 parent cf47cb6 commit 783c236
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions testing.markdown
Expand Up @@ -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 The following is a simple example that ensures the hello world app functions
properly: properly:


ENV['RACK_ENV'] = 'test'

require 'hello_world' require 'hello_world'
require 'test/unit' require 'test/unit'
require 'rack/test' require 'rack/test'


ENV['RACK_ENV'] = 'test'

class HelloWorldTest < Test::Unit::TestCase class HelloWorldTest < Test::Unit::TestCase
include Rack::Test::Methods include Rack::Test::Methods


Expand All @@ -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, into your own classes. `Rack::Test` supports this style of testing as well,
here is the above example without using Mixin. here is the above example without using Mixin.


ENV['RACK_ENV'] = 'test'


require 'hello_world' require 'hello_world'
require 'test/unit' require 'test/unit'
require 'rack/test' require 'rack/test'


set :environment, :test

class HelloWorldTest < Test::Unit::TestCase class HelloWorldTest < Test::Unit::TestCase


def test_it_says_hello_world def test_it_says_hello_world
Expand Down Expand Up @@ -183,12 +182,12 @@ removed in Sinatra `1.0`.
Sinatra can be tested under plain RSpec. The `Rack::Test` module should be Sinatra can be tested under plain RSpec. The `Rack::Test` module should be
included within the `describe` block: included within the `describe` block:


ENV['RACK_ENV'] = 'test'

require 'hello_world' # <-- your sinatra app require 'hello_world' # <-- your sinatra app
require 'rspec' require 'rspec'
require 'rack/test' require 'rack/test'


set :environment, :test

describe 'The HelloWorld App' do describe 'The HelloWorld App' do
include Rack::Test::Methods include Rack::Test::Methods


Expand Down Expand Up @@ -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: Testing with Bacon is similar to `test/unit` and RSpec:


ENV['RACK_ENV'] = 'test'

require 'hello_world' # <-- your sinatra app require 'hello_world' # <-- your sinatra app
require 'bacon' require 'bacon'
require 'rack/test' require 'rack/test'


set :environment, :test

describe 'The HelloWorld App' do describe 'The HelloWorld App' do
extend Rack::Test::Methods extend Rack::Test::Methods


Expand All @@ -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 The `Rack::Test` module should be included within the context of the
`describe` block: `describe` block:


ENV['RACK_ENV'] = 'test'

require 'hello_world' # <-- your sinatra app require 'hello_world' # <-- your sinatra app
require 'test/spec' require 'test/spec'
require 'rack/test' require 'rack/test'


set :environment, :test

describe 'The HelloWorld App' do describe 'The HelloWorld App' do
include Rack::Test::Methods include Rack::Test::Methods


Expand All @@ -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][]. From `Webrat`'s wiki where you'll find more [examples][].


ENV['RACK_ENV'] = 'test'

require 'hello_world' # <-- your sinatra app require 'hello_world' # <-- your sinatra app
require 'rack/test' require 'rack/test'
require 'test/unit' require 'test/unit'
Expand Down Expand Up @@ -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 `Capybara` will use `Rack::Test` by default. You can use another driver, like
`Selenium`, by setting the default_driver. `Selenium`, by setting the default_driver.


ENV['RACK_ENV'] = 'test'

require 'hello_world' # <-- your sinatra app require 'hello_world' # <-- your sinatra app
require 'capybara' require 'capybara'
require 'capybara/dsl' require 'capybara/dsl'
Expand Down

0 comments on commit 783c236

Please sign in to comment.