Skip to content

Instantly share code, notes, and snippets.

@danmayer
Created January 6, 2012 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmayer/1568648 to your computer and use it in GitHub Desktop.
Save danmayer/1568648 to your computer and use it in GitHub Desktop.
A example of a bad I18n rails test... Found some tests failing in a project because tests in different files would change I18n.locale, changes like this make your tests fail if not run in your standard order.
require File.dirname(__FILE__) + '/../test_helper'
class FakeTest < ActiveSupport::TestCase
test "first de" do
puts "about to be de: #{I18n.locale}"
assert_equal 'en', "#{I18n.locale}"
I18n.locale = 'de'
assert true
end
test "then fr" do
puts "about to be fr: #{I18n.locale}"
assert_equal 'en', "#{I18n.locale}"
I18n.locale = 'fr'
assert true
end
end
######
#
# A example of a bad I18n rails test... Found some tests failing in a project because tests in different
# files would change I18n.locale, changes like this make your tests fail if not run in your standard order.
# Don't modify I18n.locale in test with out a block the resets it or a teardown to set back to default.
#
######
# ruby test/unit/fake_test.rb
# Loaded suite test/unit/fake_test
# Started
# about to be de: en
# .about to be fr: de
# F
# Finished in 0.019414 seconds.
# 1) Failure:
# test_then_fr(FakeTest) [test/unit/fake_test.rb:14]:
# <"en"> expected but was
# <"de">.
# 2 tests, 3 assertions, 1 failures, 0 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment