RSpecRake makes easier to configure rspec for rake tasks.
gem install rspec_rake
Write configuration for rake tests in your rails_helper.rb
or spec_helper.rb
RSpecRake.configure do |config|
config.require_tasks(File.join('your', 'rake-task', 'dir-path'))
config.auto_reenable = true # Optional
end
Rake::Task
can invoke task only 1 time because it has #already_invoked
flag.
But we often want to invoke more in specs.
So if you want to invoke more than 1 time, use auto_reenable
option.
Be careful your specs doesn't go infinite loop 😈
# in rails_helper
RSpecRake.configure do |config|
config.require_tasks(File.join(Rails.root, 'lib', 'tasks')) # or Rails.application.load_tasks
config.auto_reenable = true # Optional
end
# in specs, Rake::Task can call everywhere
before { Rake::Task['some:task'].invoke }
subject { Rake::Task['some:task'].invoke }
after { Rake::Task['some:task'].invoke }
Bug reports and pull requests are welcome on GitHub at https://github.com/bakunyo/rspec_rake.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
- Fork it ( http://github.com/bakunyo/rspec_rake/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Released under the MIT License. See the LICENSE file for further details.