Yak Shaving, Troubleshooting with Mailcatcher

For an unknown reason, I had trouble with MailCatcher after I updated to Ruby 2.1.3.

I would only get a 10% of the mail messages in the mailcatcher window. This was absolutely maddening.

At the time of this article, Mailcatcher, v0.5.12, had not been updated since May 29, 2013. So I did the following to get the pre-release version of MailCatcher:

  1. Get the source code
git clone git@github.com:sj26/mailcatcher.git
  1. Cd to the mailcatcher directory
cd mailcatcher
  1. Run bundle
bundle install
  1. Build the gem:
rake package    
  1. Uninstall the gem wherever it’s already installed. This is really important as your gemset versions of MailCatcher will override a system version, which we’ll install in a few steps.
gem uninstall mailcatcher
gem uninstall -i /Users/$USER/.rvm/gems/ruby-2.1.3@global mailcatcher
  1. Install the gem you built
gem install mailcatcher-0.6.0.gem
  1. Put a rvm wrapper on it (change ruby version if you need to):
rvm wrapper ruby-2.1.3@mailcatcher --no-prefix mailcatcher catchmail
  1. Verify that you’re getting this version:
type mailcatcher
  1. Run mailcatcher like this to clearly see that it’s working. -v => verbose, -f => foreground, -b => open browser
mailcatcher -v -f -b

Prosper!

Note: My issue with inconsistent email might have been that my Mac needed restarting. Argh…

thanks for the effort, however it doesnt work for me.
you are missing step 1.5:

cd mailcatcher

after trying:

rake package --trace

im getting this:

rake aborted!
cannot load such file – mail_catcher/version
/usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' /usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require’
/private/tmp/mailcatcher/mailcatcher/Rakefile:4:in <top (required)>' /usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/rake_module.rb:25:in load’
/usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/rake_module.rb:25:in load_rakefile' /usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/application.rb:637:in raw_load_rakefile’
/usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/application.rb:94:in block in load_rakefile' /usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/application.rb:165:in standard_exception_handling’
/usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/application.rb:93:in load_rakefile' /usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/application.rb:77:in block in run’
/usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/application.rb:165:in standard_exception_handling' /usr/local/Cellar/ruby/2.1.2/lib/ruby/2.1.0/rake/application.rb:75:in run’
/usr/local/opt/ruby/bin/rake:33:in `’

any idea how to fix this?
thanks

I was missing

bundle install

after the missing cd

Fixed above.

Thanks!

rake package

was not working for me. I was also getting

cannot load such file -- mail_catcher/version

with the exact same trace. I finally got it working by using

gem build mailcatcher.gemspec instead of rake package .

then everything else was ok. Thanks for helping.

Thanks for letting us know in case somebody else runs into that issue. I wonder why you’d have to do a specific gem build. I’ve never done that.

It seems that it’s pretty similar since the build method from Gem::Package is called inside the rake task (see below). However the rake task uses an asset task as argument which may cause an issue when compiling the assets. It’s actually what was causing the issue on my computer.

source code from here

desc "Package as Gem"
task "package" => ["assets"] do
  require "rubygems/package"
  require "rubygems/specification"

  spec_file = File.expand_path("../mailcatcher.gemspec", __FILE__)
  spec = Gem::Specification.load(spec_file)

  Gem::Package.build spec
end

desc "Compile assets"
task "assets" do
  compiled_path = File.expand_path("../public/assets", __FILE__)
  FileUtils.mkdir_p(compiled_path)

  require "mail_catcher/web/assets"
  sprockets = MailCatcher::Web::Assets
  sprockets.css_compressor = :sass
  sprockets.js_compressor = :uglifier
  sprockets.each_logical_path(/(\Amailcatcher\.(js|css)|\.(xsl|png)\Z)/) do |logical_path|
    if asset = sprockets.find_asset(logical_path)
      target = File.join(compiled_path, logical_path)
      asset.write_to target
    end
  end
end