-
-
Notifications
You must be signed in to change notification settings - Fork 761
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
Warn users about stupid behavior like returning from example. #628
Conversation
Currently if you return from example, RSpec happily carries away not executing whole bunch of your examples without any warning. This is VERY dangerous, because it gives false sense that user code is being tested, while it is really not. These warnings should at least give user notification that something is wrong.
My gut is that this feels a bit unnecessary. If you were writing tests first and watching them fail for the right reasons (or even if you write tests afterward, forcing them to fail), is this needed? It's definitely a mistake, but I wonder the value of maintaining code in RSpec to warn about it. |
I wrote that test 6 months ago. It worked perfectly well, no errors. Running rspec "spec_file.rb" gave no errors because lots of examples were not executed (try tracking if there's 150 or 170 dots). How should I have known that rspec behaves like that? And because of this numerous releases with broken code have been deployed into production, just because Last of all - I spend half of a day tracking this down. Do you still feel like this is irrelevant? |
Sorry for the tone, but maintaining 5 lines of code (not counting in warning text) isn't too hard and could save hundreds of hours of developer pain. |
@arturaz are you saying that you wrote a return statement in an example, or that rspec put one somewhere that messed you up? |
That totally sucks, I agree. But I'm thinking that it's because the tests are not written very well. I personally would fully expect that I don't like the idea of adding a warning simply because someone used a construct ( If the tests were written in such a way that the original developer watched the test fail first, this wouldn't have been an issue, I don't think.
Again, I hear you that it sucks :(
I think so, but I'll wait to hear from other folks or team members. |
There are all kinds of silly errors one can make, e.g. writing |
@dchelimsky I did put return into @alindeman I feel that code should try to handle as much human stupidity as possible. Lets talk about dreaded NullPointerException in Java or NoMethodError on nil in Ruby. Does it mean that developer was stupid and messed up? Indeed it does. Does it mean measures shouldn't be taken against it? Of course not. Scala Option monad, Java @NotNull annotation, Kotlin null checking. All of those are there to help people, who make mistakes no matter how skilled they are. Does writing But if RSpec could possibly prevent somebody wiping their database clean, because some test that handled that delicate situation with broken code didn't run and rspec did not report it - I'd say that's a good thing. One way or another - this could be argued as a bug. RSpec has to run 200 examples, but it only runs 100 without any interaction. Seems like a bug to me. Even if it is user induced. |
@fj Please explain exactly how you would catch this kind of error with "fail first, pass afterwards". About stupid errors: IDEs issue warning in Java if you try to compare two strings with == (obj equality) instead of .equals (content equality) This isn't a huge change. It is not a bunch of smart code. Saving people from frustration by merging 5 lines = great success. And if it was possible to catch and warn about other stupid mistakes - my take would be to do that too. |
@arturaz Not sure how much more I can distill it than that. Just write the test first before you write any code and then run it, to be sure that it failed. If you accidentally type "return" at some point, your test won't pass; it won't even run to begin with. I think there could be some merit to something like a style-checker for RSpec (warn if your test contains no assertions, warn if you do |
@arturaz there are hundreds of mistakes you might make like this. RSpec does try from time to time to help when you make a mistake using RSpec's APIs, but it can't be in the business of protecting you from basic Ruby mistakes like this. |
@dchelimsky Seriously? RSpec ignores a bunch of the examples and that's perfectly fine? :) Not even a warning? Not even "100 examples not run" at the end of the specs? Wow. |
RSpec isn't ignoring examples. The test explicitly tells Ruby to bail out of the example via |
FWIW, I tried to repro the error, and from what I can see, you get a https://gist.github.com/2875353 @arturaz I'm 100% on board with @dchelimsky on this. |
@myronmarston, I think it's a 1.8 <=> 1.9 difference.
|
Ok, it seems that I need to take this to JRuby guys then. Sorry for the fuss. |
Currently if you return from example, RSpec happily carries away not
executing whole bunch of your examples without any warning. This is VERY
dangerous, because it gives false sense that user code is being tested,
while it is really not.
These warnings should at least give user notification that something is
wrong.