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

Compiler parser spec cleanup #15446

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

FnControlOption
Copy link
Contributor

Note: Commit ea79701 may be controversial. I slightly prefer explicit test cases over loops, but I have no strong feelings either way!

@straight-shoota
Copy link
Member

I too prefer unrolled loops for explicitness and grepability.

The loops however do provide value in grouping: They express that all examples are functionally equivalent, just testing different values.
This notion gets lost when they're just unrolled into the long list of examples.

Some sense of togetherness could be established by grouping the examples via describe. This would also assign a description which further helps understanding the purpose. We're missing that far too much in these massive spec files.

The other aspect of functional equivalence has particular relevance for more complex examples: Generalizing the implementation helps keep the code clean and easy to read. For example, extract the shared plumbing into a spec helper method and let the unrolled loop items call that explicitly. Perhaps that could be a strategy to explore for further enhancements of the more complex loops not touched in thie PR.
Of course this mechanism reduces grepability again if the tested source code is constructed in a helper method. It's all about balance.

# loop
%[a b c].each do |value|
  it "#{value} foo" do
    assert_fooing(value)
  end
end

# unrolled with helper
private def it_foos(value)
  it "#{value}.foo" do
    assert_fooing(value)
  end
end

it_foos "a"
it_foos "b"
it_foos "c"

For this PR I'd like to have the former loops grouped into describe blocks.
Unrolling further loops could be left for follow-ups.

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.

2 participants