Find Where a Rake Task is Defined

In any Rails application you can see which rake tasks are available - either by running rake -AT (or rake --all --tasks) to see all tasks, or rake -T (or rake --tasks) to see all tasks with descriptions.

However, today I learnt you can also see where a rake task is defined by running rake -W (or rake --where). This is useful if a gem is adding a rake task and you want to look at the source.

All of these commands also take an optional pattern to filter the results.

rake -W db:schema:load

rake db:schema:load                 /Users/jacopretorius/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.6/lib/active_record/railties/databases.rake:247
rake db:schema:load_if_ruby         /Users/jacopretorius/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.6/lib/active_record/railties/databases.rake:251