Replies: 2 comments
-
I could find this https://guides.rubyonrails.org/testing.html#testing-routes
But I don't see anything related specifically to direct routes.
The error mentioning the host is interesting. Wondering if testing other
routes work?
Would `demo_path(host: 'test.host')` work?
|
Beta Was this translation helpful? Give feedback.
-
Thanks @pirj ! On further investigation, I think I may have been running into a Rails bug unrelated to rspec-rails after all. see: https://discuss.rubyonrails.org/t/bug-direct-routing-paths-with-path-still-require-host/80411 I'd delete or "close" this discussion, but I don't think there's a way to do that! I'm potentially interested in trying to PR a fix for the Rails bug... but only if there's some indication some Rails maintainer might be interested, because in the past I've spent lots of time on PR's that never go anywehre for lack of any Rails maintainer interested in reviewing or merging. |
Beta Was this translation helpful? Give feedback.
-
I have a "direct" route defined in routes.rb:
I can run this in a console
app.demo_path
, and it returns/widgets
, no problem.I am trying to write some tests in an rspec-rails spec,
type: routing
.If I try to execute
demo_path
, I get an argument error,Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
.I guess returning a hash from a direct route ends up calling
url_for
, which in this context complains without knowing the host. Even though I called it asdemo_path
, it really ought not to need a host... But I haven't totally traced everything through all the rails and rspec methods, it's definitely pretty confusing stuff.I wanted to try to compare this to what Rails does... which would help determine if this could be called a bug in rspec-rails... but I'm not sure there is an equivalent of
type: :routing
in Rails own tests? What is the rspec-rails routing spec supposed to correspond to?In general, could anyone recommend the best way/place to test routes like this, including "direct" routes?
Beta Was this translation helpful? Give feedback.
All reactions