Skip to content

Conversation

@sclinede
Copy link

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.
But they are included to different classes and do not affect each other.

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#1652

@sclinede
Copy link
Author

sclinede commented Jan 20, 2017

Hi penople. This is my first try for rspec and also just a working draft rather then full solution.
Just want to be sure that I'm on right track)

@sclinedesclinede changed the title with_routing not working with get :indexFix with_routing not working with get :indexJan 20, 2017
@sclinede
Copy link
Author

sclinede commented Jan 20, 2017

On the other hand we can do it like that https://gist.github.com/sclinede/3dc0565e5ef9cb9d99bbcf6719302c5d#file-controller_example_group-rb-L4-L18
I mean move ActionDispatch::Assertions::RoutingAssertions to ControllerExampleGroup

@pirj
Copy link
Member

pirj commented Jan 8, 2020

@sclinede Can you please add a test that would fail without the patch?

@sclinede
Copy link
Author

@pirj You could find failing spec in an additional commit a9adc65

@sclinede
Copy link
Author

The solution was tested against https://github.com/samphippen/test_issue_817 provided by @penelopezone

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. Closesrspec#1652
@sclinede
Copy link
Author

sclinede commented Jan 9, 2020

I don't get it. The test suit is failing around teardown method somewhere deep. If you have any suggestions I'll appreciate.
Meanwhile, trying to figure it out by myself...
@pirj

defsetup(*methods, &block)
@setup_methods += methods
@setup_blocks << blockifblock
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have found it yourself already, but anyway - if you add a def teardown(*); end here, the spec starts failing with a different error.

@sclinede
Copy link
Author

So... it looks like I need more time to invest in that change. Hope I'll find it soon :)
I don't give up

@pirj
Copy link
Member

pirj commented Mar 13, 2020

@sclinede Have you had a chance to take a closer look at teardown problem?

@JonRoweJonRowe changed the base branch from master to mainAugust 2, 2020 02:13
@JonRoweJonRowe mentioned this pull request Jan 18, 2022
21 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invoking with_routing does not work with the get :index style of invoking controller actions in controller specs

2 participants

@sclinede@pirj