How to Run Rails Console in the Test Environment and Load Test_Helper.Rb

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



Leave a reply



Submit