behaves icon indicating copy to clipboard operation
behaves copied to clipboard

Add block support to behaves_like

Open PikachuEXE opened this issue 5 years ago • 7 comments

Fix #2 by using block Not sure if I should remove the at_exit one

PikachuEXE avatar Jun 10 '19 03:06 PikachuEXE

Are you sure Travis is setup properly o_0?

PikachuEXE avatar Jun 10 '19 03:06 PikachuEXE

👋Thanks for the PR Pikachu! Really appreciate it. Will take a look at it and get back to you.

EDIT: Yeah I use CircleCI and it doesn't look like it's working properly :p I'll take a look, thanks!

edisonywh avatar Jun 10 '19 13:06 edisonywh

Hey, I took a look at it and here are my thoughts:

While the idea proposed in this PR is a good solution, I don't think it is a suitable fix for #2.

Reason being that the idea of the issue is to re-enable the specs, however with your implementation it's not fixing it, but rather changing the usage altogether. This would drastically change the usage of it, which I'd rather not do. I also don't see additional use cases for converting it to be a block. Perhaps you could show me some potential use cases that are only possible with blocks!

That being said, while I really appreciate your hard work, I'm afraid I can't accept the PR as it would alter the usage significantly.

I've came up with an alternate idea over at #16 and would love to hear your feedback on that!

edisonywh avatar Jun 12 '19 17:06 edisonywh

I agree this won't fix #2 I am actually having doubt on your code will then throw error on file load

I do see your tests on #16 But when is check_for_unimplemented called? I only see such error on "exit" (If I do console load) Instead on definition

Ruby doc for at_exit says:

Converts block to a Proc object (and therefore binds it at the point of call) and registers it for execution when the program exits. If multiple handlers are registered, they are executed in reverse order of registration.

So this PR is for forcing error to be raised at the end of block call (when block given) Of course current way works too but I need to start console and exit to see the errors :P

PikachuEXE avatar Jun 13 '19 06:06 PikachuEXE

Could you elaborate on this?

I need to start console and exit to see the errors

Not exactly sure how to replicate so not sure if I'm fully understanding you

edisonywh avatar Jun 15 '19 07:06 edisonywh

If I require a file with this content in console (irb, pry, etc.):

# require_relative "behaves"

class Animal
  extend Behaves

  implements :method_one, :method_two
end
class Dog
  extend Behaves

  behaves_like Animal
end

It won't fire any error until I type exit

PikachuEXE avatar Jun 17 '19 01:06 PikachuEXE

Ah, I got it now! This is a very valid concern that your PR is trying to solve, thanks so much for bringing this up!

I've opened up an issue here #21 hoping to discuss any potential alternative (although I'm leaning towards your solution now), but meanwhile I'll reopen this PR :)

Thanks again Pikachu!

edisonywh avatar Jun 18 '19 13:06 edisonywh