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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Greeter | |
def greet | |
puts 'Hello!' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'greeter' | |
desc 'Outputs a greeting to stdout' | |
task :hello do | |
Greeter.new.greet | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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