2

We create rails 3.2.9 engine with the command below:

rails plugin new my_eng --mountable --dummy-path=spec/dummy

in my_eng.gemspec, rspec was added:

s.add_development_dependency "rspec-rails", ">= 2.0.0"

Run bundle install. Then in engine's root directory:

rails g rspec:install

A spec_helper.rb file is created under spec/.

The problem is that when a model or controller is created,ex, rails g model my_model..., under spec/, there is no models directory and my_model_spec.rb were created. We tried to run rails g rspec:install under spec/dummy/ and the problem remains. What's wrong with our code? Thanks for the help.

user938363
  • 9,990
  • 38
  • 137
  • 303

1 Answers1

3

You gotta insert in config/application.rb something like:

config.generators do |g|
  g.template_engine :erb
  g.test_framework  :rspec, :fixture => true, :views => false
  g.integration_tool :rspec, :fixture => true, :views => true
  g.fixture_replacement :factory_girl, :dir => "spec/support/factories" 
end
Rodrigo Oliveira
  • 913
  • 5
  • 16
  • In engine.rb, we use the exact same code from Brian's: config.generators do |g| g.test_framework :rspec, :view_specs => false end. Among 10 engines created, there is one rspec working. Just tried the following and it worked: config.generators.integration_tool :rspec config.generators.test_framework :rspec. This code is basically doing the same as what it is in RodrigoOliveira or Brian's. But not sure why the code with do loop was not working every time as it should be. – user938363 Nov 24 '12 at 21:25
  • What does the :views => true or false mean? With the code above, is factory girl created along with a rails generator? – user938363 Nov 24 '12 at 21:29
  • It mean that view's specs will not be created. – Rodrigo Oliveira Nov 24 '12 at 21:31
  • Is it erb by default (g.template_engine :erb)? – user938363 Nov 24 '12 at 21:38