I'm using rspec with Rails 4 and when creating controllers, for example, I always have to pass the "--no-test-framework" parameter. Is there a way to not generate these tests by default without needing to explicitly specify it (I often forget and then need to manually delete the generated tests).
Thank you!
Once the skeleton of the new Rails application has been built, you will see a folder called test in the root of the new application, and many subfolders and files within the test directory. For the purposes of this post, I will be focusing on adding tests to the models directory, since unit testing in Rails primarily involves testing models.
The easiest way to see functional tests in action is to generate a controller using the scaffold generator: $ bin/rails generate scaffold_controller article title:string body:text ... create app/controllers/articles_controller.rb ... invoke test_unit create test/controllers/articles_controller_test.rb ...
Model tests are used to test the various models of your application. Rails model tests are stored under the test/models directory. Rails provides a generator to create a model test skeleton for you. Model tests don't have their own superclass like ActionMailer::TestCase. Instead, they inherit from ActiveSupport::TestCase.
Rails creates a test directory for you as soon as you create a Rails project using rails new application_name. If you list the contents of this directory then you shall see: The helpers, mailers, and models directories are meant to hold tests for view helpers, mailers, and models, respectively.
Just add the following to config/application.rb
(within the Application class):
config.generators.test_framework false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With