-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL helpers do not work in view specs with config.threadsafe! #476
Comments
What's with the extra "app" directory?
Also, change |
The whole Rails application is stored in a directory called "app." So I've removed the leading slash from the view path, no change. |
RSpec's ci suite includes generating and running view specs for the stock rails-generated views, which include links to If you can whip up an app that I can clone, bundle, run specs and see the failure, I'll be glad to reopen this, but closing for now as I cannot reproduce the error. |
Well if I could narrow it down to a proof of concept I could probably fix the problem :) Could you at least lend me some insight? This is the result of calling
And this the result for the same code in my broken app:
Everything's the same except for three missing ancestors: Any ideas on why these are missing, by chance? |
@RISCfuture I wish I could help you, but I don't know how I can without being able to debug your code on my system. Two of the modules are anonymous, and the fact that |
Figured it out. It's setting |
Nice find, helped me out :) |
Hey guys noob here, are you guys adding config.threadsafe! somewhere inside your config/environments/*.rb files? or how did you manage to fix this? |
Personally I modified the test code that required |
that also went over my head i assume you modified a vendored rspec-rails gem to allow disabling |
No, |
I see, mine is off also, so there must be something else :( |
i am also missing |
This issue is quite easy to reproduce when setting Also, not being able to execute tests with |
Here is a provisional fix that worked for my tests. Just put the following code at the end of # This is a provisional fix for an rspec-rails issue
# (see https://github.com/rspec/rspec-rails/issues/476).
# It allows for a proper test execution with `config.threadsafe!`.
ActionView::TestCase::TestController.instance_eval do
helper Rails.application.routes.url_helpers#, (append other helpers you need)
end
ActionView::TestCase::TestController.class_eval do
def _routes
Rails.application.routes
end
end |
@KlausTrainer "cannot-reproduce" removed and issue reopened. Care to make a proper patch w/ specs? |
Maybe on Friday I'll find some time to take a deeper look into this issue and maybe even come up with a patch. |
Great. Thanks. |
@KlausTrainer Which Friday were you referring to? ;-) |
@KlausTrainer: any news? Do you need any help? |
This just bit me, using the monkey patch provided by Klaus for now. |
This is a bug upstream in Rails, IMHO. Here's an require "test_helper"
class FoosViewTest < ActionView::TestCase
test "foos/index.html.erb renders correctly" do
@foos = []
render file: "foos/index.html.erb"
end
end When
Without Given that, I encourage a bug to be filed against Rails. When/if it's fixed, it should trickle down to rspec-rails since our view specs basically wrap an Sorry this took so long to flesh out, but I'm going to close this again unless someone thinks I've missed something. |
Hi guys Just got bitten by this, the fix works well, thanks @KlausTrainer. Is there an issue open in rails for this? If not, I might create one and possibly add a failing test / fix. |
I don't remember creating one. Please do and link it here! |
Hey, I've been wracking my head trying to figure this one out and I've hit a wall. Ever since upgrading our app to Rails 3.1 and RSpec 2.7, the URL helpers are broken in view specs. Example backtrace:
Obviously,
account_path
is a valid auto-generated URL method. Errors of this type are raised for all views that make calls to URL-generating methods.If I modify my
ApplicationHelper
toinclude Rails.application.routes.url_helpers
(which of course I shouldn't have to do), then the method becomes defined, but its call tourl_for
raises an error:Here's an example of one such view spec; pretty straightforward:
The text was updated successfully, but these errors were encountered: