Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing Rake tasks with RSpec examples from the talk I gave at Test Ruby PDX in March 2016. See more here: http://bit.ly/testing-rake-tasks
class Greeter
def greet
puts 'Hello!'
end
end
require 'rake'
load 'Rakefile'
describe 'Rake tasks' do
describe 'hello' do
before { Rake::Task['hello'].reenable }
describe 'features' do
it 'outputs Hello! to stdout' do
expect do
Rake::Task['hello'].invoke
end.to output("Hello!\n").to_stdout
end
end
describe 'units' do
it 'uses a Greeter to greet' do
expect(Greeter).to receive_message_chain(
:new,
:greet
)
Rake::Task['hello'].invoke
end
end
end
end
require_relative 'greeter'
desc 'Outputs a greeting to stdout'
task :hello do
Greeter.new.greet
end
require 'rake'
load 'Rakefile'
Rake::Task['hello'].invoke
Rake::Task['hello'].reenable
Rake::Task['hello'].invoke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment