Skip to content

Commit

Permalink
Make sure that the test case is run under test env
Browse files Browse the repository at this point in the history
* Unset $RAILS_ENV that got set by abstract_unit to trigger the default.
* split out environment setting since Ruby 1.9.3 doesn't support inline
  ENV setting.
  • Loading branch information
sikachu committed Mar 11, 2013
1 parent 7cc588b commit 7734254
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion railties/test/application/test_runner_test.rb
Expand Up @@ -7,6 +7,7 @@ class TestRunnerTest < ActiveSupport::TestCase


def setup def setup
build_app build_app
ENV['RAILS_ENV'] = nil

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Mar 20, 2013

Member

Should not we storing the actual value of RAILS_ENV and restoring in the teardown method?

create_schema create_schema
end end


Expand All @@ -22,6 +23,20 @@ def test_should_not_display_heading
end end
end end


def test_run_in_test_environment
app_file 'test/unit/env_test.rb', <<-RUBY
require 'test_helper'
class EnvTest < ActiveSupport::TestCase
def test_env
puts "Current Environment: \#{Rails.env}"
end
end
RUBY

assert_match /Current Environment: test/, run_test_command('test/unit/env_test.rb')
end

def test_run_shortcut def test_run_shortcut
create_test_file :models, 'foo' create_test_file :models, 'foo'
output = Dir.chdir(app_path) { `bundle exec rails t test/models/foo_test.rb` } output = Dir.chdir(app_path) { `bundle exec rails t test/models/foo_test.rb` }
Expand Down Expand Up @@ -200,7 +215,8 @@ def test_env
end end
RUBY RUBY


assert_match /development/, Dir.chdir(app_path) { `RAILS_ENV=development bundle exec rails test test/unit/env_test.rb` } ENV['RAILS_ENV'] = 'development'
assert_match /development/, run_test_command('test/unit/env_test.rb')
end end


def test_run_different_environment_using_e_tag def test_run_different_environment_using_e_tag
Expand Down

0 comments on commit 7734254

Please sign in to comment.