简体   繁体   中英

Trouble getting dummy app in a Rails engine to load assets from other gems

I have a rails engine that's been working great for the past year. I decided it was time to add some automated testing to the application and I'm running into a problem getting the dummy app to run.

I'm using rspec in my engine and I have the dummy app at spec/dummy . My original engine was NOT generated using the rails plugin new command. I created it using bundle gem and built it up over time by adding the required files. To get the automated testing working, I created a new engine using rails plugin new so I could see how the dummy rails app is created. I copied all the relevant files into my new engine and almost everything works great. I'm able to execute some simple rspec examples against the dummy app, however, these are very basic examples which boot the dummy app, but don't actually hit any controller actions.

I wanted to see if I could run the dummy application so I could start adding more interesting rspec tests using capybara. My engine adds some controllers and views to its host rails app, so I should be able to go to the relevant paths in the browser and have the views load. When I change to the spec/dummy folder and start the rails server, the app boots fine. However, as soon as I try and bring up a page, I get the following error:

File to import not found or unreadable: font-awesome

Again, the engine has no problem running in a regular Rails application. It's something about this dummy app that isn't right. The spec/dummy/config/application.rb file has:

require "my_engine"

If I understand correctly, this should require the lib/my_engine.rb file and inside that file I have:

require "font-awesome-rails"

So at this point, my_engine should be loaded along with all of it's component gems like font-awesome-rails. I see references to font-awesome in the $LOAD_PATH so this appears to be working.

The error is occurring because the engine has an app/assets/stylesheets/my_engine.scss file which has:

@import "font-awesome";
@import "another-file-from-another-engine-I-wrote";

This file gets loaded because the app/assets/stylesheets/application.scss file of the dummy has:

@import "my_engine";

So, the dummy app imports the scss file in the engine, which in turn pulls in the font-awesome stylesheets. This technique works great for regular Rails applications, but it seems to be failing for the dummy app and I'm stumped as to why.

This isn't a font-awesome issue. If I comment out the @import "font-awesome" inside my_engine.scss , I get the exact same error on the next component asset:

File to import not found or unreadable: another-file-from-another-engine-I-wrote

I've triple checked the files in my_engine to make sure they would match what was generated if I had originally created the gem using rails plugin new . It seems like the dummy app isn't able to load the assets from the sub component gems. What am I missing?

I figured it out. Nothing was telling the engine to load the sass-rails gem. Adding this to my gemspec fixed everything:

spec.add_development_dependency "sass-rails", "~> 5.0.4"

'sass-rails is added to the Gemfile` for new Rails applications which is why everything worked fine in regular rails app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM