cat3045
cat3045

Reputation: 295

How can I regenerate the test directory in a rails project?

I've changed my models significantly and my unit tests and fixtures no longer make sense. Is there a quick rails generate command I can use to "regenerate" the test directory?

Upvotes: 1

Views: 806

Answers (2)

cat3045
cat3045

Reputation: 295

There's good news to regenerating files! If one deletes the files one wants to re-generate and then run

rails generate scaffold Model [attributes] --skip

for each model affected, only the deleted files will be regenerated. Hopefully this helps everyone else who has slacked off on updating the basic unit tests throughout many model changes and will like to quickly generate them to match their current model.

 rails generate scaffold User name email password_digest is_admin:boolean --skip
  invoke  active_record
    skip    db/migrate/20140219190354_create_users.rb
    skip    app/models/user.rb
  invoke    test_unit
  create      test/models/user_test.rb
  create      test/fixtures/users.yml
  invoke  resource_route
   route    resources :users
  invoke  scaffold_controller
    skip    app/controllers/users_controller.rb
  invoke    erb
   exist      app/views/users
    skip      app/views/users/index.html.erb
identical      app/views/users/edit.html.erb
    skip      app/views/users/show.html.erb
    skip      app/views/users/new.html.erb
    skip      app/views/users/_form.html.erb
  invoke    test_unit
  create      test/controllers/users_controller_test.rb
  invoke    helper
identical      app/helpers/users_helper.rb
  invoke      test_unit
  create        test/helpers/users_helper_test.rb
  invoke    jbuilder
    skip      app/views/users/index.json.jbuilder
    skip      app/views/users/show.json.jbuilder
  invoke  assets
  invoke    coffee
identical      app/assets/javascripts/users.js.coffee
  invoke    scss
identical      app/assets/stylesheets/users.css.scss
  invoke  scss
identical    app/assets/stylesheets/scaffolds.css.scss

Now onto writing real tests =)

Upvotes: 4

Donald
Donald

Reputation: 176

I think you're SOL, but if you've been using rails generate throughout your process hopefully your directory won't be too far off.

Upvotes: 0

Related Questions