Quick writedown on how to run Rake tasks in Cucumber or Rspec. There are a few answers out on Stackoverflow but those didn’t exactly fit my needs. Using the setup they provided worked well on running individual scenarios, but failed when you ran 2 scenarios at the same time, and each did invoke 1 or 2 rake tasks.

My final working solution looks like this

And /^the rake task to remind of expiring subscriptions ran$/ do
  execute_rake('billing.rake', 'billing:remind_user_of_expiring_subscription')

def execute_rake(file, task)
  require 'rake'
  rake = Rake::Application.new
  Rake.application = rake
  load "#{Rails.root}/lib/tasks/#{file}"

Kudos goes to this answer on Stackoverflow: Answer