-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Introduce NullShow object #1220
Conversation
it "returns it" do | ||
user = double | ||
the_weekly_iteration = double | ||
allow(Show).to receive(:the_weekly_iteration).and_return(the_weekly_iteration) |
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.
Line is too long. [86/80]
Previously, any test that hit the Explore page needed to create a Show in the database with a particular name ("The Weekly Iteration"). Instead, this commit returns a NullShow if that record cannot be found.
4a22683
to
6562686
Compare
Does the weekly iteration ever not exist? |
@JoelQ Pretty much only in tests. And dev, potentially. |
Ah, I see. Won't you still be hitting the database, returning |
Yes. I don't see how we can avoid hitting the DB though. We need to check if it exists somehow. |
Any reason not to use a stub here instead? |
Then I go from needing to create a |
Admittedly, it does feel a little weird to make a null object just for tests. |
Maybe I should just make the Show in a global |
How many specs hit the explore page? I assume we are talking about feature specs? |
Yep. Just feature specs. Right now it's one. But I added another in a branch so decided to try this as a preparatory refactoring. |
If it's only one or two places, would just a factory be ok? |
Alternatively, if there are many things that need to be setup just to visit the explore page, how about creating a helper method named |
It just seems strange to add a Null object that will never be used in production just to remove a line or two from some specs. |
There's actually already a factory. If a spec needs to hit that page, it uses the factory to create the show. It just feels a little off to me to need to remember to do that when any spec happens to hit that page. I take it you're not sold on the null object being worth it? :) |
Yeah, I agree. I think I'll close this. |
Thanks for the back-and-forth! |
Glad to help! |
Previously, any test that hit the Explore page needed to create a Show
in the database with a particular name ("The Weekly Iteration").
Instead, this commit returns a NullShow if that record cannot be found.