Running with Ruby

Tag: Ruby 2.0 (page 2 of 3)

Ruby 2.1.0-p0 and 2.0.0-p247 – Could not find minitest-4.7.5 in any of the sources

So if you get this message, while doing bundle install:

/ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/spec_set.rb:92:in `block in materialize':
Could not find minitest-4.7.5 in any of the sources (Bundler::GemNotFound)
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/spec_set.rb:85:in `map!'
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/spec_set.rb:85:in `materialize'
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/definition.rb:114:in `specs'
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/definition.rb:159:in `specs_for'
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/definition.rb:148:in `requested_specs'
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/environment.rb:18:in `requested_specs'
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler/runtime.rb:13:in `setup'
from /ruby/gems/2.1.0-p0/gems/bundler-1.5.0/lib/bundler.rb:120:in `setup'
from /ruby/gems/2.1.0-p0/gems/rubygems-bundler-1.5.0/lib/rubygems-bundler/noexec.rb:74:in `setup'
from /ruby/gems/2.1.0-p0/gems/rubygems-bundler-1.5.0/lib/rubygems-bundler/noexec.rb:103:in `check'
from /ruby/gems/2.1.0-p0/gems/rubygems-bundler-1.5.0/lib/rubygems-bundler/noexec.rb:109:in `<top (required)>'
from /ruby/2.1.0-p0/rubygems/core_ext/kernel_require.rb:110:in `require'
from /ruby/2.1.0-p0/rubygems/core_ext/kernel_require.rb:110:in `rescue in require'
from /ruby/2.1.0-p0/rubygems/core_ext/kernel_require.rb:35:in `require'
from /ruby/gems/2.1.0-p0/gems/rubygems-bundler-1.5.0/lib/rubygems_executable_plugin.rb:4:in `block in <top (required)>'
from /ruby/gems/2.1.0-p0/gems/executable-hooks-1.2.4/lib/executable-hooks/hooks.rb:50:in `call'
from /ruby/gems/2.1.0-p0/gems/executable-hooks-1.2.4/lib/executable-hooks/hooks.rb:50:in `block in run'
from /ruby/gems/2.1.0-p0/gems/executable-hooks-1.2.4/lib/executable-hooks/hooks.rb:49:in `each'
from /ruby/gems/2.1.0-p0/gems/executable-hooks-1.2.4/lib/executable-hooks/hooks.rb:49:in `run'
from /Users/smithy/.rbenv/versions/2.1.0-p0-p247/bin/ruby_executable_hooks:10:in `<main>'

You need to update your bundler:

gem update bundler
Updating installed gems
Updating bundler
Fetching: bundler-1.5.2.gem (100%)
Successfully installed bundler-1.5.2
Parsing documentation for bundler-1.5.2
Installing ri documentation for bundler-1.5.2
Installing darkfish documentation for bundler-1.5.2
Gems updated: bundler

Paperclip and Rspec: Stubbing Paperclip/ImageMagick to make specs run faster, but with image resolution validation

I always test my Paperclip stuff. Mostly because quite often, I need to ensure proper images resolution or other image-based conditions. Unfortunately, it takes some time, mostly because ImageMagick is performing resource consuming operations. Each resolution test needs to get valid image to determine width and height. After that, Paperclip will try to create all the thumbs and save them. This takes a lot of time! Luckily there’s a Quickerclip that stubs Paperclip methods, allowing it to run faster. There’s one small issue with this code: it stubs the image, so there’s no way to test resolution validations. In order to make it work, but without any additional callbacks and without images converting, we need to stub two things:

First the method:

# We stub some Paperclip methods - so it won't call shell slow commands
# This allows us to speedup paperclip tests 3-5x times.
module Paperclip
  def cmd, params = "", expected_outcodes = 0
    cmd == 'convert' ? nil : super

This will ignore convert command, so thumbnails won’t be created on save.

Also we need to stub the Paperclip::Attachment.post_process:

class Paperclip::Attachment
  def post_process

Don’t forget to add this to your spec_helper or test_helper file!

After that, your tests/specs should run 3-5x times faster (it depends on how heavily you app is Paperclip based.

For Paperclip newer than 3.5.2 please use code presented below:

module Paperclip
  def cmd, arguments = "", interpolation_values = {}, local_options = {}
    cmd == 'convert' ? nil : super

class Paperclip::Attachment
  def post_process
Olderposts Newerposts

Copyright © 2021 Running with Ruby

Theme by Anders NorenUp ↑