Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Rails unit tests be run on a different environment than test?

We have a large multi-developer project under Rails in which we are using tests for both models and controllers. Right now the developers have to switch the DB parameters for the 'test' environment to match their local dev environments before running tests. I am wondering if there is a way to run those tests on any environment other than 'test'?

For example we have in database.yml:

test:
  database: ...
  host: ...
  username: ...
  password: ...
...
dev-one:
  ...
dev-two:
  ...

I can't find anything in the docs on this but maybe I am looking in the wrong place. Any ideas?

Thanks!

like image 651
futureal Avatar asked May 18 '10 21:05

futureal


People also ask

Are unit tests run in production?

Yes of course! Unit tests run on all build configurations. Unit tests are always intact but this does not mean that shipped assemblies are dependent on anything relating to the tests. Tests are always written in a parallel assembly (in the same build environment) that then tests the production assembly.

What type of test is not typical in a Rails application?

Integration. Don't try to test all the combinations in integration tests. That's what unit tests are for. Just test happy-paths or most common cases.

How do I run a test in Rails?

2.7 The Rails Test Runner Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.

What is unit test Rails?

They make sure that a section of an application, or a “unit”, is behaving as intended. In a Rails context, unit tests are what you use to test your models. Although it is possible in Rails to run all tests simultaneously, each unit test case should be tested independently to isolate issues that may arise.


1 Answers

As of right now this still does not work. I've submitted an issue: https://github.com/rails/rails/issues/21478.

I'll edit this answer with updates

like image 114
frankpinto Avatar answered Sep 18 '22 06:09

frankpinto