Updated

spec/support / rake_task_example_group.rb

A
44 lines of codes
2 methods
13.5 complexity/method
1 churn
26.98 complexity
0 duplications
require 'rake' module RakeTaskExampleGroup
  1. RakeTaskExampleGroup has no descriptive comment
extend ActiveSupport::Concern included do let(:rake) { Rake.application } let(:task) { self.class.top_level_description } let(:prerequisites) { subject.prerequisites } subject { rake[task] } around do |example| with_rake_env { example.run } end end private def application_tasks
  1. RakeTaskExampleGroup#application_tasks doesn't depend on instance state (maybe move it to another class?)
Rails.application.paths['lib/tasks'].to_a end def with_rake_env
  1. RakeTaskExampleGroup#with_rake_env has approx 6 statements
new_rake = Rake::Application.new old_rake, Rake.application = Rake.application, new_rake # The Rails enviroment is already loaded so we define an # empty environment task to fufill the prerequisites. Rake::Task.define_task(:environment) # Load just the application tasks defined in `lib/tasks` application_tasks.each { |task| load(task) } yield ensure Rake.application = old_rake end end RSpec.configure do |config| config.include RakeTaskExampleGroup, type: :rake, file_path: %r[spec/tasks] end