I'm an experienced programmer, but brand new to Ruby and Rails. I want to try building new tests for an existing project, so I thought a good way to start would be to reproduce existing tests line by line in the Rails console. However, I haven't been able to make it work.
As this question suggests, I went to the main directory of the project and did this:
$ rails console -e test
Loading test environment (Rails 5.2.0)
irb(main):001:0> require './test/test_helper'
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's 'rails' settings.
(1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
=> true
So far so good. But I still couldn't load the actual test modules:
irb(main):002:0> require './test/controllers/users_controller_test'
Traceback (most recent call last):
2: from (irb):2
1: from test/controllers/users_controller_test.rb:1:in `<top (required)>'
LoadError (cannot load such file -- test_helper)
So then I tried adjusting the $LOAD_PATH as follows, which seems to work:
irb(main):003:0> $LOAD_PATH.unshift '/{{absolute path to project}}/test'
{{irb now prints the new $LOAD_PATH which is really long}}
irb(main):004:0> require './test/controllers/users_controller_test'
=> true
But when I try to run the actual tests, it's still not working. It looks like some kind of unloaded "routes":
irb(main):008:0> my_test = UsersControllerTest.new("My Test")
=> #<UsersControllerTest:0x000055c90aadd148 @NAME="My Test", @failures=[], @assertions=0>
irb(main):009:0> my_test.test_routes
Traceback (most recent call last):
2: from (irb):9
1: from test/controllers/users_controller_test.rb:11:in `test_routes'
NoMethodError (undefined method `recognize_path' for nil:NilClass)
irb(main):010:0> my_test.test_new_view
Traceback (most recent call last):
2: from (irb):10
1: from test/controllers/users_controller_test.rb:191:in `test_new_view'
RuntimeError (@routes is nil: make sure you set it in your test's setup method.)
Is there an easier way to run tests from the console? How can I resolve the missing "routes" so I can run the tests from the rails console? Or is my goal inadvisable to begin with?