Skip to content

Instantly share code, notes, and snippets.

@georg
Created August 26, 2009 03:44
Show Gist options
  • Save georg/175282 to your computer and use it in GitHub Desktop.
Save georg/175282 to your computer and use it in GitHub Desktop.
# Put this in features/env/mailtrap.rb to automatically run mailtrap for your Cucumber tests.
class Mailtrap
def self.start
@mailtrap_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'mailtrap.log'))
clear_mailtrap_file
@mailtrap = IO.popen("mailtrap run --file=#{@mailtrap_file}")
end
def self.clear_mailtrap_file
FileUtils.rm_f @mailtrap_file
end
def self.stop
Process.kill('HUP', @mailtrap.pid)
end
def self.content
File.read(@mailtrap_file)
end
end
Mailtrap.start
at_exit do
Mailtrap.stop
end
After do |scenario|
unless scenario.failed?
Mailtrap.clear_mailtrap_file
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment