Rake before task hook
You can use the dependency of Rake task to do that, and the fact that Rake allows you to redefine existing task.
Rakefile
task :your_task do
puts 'your_task'
end
task :before do
puts "before"
end
task :your_task => :before
As result
$ rake your_task
before
your_task
A General Method to be invoked before every rake execution
This seems to be a bit awkward, But it may help others.
Rake.application.top_level_tasks
will return an array of information including Rake name and its arguments.
Reference attached below.
pry(main)> a = Rake.application.top_level_tasks
=> ["import_data[client1,", "data.txt]"]
Is there a way to hook a before and after suite, in a Rakefile?
If your specs failed, maybe that's why nothing after Rake::Task["spec"].execute
gets executed. Instead of using the Rakefile, why not use Rspec's before(:suite)
and after(:suite)
hooks? You can put that code in your spec_helper.rb
if you have one.
https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/hooks/before-and-after-hooks#before/after-blocks-defined-in-config-are-run-in-order
Related Topics
How to Mark a Cucumber Scenario as Pending
Mailchimp API Not Replacing Mc:Edit Content Sections (Using Ruby Library)
Select Checkbox Pass Array in Ruby on Rails
Why Aren't Global (Dollar-Sign $) Variables Used
How to Create Dynamic CSS in Rails
Working with Decimals in Ruby on Rails 3
Erroneous "Insecure World Writable Dir Foo in Path" When Running Ruby Script
Ruby on Rails: How to Add a CSS File with Rails Project
Getting Headers from a Ruby Net::Http Request Before Making the Request
How to Strip Leading and Trailing Quote from String, in Ruby
In Ruby How to Use Class Level Local Variable? (A Ruby Newbie's Question)
How to Write to File When Using Marshal::Dump in Ruby for Object Serialization