You just add the following line to your local ~/.gemrc
file (it is in your home folder):
gem: --no-document
or you can add this line to the global gemrc
config file.
Here is how to find it (in Linux):
strace gem source 2>&1 | grep gemrc
The --no-document
option is documented in the RubyGems CLI Reference.
I am using RSpec with a Rails engine without issues.
I created my plugin using the following switches: -T --full --dummy-path=spec/dummy.
-T
excludes test/unit
--full
indicates that the plugin is an engine
--dummy-path
is simply so that we don't get a test directory (the
default is test/dummy).
From there I used the spec_helper from the "start your engines" article:
# Configure Rails Envinronment
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require 'rspec/rails'
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
RSpec.configure do |config|
config.use_transactional_fixtures = true
end
For the generators. I add a config.generators block to my engine.rb file like so:
module MyEngine
class Engine < Rails::Engine
config.generators do |g|
g.test_framework :rspec, :view_specs => false
end
end
end
With that, I'm able to get rspec tests when running a generator like the model generator.
As for the DB, is your database.yml file set up correctly? Did you load the test environment, e.g. rake db:test:clone
or rake db:migrate RAILS_ENV=test
? My guess is that RSpec can't see your tables because there isn't a test database set up.
Best Answer
I've updated this answer to match current best practices:
Bundler supports gem development perfectly. If you are creating a gem, the only thing you need to have in your Gemfile is the following:
This tells Bundler to look inside your gemspec file for the dependencies when you run
bundle install
.Next up, make sure that RSpec is a development dependency of your gem. Edit the gemspec so it reads:
Next, create
spec/spec_helper.rb
and add something like:The first two lines tell Bundler to load only the gems inside your gemspec. When you install your own gem on your own machine, this will force your specs to use your current code, not the version you have installed separately.
Create a spec, for example
spec/foobar_spec.rb
:Optional: add a
.rspec
file for default options and put it in your gem's root path:Finally: run the specs: