-
Notifications
You must be signed in to change notification settings - Fork 285
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
Use contexts #3
Comments
Deeply nested contexts can be confusing. I wouldn't use any more than 2 levels. |
I agree with this best practice, but I feel there should also be example code of how to set up the context. The |
I agree with @andyw8 and disagree with the rule. |
I disagree with using "should" in describe blocks. Do or do not - there is no "should". |
Edit: Wait - you already have this guideline here. Why is it not used in this example (or others consistently)? |
This particular example confuses me.
My concern is that |
What's the best way to go about setting up the context? Should I just be using before? In the example, the context is magically set up. |
It should be mentioned somewhere that you need |
@kikito |
I agree that the comment by @Balauru should be incorporated. Also the clarification by @warmwaffles would be nice too. These things may be obvious for experience Rails hackers but they aren't clear for a newbie. |
@russellsilva essentially in the background this happens with controller tests: subject { response } If you wish to be more explicit, then by all means, use |
I really fail to see how one is any better than the other. You're adding extra syntax and work for the program just to save yourself a few characters? Also forgot to mention that Most of these tips for writing more clear specs are appreciated, and make a lot of sense. But this one in particular struck me as a little snake oily. |
I am new to rspec. First I type a good solution and in result I have obvious for experienced users 'undefined method context'. Where is application of 'devoted to how to create a great RSpec test suite'? I wish to find reliable resource. |
How are nested contexts supposed to be done? context 'when something is set' do
context 'and when another thing is set' do
end
end is it proper to use |
I usually don't write "and" in my context descriptions, but if I could alias context "when #{message}" to when, I would :)- T On Thu, Jan 9, 2014 at 1:15 PM, Matthew Johnston notifications@github.com
|
You can't use |
Yeah, I realized |
The switch from inline matching to custom matchers from the shoulda gem in the before/after examples are extremely misleading for those of us new to RSpec. |
Personally, I stay away from |
This is inconsistent with http://betterspecs.org/#expect It should be updated to follow the other guideline. |
As a one liner syntax, I would rather recommend |
For this particular topic (and perhaps others), I would like to see what rspec prints out. That would make me better able to evaluate the idea myself. Often I write specs and then rewrite them because the output when the test is run is useless. |
Is it really okay to have nested |
@xirukitepe I think it depends on your workflow and preference. At work, we use Capybara integration tests. Capybara DSL uses Do know, if you run random specs, they will be randomized as follows:
This means, if you have 2 contexts (one saying "Users page", and another saying "sad paths"), what will be randomized is:
|
How about amending:
... to ...
Not so hot (in my opinion)
Better (again, in my opinion)
🍦 🍨 🍧 |
@nagi I like your idea. How about submitting a pull request with the change? |
I'm confused what this particular guideline is about: The good/bad example both adds the context and uses an anonymous |
+1 @warmwaffles about writing nested context with |
I miss "but" even more. Consider this example:
Even if betterspecs doesn't suggest to use a lot of nested contexts: people are doing it. So let's assume that there are many nested contexts in reality: Contexts are really helpful for branching, but they could be much more helpful if we could mark edge cases explicitly. I'd propose to suggest "but" in nested contexts for edge cases. |
Interesting. I really dislike "and" in nested context but I've seen a similar use case to "but ..." with "except ..." |
How about guiding describe vs context and change of test state, e.g.
A simple rule might be "use describe if you aren't adding any let! or before code to implement the context", but I'm not sure it's a good idea. One problem I've noticed is it encourages |
Allow "and" and "but" as well as the default prefixes. This is backed by the following discussion in _betterspecs_: betterspecs/betterspecs#3 (comment)
Write your thoughts about the "use contexts" best practice.
The text was updated successfully, but these errors were encountered: