Skip to content

Instantly share code, notes, and snippets.

@georg
Created August 26, 2009 03:44
Show Gist options
  • Select an option

  • Save georg/175282 to your computer and use it in GitHub Desktop.

Select an option

Save georg/175282 to your computer and use it in GitHub Desktop.

Revisions

  1. georg created this gist Aug 26, 2009.
    33 changes: 33 additions & 0 deletions mailtrap.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # 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