pat / combustion

Simple, elegant testing for Rails Engines
MIT License
707 stars 51 forks source link

Error Sprockets::Railtie::ManifestNeededError #102

Closed shir closed 4 years ago

shir commented 4 years ago

When I run specs with combustion configured I have next error:

$ rspec spec/features/scans/index_spec.rb 
Failure/Error: Combustion.initialize! :all

Sprockets::Railtie::ManifestNeededError:
  Expected to find a manifest file in `app/assets/config/manifest.js`
  But did not, please create this file and use it to link any assets that need
  to be rendered by your app:

  Example:
    //= link_tree ../images
    //= link_directory ../javascripts .js
    //= link_directory ../stylesheets .css
  and restart your server
# ./spec/rails_helper.rb:6:in `<top (required)>'
# ./spec/features/scans/index_spec.rb:3:in `require'
# ./spec/features/scans/index_spec.rb:3:in `<top (required)>'

This error is for any spec. Everything works when I use rails generated dummy application.

My environment:

Dependencies:

  s.add_dependency 'kaminari'
  s.add_dependency 'pg'
  s.add_dependency 'rails', '>= 5.0'
  s.add_dependency 'slim-rails'

  s.add_development_dependency 'appraisal'
  s.add_development_dependency 'capybara'
  s.add_development_dependency 'combustion', '~> 1.1'
  s.add_development_dependency 'database_cleaner'
  s.add_development_dependency 'factory_bot_rails'
  s.add_development_dependency 'rspec-rails'
  s.add_development_dependency 'rubocop', '~> 0.75.0'
  s.add_development_dependency 'rubocop-performance'
  s.add_development_dependency 'rubocop-rails'
  s.add_development_dependency 'shoulda-matchers'

I've tried to run both with appraisal and without with same result

Rails version actually installed 5.2.3

My spec/rails_helper.rb

require 'spec_helper'
require 'combustion'
ENV['RAILS_ENV'] ||= 'test'

Combustion.initialize! :all

abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'

Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }

begin
  ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
  puts e.to_s.strip
  exit 1
end
RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!
  config.filter_rails_from_backtrace!
end

spec/internal/routes.rb:

Rails.application.routes.draw do
  mount App::Engine, at: '/'
end

(real engine name instead App). Without mounting engine or mounting it on another endpoint I have the same error.

wintersolutions commented 4 years ago

@shir This is new sprockets behavior (see https://github.com/rails/sprockets/blob/master/UPGRADING.md). I agree this should be handled in combustion somehow. Here is a workaround for the meantime:

Its working in a newly created rails dummy app because it'll contain a manifest.js which is required by sprockets v4. Here is a example:

/my_engine_with_rails_dummy/app/assets/config/my_engine_with_rails_dummy_manifest.js:

//= link_directory ../javascripts/my_engine_with_rails_dummy .js
//= link_directory ../stylesheets/my_engine_with_rails_dummy .css

/my_engine_with_rails_dummy/test/dummy/app/assets/config/manifest.js:

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link my_engine_with_rails_dummy_manifest.js

You can basically copy this second file into your combustion test skeleton folder (mine is spec/internal/app/assets/config), you need to adjust the engine names/paths and it should work.

pat commented 4 years ago

Thanks @wintersolutions, your suggestion sounds correct to me. @shir: I would certainly appreciate the confirmation that this has worked for you before I add it to the generator in Combustion :)

jrochkind commented 4 years ago

This is all very confusing, the research I did on it can be found at https://bibwild.wordpress.com/2019/10/15/sprockets-4-and-your-rails-app/

I think that the manifest.js to the generator is probably the right solution. The Rails-generated content of the manifest_js is technically different for Rails 5.x apps and Rails 6.0 apps though -- the Rails 6.0-generated apps don't have //= link_directory ../javascripts .js in them, since in Rails 6 sprockets is not expected to be used with JS.

I'm not sure what that means for what combustion should generate, or if it will cause a problem to do the Rails 5.2 one.

I also don't really like what Rails is generating at all, I think it should have been what Sprockets-maintainer schneems suggested to Rails, but Rails maintainers denied. :( https://github.com/rails/rails/pull/28430

It's all pretty messy.

jrochkind commented 4 years ago

Hmm, the combustion-generated skeleton doesn't have an app/assets/images, so putting link_tree ../images in the manifest actually generates an error.

The combustion-generated skeleton also doesn't seem to have an app/asset/stylesheets or an application.css... in my app, I think I might try a manifest.js that is only //= link application.js, for the application.js the combustion-generated skeleton DOES have.

pat commented 4 years ago

@jrochkind Can the manifest file be empty? I guess that's what I'd probably default to (but if I'm generating a JS file, then I guess it makes sense to reference that).

shir commented 4 years ago

Thanks to all. Just adding an empty file spec/internal/app/assets/config/manifest.js helped. But I think it should be fixed within cumbustion.

pat commented 4 years ago

Just pushed the v1.1.2 release that generates an empty manifest file as part of the combust call. Thanks all for the input here :)