Sha256: 9a70cec8d232d4b2e8d38d319d6f7a51f592976aa5ecc8fb951767a67a63ceff

Contents?: true

Size: 1.32 KB

Versions: 41

Compression:

Stored size: 1.32 KB

Contents

# For testing rake tasks
# From: https://github.com/eliotsykes/rails-testing-toolbox/blob/master/tasks.rb
# Checkout: https://www.eliotsykes.com/test-rails-rake-tasks-with-rspec

require 'rake'

# Task names should be used in the top-level describe, with an optional
# "rake "-prefix for better documentation. Both of these will work:
#
# 1) describe 'foo:bar' do ... end
#
# 2) describe 'rake foo:bar' do ... end
#
# Favor including 'rake '-prefix as in the 2nd example above as it produces
# doc output that makes it clear a rake task is under test and how it is
# invoked.
module TaskExampleGroup
  extend ActiveSupport::Concern

  included do
    let(:task_name) { self.class.top_level_description.sub(/\Arake /, '') }
    let(:tasks) { Rake::Task }
    subject(:task) { tasks[task_name] }

    after(:each) do
      task.all_prerequisite_tasks.each { |prerequisite| tasks[prerequisite].reenable }
      task.reenable

      # clean up generated dir
      rbi_dir = Rails.root.join("sorbet", "rails-rbi")
      FileUtils.remove_dir(rbi_dir) if Dir.exists?(rbi_dir)
    end
  end
end


RSpec.configure do |config|
  config.define_derived_metadata(:file_path => %r{/spec/tasks/}) do |metadata|
    metadata[:type] = :task
  end

  config.include TaskExampleGroup, type: :task

  config.before(:suite) do
    Rails.application.load_tasks
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
sorbet-rails-0.7.34 spec/rake_helper.rb
sorbet-rails-0.7.33 spec/rake_helper.rb
sorbet-rails-0.7.32 spec/rake_helper.rb
sorbet-rails-0.7.31 spec/rake_helper.rb
sorbet-rails-0.7.27 spec/rake_helper.rb
sorbet-rails-0.7.26 spec/rake_helper.rb
sorbet-rails-0.7.25 spec/rake_helper.rb
sorbet-rails-0.7.24 spec/rake_helper.rb
sorbet-rails-0.7.23 spec/rake_helper.rb
sorbet-rails-0.7.22 spec/rake_helper.rb
sorbet-rails-0.7.20 spec/rake_helper.rb
sorbet-rails-0.7.19 spec/rake_helper.rb
sorbet-rails-0.7.18 spec/rake_helper.rb
sorbet-rails-0.7.5 spec/rake_helper.rb
sorbet-rails-0.7.4 spec/rake_helper.rb
sorbet-rails-0.7.3 spec/rake_helper.rb
sorbet-rails-0.7.2 spec/rake_helper.rb
sorbet-rails-0.7.1 spec/rake_helper.rb
sorbet-rails-0.7.0 spec/rake_helper.rb
sorbet-rails-0.6.5.1 spec/rake_helper.rb