-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Spec: add support for focus
#8125
Conversation
Before this commit an `it` block ran immediately. This makes it hard to implement other filtering mechanisms. In particular to implement something like RSpec's `focus` we need to first know whether there's any example marked with `focus: true`. Without collecting all examples first we can't do this. So, this commit first collects all describes, contexts and examples and then filters then. The code is now much cleaner is easier to extend.
Another thing this refactor will enable is running specs in random order: can't do that if they always run one after the other. |
I don't understand the purpose of the |
You can just focus on a few specs. Tagging is more complex: you need to think about a name, pass a flag, etc. I personally don't find tags useful, but |
So the workflow is this: I need to add something new somewhere. I write a new Or maybe I add a new feature and just a single test starts failing. I can focus on that, fix it, then remove it, etc. |
Some JS testing libs have this as well. Is quite helpful. |
Love this change specifically because in #8068 I'm finding the filtering rules very difficult to implement since the "it" is matched first before checking the contexts, and that made it hard when trying to match the RSpec filtering logic. I do have 2 concerns however.
|
Additionally, in RSpec, focus is basically just a tag which follows the tag rules (with special logic elsewhere to auto-add focus to the list of requested tags) Would it make more sense to treat is as such after #8068 is merged, and thus not introduce a specific |
I don't think so. The overhead is just creating lists of objects. The std specs have like 9000 specs. Creating an array of 9000 elements is almost instantaneous compared to the time it takes to actually run the spec contents.
I don't think we should copy RSpec here. The way it's done in this PR, and how it was done previously, is that each filter (location, focus, pattern, etc.) keeps some tests and removes others. Applying them in any order should give the same result: they are additive. So if we introduce tags we just need to filter examples with or without the given tags. |
Sounds good to me, and is what I was thinking as well...much more intuitive. |
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 love it! This is required for parallelizing specs too, once preview_mt
lands.
The refactor is much cleaner.
@RX14 Thank you! |
@RX14 I think it is also a necessary step to implement bisect, for finding order dependent errors. |
I was also thinking about adding |
Is this really the behaviour we want? This is a breaking change for quite a few specs. I explicitly used this as a feature. It allows to define pending specs which uses code that is not currently working but supposed to be implemented/fixed at some point. |
An example from # TODO: find_file returns empty string
pending "#find_file" do
it "finds file" do
Sass.new(include_path: INCLUDES_PATH).find_file("_simple.scss").should eq File.join(INCLUDES_PATH, "_simple.scss")
end
end
I could obviously comment it out. But I don't see much sense in compiling the content of |
I guess we can change it. I thought it was an inevitable side effect of the refactor, but I just need to make |
Actually I won't do it. If someone wants to do it please go ahead. |
There were some specs in the ecosystem that used Luckily the workaround is for the let cleanup happen when the process finished in this case, or monkey patch the |
I think that's wrong. We should probably add a Also, we could probably add |
In addition to before(:all) and after(:all), rspec has before(:suite) and after(:suite) which might be more appropriate in some cases (such as those at_exit cases). I think crystal should eventually offer all 3 as well.
|
- Fix test cases that were failing because Crystal's Spec library now executes `it` blocks at the end of the program (crystal-lang/crystal#8125). Instead of manually destroying the Duktape head in specs, let the GC take care of it. - Update `ameba` to 0.10.1.
This PR includes a series of refactors to
Spec
in order to be able to supportfocus
. Then it adds supports for it.From one of the commits description:
focus: true
Now you can mark
describe
,context
andit
withfocus: true
.When you do that, only the things that are marked with
focus: true
will run. This is really useful to, well, focus on one or several specs. One can usually pass a line number, but in my experience it sometimes happens that you add stuff at the top of the spec file and the the line numbers shift. Adjusting the numbers is a bit tedious.When any spec is marked with
focus: true
a new message appears at the end of the spec run:(in cyan)
This is because you might forget that you left a
focus: true
and don't understand why only just a couple of specs run.Better line matching
Now an entire
describe
/context
will run if you specify a line that thedescribe
contains but no innerdescribe
/it
matches. This is similar to RSpec. And this was impossible to do without collecting things.An example:
Previously nothing ran.
tags
I didn't implement it yet. But with this in place #8068 should become much, much simpler to do.
Breaking change?
This is a breaking change because if you do something like:
then it will fail because each
it
runs at the end of the program andfoo
's value will have changed.However, I think this isn't that bad:
Another thing:See: #8178pending
block will now be compiled but not ran. Apparently this wasn't the case before. In one spec we passedraw_url
to URI but I have no idea what that is, so I removed it.