Skip to content
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

Add specs for Spec filters #8242

Merged
merged 1 commit into from
Nov 7, 2019

Conversation

Fryguy
Copy link
Contributor

@Fryguy Fryguy commented Sep 27, 2019

@asterite Please review.

This adds basic specs for most of the filters as extracted in #8125.

@Fryguy Fryguy mentioned this pull request Sep 27, 2019
@Fryguy Fryguy force-pushed the add_specs_for_spec_filters branch from f62df1e to 42b942f Compare September 27, 2019 15:08
child_descriptions.unshift(item.description)
end

private def build_spec(filename, root = nil, count = 2)
Copy link
Contributor Author

@Fryguy Fryguy Sep 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to find a way to parse a heredoc of an example file, but even if I did, I wouldn't know how to tell it to use the alternate FakeRootContext instead of Spec.root_context. This approach here is similar to what's done in the other specs, so I thought it was good enough.


This method produces the equivalent of a spec file named f.cr with:

context "context_f_1" do
  it "example_f_1_1" do
    # noop
  end

  it "example_f_1_2" do
    # noop
  end
end

context "context_f_2" do
  it "example_f_2_1" do
    # noop
  end

  it "example_f_2_2" do
    # noop
  end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #5671 I have set up a parallel DSL for declaring spec examples. Maybe this SpecEnvironment could be useful here as well? It needs to be adapted to reflect the recent changes to spec internals. But it should work as well.

@asterite
Copy link
Member

Given the massive breakage that this caused, I wonder if we should simply revert this and keep the old, simpler spec. It's also more flexible. But no focus, no rand test and no parallelism in the future. Maybe it's fine. What do you think?

@ysbaddaden
Copy link
Contributor

@asterite don't revert, the benefits (filters, random and parallel runs) clearly trump the breaking change, which is merely to not trust mutable global/shared data.

The breaking change could have been more explicit in the changelog, thought.

@bararchy
Copy link
Contributor

@asterite I took me 3 days to fix everything, please don't revert XD

@Fryguy
Copy link
Contributor Author

Fryguy commented Sep 30, 2019

I think the change that caused the real issue was using at_exit to run the specs. Perhaps we can tweak that part, but the rest of these changes have been really useful. I think these features are very beneficial overall.

Total aside, I have a local branch with random specs, as well as seeded-random specs. It's ready to go, just wanted to get these specs + tags in first, so I'm not building PRs on top of PRs.

@Fryguy
Copy link
Contributor Author

Fryguy commented Oct 1, 2019

I'm not sure if there's something more I need to do for this PR...the 32 bit tests are failing, but I'm not sure if it's a general issue or something to do with my code here.

@ysbaddaden
Copy link
Contributor

Nothing but a review from someone with spec internals knowledge.

@asterite
Copy link
Member

asterite commented Oct 1, 2019

I'll be busy these weeks so at least a review from me well have to wait, sorry.

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good!

child_descriptions.unshift(item.description)
end

private def build_spec(filename, root = nil, count = 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #5671 I have set up a parallel DSL for declaring spec examples. Maybe this SpecEnvironment could be useful here as well? It needs to be adapted to reflect the recent changes to spec internals. But it should work as well.

@Fryguy
Copy link
Contributor Author

Fryguy commented Oct 8, 2019

@straight-shoota Thanks for the pointer to #5671 ... I'll see what I can use from there.

@Fryguy Fryguy force-pushed the add_specs_for_spec_filters branch from 42b942f to 0d69782 Compare October 8, 2019 19:56
@Fryguy Fryguy force-pushed the add_specs_for_spec_filters branch 2 times, most recently from e100357 to 025821e Compare October 8, 2019 20:57
@Fryguy
Copy link
Contributor Author

Fryguy commented Oct 10, 2019

@straight-shoota I've reviewed #5671 and I think for now I'd like to keep this PR as is and refactor to something like that later.


The SpecEnvironment there is a copy of a lot of stuff, and I'd like to avoid the duplication, but the concept it really good. Looking at Spec itself, the big issue with not being able to test is that it uses a lot of class variables which are in turn called directly from the various methods. Detangling that I think is the key. I've started a branch locally where instead of using the Spec module directly with class variables, we instead have a Spec::Environment class (or perhaps part of RootContext itself). We can still keep the top-level Spec DSL methods for convenience, but they defer to an instance of RootContext with its own environment. Then, in specs, we can create a new RootContext, with a separate environment and it won't collide with the singleton environment. cc @asterite

@Fryguy Fryguy force-pushed the add_specs_for_spec_filters branch from 025821e to 6a46b0b Compare October 17, 2019 18:47
@Fryguy
Copy link
Contributor Author

Fryguy commented Oct 17, 2019

Moved the helper methods into a spec_helper.cr similar to #8310 . This will also make it easier to rebase those PRs later.

@RX14
Copy link
Member

RX14 commented Oct 29, 2019

Needs a rebase.

@Fryguy Fryguy force-pushed the add_specs_for_spec_filters branch from 6a46b0b to 62e904f Compare October 30, 2019 22:02
@Fryguy
Copy link
Contributor Author

Fryguy commented Oct 30, 2019

Done.

@Fryguy Fryguy force-pushed the add_specs_for_spec_filters branch from 62e904f to b6e6736 Compare October 30, 2019 22:04
@RX14 RX14 merged commit 13f1c19 into crystal-lang:master Nov 7, 2019
@Fryguy Fryguy deleted the add_specs_for_spec_filters branch November 7, 2019 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants