Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active February 9, 2021 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-yuri/bcd300a7a3e614a0d25d674487b370fb to your computer and use it in GitHub Desktop.
Save x-yuri/bcd300a7a3e614a0d25d674487b370fb to your computer and use it in GitHub Desktop.
#rails #ruby #minitest #rake #pry #pry-byebug

rails: minitest, rake, pry-byebug

  • for rake rails application is required from Rakefile
  • for rake before requiring gems rails sets RAILS_ENV (if not set yet)
  • the default rake task is test
  • TESTOPTS can be used to pass parameters to minitest
  • rails' test task inherits from Rake::TestTask
  • before running tests rails runs db:test:prepare -> db:test:load -> db:test:purge (drop + create) -> db:test:load_schema
    • the last one loads db/schema.rb which brings the db to the appropriate state
    • if after that there are still unapplied migrations, it instructs to apply them
    • alternatively you can run bin/rake db:migrate which will apply the migrations to the development db, and as such update db/schema.rb
    • but if all test migrations get unapplied, and db/schema.rb contains version: 0, db:test:load_schema puts 0 into the schema_migrations table, and fails (since the upcoming migrations are unapplied), this can be resolved by removing the test database, and running db:migrate
  • rails s (or rather webrick) starts a thread for each request, as such pry's !!! doesn't have the effect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment