Module: RspecExtensions::InvokeTask

Defined in:
lib/rspec_tapas/invoke_task.rb

Instance Method Summary collapse

Instance Method Details

#invoke_task(name, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rspec_tapas/invoke_task.rb', line 4

def invoke_task(name, options = {})
  task_path =
    RSpec.current_example.[:file_path].match(%r{spec/(?<file_path>.*)_spec\.rb})[:file_path]
  loaded_files_excluding_current_rake_file =
    $".reject { |file| file == Rails.root.join("#{task_path}.rake").to_s }
  Rake.application = Rake::Application.new
  Rake.application.rake_require(
    task_path,
    [Rails.root.to_s],
    loaded_files_excluding_current_rake_file
  )
  Rake::Task.define_task(:environment)
  task = Rake.application[name]
  task.execute(options)
end