title: How to invoke RSpec inside a rake task?
body: <p>We wrote some tests that are necessary, but very slow. So we configured RSpec to exclude them except on Solano, where we set up an ENV variable.</p>
  
  <pre><code># spec_helper
  unless ENV['RUN_ALL_TESTS'] == 'true'
    config.filter_run_excluding :slow
  end
  </code></pre>
  
  <p>That works, but I'm trying to write a rake task we can call to run every test locally by setting that same ENV variable and then running the suite. I'm having trouble figuring out how to trigger RSpec. This is what I've got now:</p>
  
  <pre><code># all_tests.rake
  require 'rspec/core/rake_task'
  
  desc 'Run all tests, even those usually excluded.'
  task all_tests: :environment do
    ENV['RUN_ALL_TESTS'] = 'true'
    RSpec::Core::RakeTask.new(:spec)
  end
  </code></pre>
  
  <p>When I run it, it doesn't run any tests.</p>
  
  <p>Most of the stuff I found is for triggering a rake task inside of a test, testing a rake task, or setting up a Rakefile. We're using <code>rspec-rails</code>, our default rake task is already set up.</p>