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

Re-enable tests for raise_error #2

Closed
edisonywh opened this issue Jun 8, 2019 · 0 comments · Fixed by #16 · May be fixed by #12
Closed

Re-enable tests for raise_error #2

edisonywh opened this issue Jun 8, 2019 · 0 comments · Fixed by #16 · May be fixed by #12
Assignees

Comments

@edisonywh
Copy link
Owner

Problem

Currently behaves uses at_exit to run checks for behaves_like. The problem with this is that this screws with rspecs's raise_error.

I've opened up an issue over at rspec/rspec-expectations#1117

I'm trying to look for an alternative if there's one, feel free to make a PR if you know of any.

Rationale

The reason for using at_exit is as follow:

The point of at_exit is so that you can put your behaves_like at the top of the file.

Because code is evaluated from top to bottom, there's no way for behaves_like to know what method the class has implemented, unless you put it all the way down at the bottom, after the declaration of all methods, which is ugly and unconventional.

@edisonywh edisonywh self-assigned this Jun 12, 2019
edisonywh added a commit that referenced this issue Jun 12, 2019
A reply is given for the [RSpec
issue](rspec/rspec-expectations#1117), I've
reviewed the proposed solution and found that I'd take a different
approach instead in order to fix the `at_exit` spec.

First off, this commit extracts out the core logic for `behaves_like`
into a `private` method. This is important for a couple of reason.

By extracting it out, `behaves_like` now only consists of the `at_exit`
logic, and because I can't test `at_exit` due to the nature of it, I've
decided to test directly on the newly extracted `private` method.

While it is generally frowned upon to test private methods (you should
be testing the public interfaces only!!), and I do agree on that on a
general case, I think that this is an exceptional situation that calls
for a break of rules.

Guidelines should be all that is, guides, it should not be rules that
prevent innovation. Thus I've decided to break the rule this time.

Fixes #2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant