Skip to content

Instantly share code, notes, and snippets.

@brettchalupa
Created March 14, 2016 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brettchalupa/49fd4c097c54f3ca0ec8 to your computer and use it in GitHub Desktop.
Save brettchalupa/49fd4c097c54f3ca0ec8 to your computer and use it in GitHub Desktop.
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