aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/connection_handling.rb2
-rw-r--r--guides/source/testing.md13
2 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index 8f51590c99..984af79642 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -1,6 +1,6 @@
module ActiveRecord
module ConnectionHandling
- RAILS_ENV = -> { (Rails.env if defined?(Rails)) || ENV["RAILS_ENV"] || ENV["RACK_ENV"] }
+ RAILS_ENV = -> { (Rails.env if defined?(Rails.env)) || ENV["RAILS_ENV"] || ENV["RACK_ENV"] }
DEFAULT_ENV = -> { RAILS_ENV.call || "default_env" }
# Establishes the connection to the database. Accepts a hash as input where
diff --git a/guides/source/testing.md b/guides/source/testing.md
index c762379cca..f7103adc1c 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -371,6 +371,19 @@ behavior:
$ BACKTRACE=1 bin/rake test test/models/article_test.rb
```
+If we want this test to pass we can modify it to use `assert_raises` like so:
+
+```ruby
+test "should report error" do
+ # some_undefined_variable is not defined elsewhere in the test case
+ assert_raises(NameError) do
+ some_undefined_variable
+ end
+end
+```
+
+This test should now pass.
+
### Available Assertions
By now you've caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned.