Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gem with multiple requires in gemfile

So I have this gem and it depends on lots of other gems. While in the gemspec it says

s.add_dependency "haml" ...

bundler does not seem to care, so I have to repeat these dependency in the Gemfile. Is there a syntax to require multiple gems? Something like that (does not work):

gem "so-and-so",
   :git => "some-repo",
   :require => ["this-gem", "that-gem", "and-what-not"]

require seems to only allow a single object

like image 923
Jan Avatar asked Feb 02 '12 13:02

Jan


1 Answers

According to the Gemfile documentation you can simply pass an array of requires. I hit this question while researching RSpec like syntactical sugar for Minitest and noting that I'd need to:

require 'minitest/spec'
require 'minitest/autorun'

To get this to work. I'd never tried multiple requires in a Gemfile before, and googling led me here to this question, and more Googling led me to the Gemfile docs which state:

REQUIRE AS (:require)
Each gem MAY specify files that should be used when autorequiring via
Bundler.require. You may pass an array with multiple files, or false
to prevent any file from being autorequired.

gem "sqlite3-ruby", :require => "sqlite3"
gem "redis", :require => ["redis/connection/hiredis", "redis"]
gem "webmock", :require => false

So in my own Gemfile I have included

group :test do
  gem 'minitest', require: ['minitest/autorun', 'minitest/spec']
  gem 'rack-test', require: 'rack/test'
  gem 'simplecov', require: false
end

Which works perfectly and allows me to write a test like

describe 'basic crud' do
  it 'must create a user with valid details' do
    User.transaction do
      user = User.create!(username: 'test', password: 'pass')
      user.username.must_equal 'test'
      user.destroy
    end
  end
end

Which I find reads nicer than assert_equals user.username, 'test' and gives me access to my familiar before :each do… and after :all do… prep and cleanup methods.

like image 199
Dave Sag Avatar answered Oct 02 '22 08:10

Dave Sag