Skip to content

Instantly share code, notes, and snippets.

@vovimayhem
Last active December 10, 2015 20:58
Show Gist options
  • Save vovimayhem/4491427 to your computer and use it in GitHub Desktop.
Save vovimayhem/4491427 to your computer and use it in GitHub Desktop.
Crear app/engine de Rails usando MySQL y RSpec.

New Rails App

At Terminal/Command:

  • The -T option tells rails not to include Test::Unit
  • The --database=mysql tells rails to include Mysql gem and configs
  • The --skip-bundle is self explanatory... rails new myapp -T --skip-bundle --database=mysql

in Gemfile:

gem 'rspec-rails'

in config/initializers/generator.rb

Rails.application.config.generators do |g|
    g.test_framework = :rspec
end

At Terminal / Command:

bundle install
rails g rspec:install

New Rails Engine:

At Terminal / Command Line:

rails plugin new myengine --mountable --dummy-path=spec/dummy -T --skip-bundle

At Gemfile:

gem 'rspec-rails'

At Terminal / Command Line:

bundle install
bundle exec rails g rspec:install

Modify spec_helper to know about the dummy app

The default generated spec_helper will try to load your Rails environment from the wrong place. So, change: require File.expand_path("../../config/environment", FILE) to: require File.expand_path("../../spec/dummy/config/environment", FILE)

Use RSpec Generators

Add the following to your “lib/myengine/engine.rb” file, inside the Engine class:

config.generators do |g|                                                               
  g.test_framework :rspec
  g.integration_tool :rspec
end

Sources:

http://stackoverflow.com/questions/6728618/how-can-i-tell-rails-to-use-rspec-instead-of-test-unit-when-creating-a-new-rails http://whilefalse.net/2012/01/25/testing-rails-engines-rspec/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment