-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expose path to view specs #1402
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
Expose path to view specs #1402
Conversation
module Rails | ||
# Methods added to ActionView::TestCase::TestController, only in view specs | ||
module ViewController | ||
def self.included(_klass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm mistaken, this will permanently include the ExtraParamsAccessors
methods into ActionView::TestCase::TestController for the rest of the process, including other types of specs. Is my read on this right, and is that the intended behaviour? To me, this looks like it's basically lazy addition of some methods to ActionView::TestCase::TestController
as opposed to only including some methods in to view specs. If that's the intention, then does the comment need to be changed to better reflect that's whats happening?
PS: If I'm wrong, please let me know, I'm not super familiar with this code ^_^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't thought about that distinction. The intention is to include them only for view specs. It's an awkward fit because the user has to set them somehow, and they've already got a controller object available. I thought about surfacing a whole different object, but the extra params are not unrelated to the controller, request, etc.
That said - what's the right way to include those methods in the controller class just for view specs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cupakromer would know better than me, but my instincts are saying before/after that adds/remove methods in a similar way to how syntax.rb works: https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/expectations/syntax.rb#L38-L64
I've left a few comments. @cupakromer if you agree/have further questions I'd love if you could take a look at this when you get a chance. |
Open question: does this need to be squashed before merging? |
I'd like it if we could get this squashed :) |
end | ||
""" | ||
When I run `rspec spec/views` | ||
Then the examples should all pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay cukes! 💙 I recognize that the style for these mirrors the existing spec. If you'd be so kind to update them with a newer style we working towards that would be great!
- Use backticks for code in descriptions (including scenarios) as in normal markdown, so the scenarios should use
request.fullpath
- Scenarios should start capitalized; does not apply when starting with a code fragment
- Avoid "should" opting for more direct and present language. For example "Actions which do not require extra parameters have
request.fullpath
set"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is resolved, and it's a hangover comment that github didn't squash.
I like how this is progressing. 😸 : I like seeing the progress over the commit history. I'd really like to persevere a bunch of that if we can. I think when doing the final squash, if the ideas, the why of the current design decisions, and details about attempted but ultimately removed design decisions would be awesome 💙 💙 In general I strongly avoid using My thinking goes:
I'm happy to talk to some people tomorrow and get some hard numbers on larger apps and their route count. I'm also happy to test out a benchmark using |
@imryo and I are working on a new branch that does this with a |
@cupakromer @samphippen what's your recommendation for dealing with code that's different in 1.8.7 vs 1.9? |
|
We often conditionally define one of two method implementations based on a Ruby version. Would that work here? (On my phone so hard to link you to examples right now) |
Actually, looking at the include check, I think that 'klass.method_defined?(name)' would work best. It works with strings or symbols on 1.8 and 1.9+ and is constant time instead of linear. |
Thanks @myronmarston! |
Ping @cupakromer, did you get a chance to rereview this? |
Sorry, slipped off my todo list. I will get to this today :-D |
@@ -21,3 +21,4 @@ bundle | |||
.bundle | |||
specs.out | |||
spec/examples.txt | |||
specs.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
@cupakromer I think we have one more comment to straighten out before this can be accepted. It would be great to finish this up. |
a6a2df2
to
527605f
Compare
This enables URL helpers to work in view specs via the `extra_params` API. This API updates the controller's path information via a writer and allows the user to read path information out of the controller.
aa735b5
to
adf9a4d
Compare
Expose path to view specs
Guess people forget this when working on rspec#1402 rspec#1402
Guess people forget this when working on rspec#1402 rspec#1402
Guess people forget this when working on rspec#1402 rspec#1402
Guess people forget this when working on rspec#1402 rspec#1402
Fix for #1347.
Expose inferred path data to view specs, since we already expose inferred controller & action. This will allow view specs to exercise views that depend on the current page.
We did two implementations - the first commit uses
rescue nil
- the second one has no rescues but uses somewhat awkward logic to iterate through the routes to find a matching one.If you know of a better way to implement this without rescue...would love to hear about it.