Trouble setting up Stimpack in app - unable to find routes file within pack

This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.

Message originally sent by slack user U71DGIY2XJP

Hey everyone! First off wanted to thank you for supporting these awesome open source tools! I am a developer at ezCater, and we are having some issues setting up Stimpack in one of our apps, it is unable to fin the routes file within the pack. Hoping this is the right place to get some help. Details in the thread!

Message originally sent by slack user U71DGIY2XJP

We are following the docs on how to split routes between packs. We moved all existing routes into packs/v1/config/routes/v1.rb, and in the main config/routes.rb, simply do draw(:v1). We are seeing the error:

Your router tried to #draw the external file v1.rb,
but the file was not found in:
* /usr/src/app/config/routes

Message originally sent by slack user U71DGIY2XJP

Seems it does not know to look for the routes file inside the pack?

Message originally sent by slack user U78561YO9UP

Hey Ritam, what version of Rails are you on?

Message originally sent by slack user U71DGIY2XJP

v6.1.7

Message originally sent by slack user U716MMIE3T4

<@U71DGIY2XJP> It seems that for some reason, stimpack is not recognising your pack root path. If the stimpack was enabled, the error that you get when trying to draw a non-existing route file would include the pack’s route folder:

... but the file was not found in:
 * /usr/src/app/config/routes
 * /usr/src/packs/v1/config/routes

Message originally sent by slack user U716MMIE3T4

Because of that, I suspect the problem is with correctly enabling stimpack rather than with that single v1.rb route file (which seems like correctly placed).

Message originally sent by slack user U716MMIE3T4

If you haven’t manually configured Stimpack.config.root path, the default path for the packs is expected to be in the root folder - "#{Rails.root}/packs" (not in the "#{Rails.root}/app/packs/ ). <@U71DGIY2XJP> Just to confirm - is that the case in your application?

Message originally sent by slack user U71DGIY2XJP

Yeah, it wasn’t working when Stimpack.config.root was not manually configured. I added Stimpack.config.root = "packs" but that did not seem to fix it

Message originally sent by slack user U71DGIY2XJP

So to clarify, I have tried both setting and not setting the Stimpack.config.root, neither seeemd to work

Message originally sent by slack user U716MMIE3T4

I see. Well, given that you named your folder as packs, theoretically you shouldn’t need to set config root.

Message originally sent by slack user U716MMIE3T4

Let’s try something else ten - could you please paste the full paths of both config/routes/routes.rb and config/routes/v1.rb files please?

Message originally sent by slack user U71DGIY2XJP

yessir, they are:
/Users/ritambanerjee/code/work/pos-rails/config/routes.rb

/Users/ritambanerjee/code/work/pos-rails/packs/v1/config/routes/v1.rb

Message originally sent by slack user U716MMIE3T4

Hi again <@U71DGIY2XJP>, sorry for not responding during the weekend.

Thanks for sharing the full paths. They look correct. I tested it on my local machine, with Rails 6.1.7 and stimpack 0.7.1 and the routes were loaded correctly. So let’s try to investigate it a bit further.

I have two questions now:

  1. In your package folder, is package.yml file present? (The path of that file should be /Users/ritambanerjee/code/work/pos-rails/packs/v1/package.yml)
  2. Could you please run bin/rails runner 'pp Stimpack::Packs.root' and bin/rails runner 'pp Stimpack::Packs.all' to check the Stimpack config?

Message originally sent by slack user U71DGIY2XJP

No worries hope you had a good weekend! Ohhh I had the package.yml in the package in the wrong place! Moved it where you specified and it seems to work! Thanks so much!!

Message originally sent by slack user U716MMIE3T4

Great to hear that <@U71DGIY2XJP>! Good luck - and please share your experiences of using packwerk in the <#C02TLU33RNW|packwerk> channel, it will be super interesting to hear them :wink:

Message originally sent by slack user U71DGIY2XJP

I will definitely do that!
Quick follow up question, is there anything that needs to be done to get Rspec to pick up on tests in the pack?
rspec packs/v1/spec/models/* → no specs run
rspec packs/v1/spec/models/foobar_spec.rb → runs the one file

Message originally sent by slack user U716MMIE3T4

I assume you’ve added the --require stimpack/rspec into the .rspec file, as README suggests?

Message originally sent by slack user U716MMIE3T4

After a quick look at README and the source code, it looks like running tests from just one folder within the package might not be supported… But I’m not 100% sure

Message originally sent by slack user U71DGIY2XJP

yeah, Ive pointed rspec to the new pack. Ok, thanks!