Skip to content

Fix with_routing not working with get :index - #1777

Open
sclinede wants to merge 2 commits into
rspec:mainfrom
sclinede:fix/issue-1652
Open

sclinede wants to merge 2 commits into
rspec:mainfrom
sclinede:fix/issue-1652

Conversation

@sclinede

Copy link
Copy Markdown

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

sclinede commented Jan 20, 2017

Copy link
Copy Markdown
Author

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)

@sclinede sclinede changed the title with_routing not working with get :index Fix with_routing not working with get :index Jan 20, 2017
@sclinede

sclinede commented Jan 20, 2017

Copy link
Copy Markdown
Author

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

pirj commented Jan 8, 2020

Copy link
Copy Markdown
Member

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

@sclinede

sclinede commented Jan 9, 2020

Copy link
Copy Markdown
Author

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

@sclinede

sclinede commented Jan 9, 2020

Copy link
Copy Markdown
Author

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

Comment thread spec/rspec/rails/example/controller_example_group_spec.rb Outdated
Comment thread spec/rspec/rails/example/controller_example_group_spec.rb
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
@sclinede

sclinede commented Jan 9, 2020

Copy link
Copy Markdown
Author

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

def setup(*methods, &block)
@setup_methods += methods
@setup_blocks << block if block
end

Copy link
Copy Markdown
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
Copy Markdown
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

pirj commented Mar 13, 2020

Copy link
Copy Markdown
Member

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

@JonRowe
JonRowe changed the base branch from master to main August 2, 2020 02:13
@JonRowe JonRowe mentioned this pull request Jan 18, 2022
21 tasks
Sign up for free to 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