-
-
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
Invoking with_routing
does not work with the get :index
style of invoking controller actions in controller specs
#1652
Comments
I would like to tackle this issue for hacktoberfest. |
@johndavidmartinez please do go ahead! Let me know if you need any help. |
Sorry. I feel like I overcommitted in the moment. I haven’t had time to work on this issue. I wanted to let you all know. Thanks. |
I spent some time looking into this. It is odd. I wanted to write up my findings in case someone had an ideas. Sorry if this is overly detailed, but I found it useful to type it up: To recap the test app that @samphippen made. It has two test cases:
The fun fact:The The work around:This can be worked around by setting def skip_routing
with_routing do |map|
+ @routes = map
map.draw do
get 'subclass/index' => "subclass#index"
end
end
end Suggestions?I tried setting Any ideas on why the ivar is not in scope when |
I tried also to debug the issue and I wanted to share the results: 1- the passing test is using why not use @cupakromer suggestion to use specify do
routes.draw { get ':controller/:action' }
expect(get: '/subclass/test').to route_to("subclass#test")
end
specify do
routes.draw { get ':controller/:action' }
get :test
expect(response.body).to eq 'ok'
end |
Spent more time on this with the help of @h-m-m, and found the same thing. Tried to dig into why |
As guys previously mentioned in the thread the problem is that `#get` is called on other context then `#with_routing`. It is caused by https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/controller_example_group.rb#L5. ActionDispatch::Assertions::RoutingAssertions is adding #with_routing to an assertion_instance, and ActionController::TestCase::Behavior is adding #get to ControllerExampleGroup. So I decided to add an ControllerAssertionDelegator which will include both of them. Actually AssertionDelegator missed some methods, so I featured them in that delegator. Closes rspec#1652
As guys previously mentioned in the thread the problem is that `#get` is called on other context then `#with_routing`. It is caused by https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/controller_example_group.rb#L5. ActionDispatch::Assertions::RoutingAssertions is adding #with_routing to an assertion_instance, and ActionController::TestCase::Behavior is adding #get to ControllerExampleGroup. So I decided to add an ControllerAssertionDelegator which will include both of them. Actually AssertionDelegator missed some methods, so I featured them in that delegator. Closes rspec#1652
As guys previously mentioned in the thread the problem is that `#get` is called on other context then `#with_routing`. It is caused by https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/controller_example_group.rb#L5. ActionDispatch::Assertions::RoutingAssertions is adding #with_routing to an assertion_instance, and ActionController::TestCase::Behavior is adding #get to ControllerExampleGroup. So I decided to add an ControllerAssertionDelegator which will include both of them. Actually AssertionDelegator missed some methods, so I featured them in that delegator. Closes rspec#1652
As guys previously mentioned in the thread the problem is that `#get` is called on other context then `#with_routing`. It is caused by https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/controller_example_group.rb#L5. ActionDispatch::Assertions::RoutingAssertions is adding #with_routing to an assertion_instance, and ActionController::TestCase::Behavior is adding #get to ControllerExampleGroup. So I decided to add an ControllerAssertionDelegator which will include both of them. Actually AssertionDelegator missed some methods, so I featured them in that delegator. Closes rspec#1652
Is this issue related to/fixed by rails/rails#27371 ? |
Hi Rspec people. This might be helpful: https://stackoverflow.com/questions/27068995/with-routing-test-helper-doesnt-work-for-integration-tests/27083128 I had to waste time googling this again recently. This: http://api.rubyonrails.org/v5.1/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-with_routing is only useful for checking route generation, not executing calls like it was in Rails4 controller tests. So that little helper draws routes, allows to call new routes and then restored them to default state. |
As guys previously mentioned in the thread the problem is that `#get` is called on other context then `#with_routing`. It is caused by https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/controller_example_group.rb#L5. ActionDispatch::Assertions::RoutingAssertions is adding #with_routing to an assertion_instance, and ActionController::TestCase::Behavior is adding #get to ControllerExampleGroup. So I decided to add an ControllerAssertionDelegator which will include both of them. Actually AssertionDelegator missed some methods, so I featured them in that delegator. Closes rspec#1652
As guys previously mentioned in the thread the problem is that `#get` is called on other context then `#with_routing`. It is caused by https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/controller_example_group.rb#L5. ActionDispatch::Assertions::RoutingAssertions is adding #with_routing to an assertion_instance, and ActionController::TestCase::Behavior is adding #get to ControllerExampleGroup. So I decided to add an ControllerAssertionDelegator which will include both of them. Actually AssertionDelegator missed some methods, so I featured them in that delegator. Closes rspec#1652
As guys previously mentioned in the thread the problem is that `#get` is called on other context then `#with_routing`. It is caused by https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/controller_example_group.rb#L5. ActionDispatch::Assertions::RoutingAssertions is adding #with_routing to an assertion_instance, and ActionController::TestCase::Behavior is adding #get to ControllerExampleGroup. So I decided to add an ControllerAssertionDelegator which will include both of them. Actually AssertionDelegator missed some methods, so I featured them in that delegator. Closes rspec#1652
Original context: #817
App that demonstrates issue: https://github.com/samphippen/test_issue_817
In order for this issue to be fixed, all specs in the app linked above should pass.
The text was updated successfully, but these errors were encountered: