How to run Rails console in the test environment and load test_helper.rb?
For Rails < 3.0
Run script/console --help
. You'll notice that the syntax is script/console [environment]
, which in your case is script/console test
.
I'm not sure if you have to require the test helper or if the test environment does that for you, but with that command you should at least be able to boot successfully into the test env.
As a sidenote: It is indeed kind of odd that the various binaries in script/ has different ways of setting the rails environment.
For Rails 3 and 4
Run rails c test
. Prepend bundle exec
if you need this for the current app environment.
For Rails 5 and 6
Run rails console -e test
.
how do I set up factory_girl in my test_helper.rb file to use with shoulda?
You have a typo. You should use
Factory.find_definitions
not
FactoryGirl.find_definitions
As you do in your OutboundMailerTest class.
require: No such file to load -- test_helper (LoadError) happens only in production not in development
This is a stab in the dark, but are you requiring your test_helper somewhere else in your application? From reading the backtrace it looks like you're requiring it in app/app/helpers/sessions_helper_test.rb
.
Also, the app/app/
looks fishy. Do you have an app folder inside of your app folder? That could be a problem too.
Rails tests can't find test_helper
ruby 1.9.2 removed ".", the current directory, from the load path. I have to do this to get it to work:
require 'test_helper'
and call it like:
ruby -I. unit/person_test.rb
How do I write a helper for an integration test in Rails?
Pick one:
module IntegrationHelperTest
# ...
end
require 'test_helper'
require 'integration/integration_helper_test'
class PostIntegrationTest < ActionDispatch::IntegrationTest
include IntegrationHelperTest
# ...
end
or
class IntegrationHelperTest < ActionDispatch::IntegrationTest
# ...
end
require 'test_helper'
require 'integration/integration_helper_test'
class PostIntegrationTest < IntegrationHelperTest
# ..
end
Related Topics
Given the Session Key and Secret, How to Decrypt Rails Cookies
Tell the End of a .Each Loop in Ruby
Create Array of N Items Based on Integer Value
Ruby - Replace the First Occurrence of a Substring with Another String
Rails 6.1, Ruby 3.0.0: Tests Error as They Cannot Load Rexml
How to Get a Stack Trace Object in Ruby
Test Whether a Variable Equals Either One of Two Values
Execute a Rake Task from Within Migration
Case-Insensitive Array#Include
Which Algorithm Does Ruby's Sort Method Use
What's the Best Way to Search for a String in a File
Ruby: Sum Corresponding Members of Two or More Arrays
Ruby on Rails Error "Cannot Load Such File -- Less"
How to Execute Ruby Template Files (Erb) Without a Web Server from Command Line