metaprogramming and modules inclusion in World

28 views
Skip to first unread message

Joaquin Rivera Padron

unread,
Jun 8, 2010, 11:17:44 AM6/8/10
to cu...@googlegroups.com
hi there,
even though I don't really 100% like the approach of opening classes and redefining them in my steps, as a sort of stubbing I'd say, for speed reasons I do it sometimes.

Today I defined a method that will be meta-programatically redefined (eval-ed) using a parameter, please take a look here http://gist.github.com/430157

the thing is the method works when defined directly in the steps file, but when I move it to a helper module and include it in the World then it does not work.

so, even though I don't really have a clear question to ask, I guess a try would be:
* is it that meta-programming is a no-go in World's inclusions?
* what's the effect of redefining classes like this?
* what's your opinion on the use of this approach?

greetings,
joaquin

--
www.least-significant-bit.com

Matt Wynne

unread,
Jun 8, 2010, 12:39:20 PM6/8/10
to cu...@googlegroups.com
On 8 Jun 2010, at 16:17, Joaquin Rivera Padron wrote:

hi there,
even though I don't really 100% like the approach of opening classes and redefining them in my steps, as a sort of stubbing I'd say, for speed reasons I do it sometimes.

Today I defined a method that will be meta-programatically redefined (eval-ed) using a parameter, please take a look here http://gist.github.com/430157

the thing is the method works when defined directly in the steps file, but when I move it to a helper module and include it in the World then it does not work.

Just a guess, but try changing line 12 to 
  module ::Recaptcha

You might be ending up defining a new module inside the Cucumber::World namespace instead of duck punching the one you're aiming for.


so, even though I don't really have a clear question to ask, I guess a try would be:
* is it that meta-programming is a no-go in World's inclusions?
* what's the effect of redefining classes like this?
* what's your opinion on the use of this approach?

greetings,
joaquin

--
www.least-significant-bit.com

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.

Matt Wynne

unread,
Jun 8, 2010, 12:48:23 PM6/8/10
to cu...@googlegroups.com
On 8 Jun 2010, at 16:17, Joaquin Rivera Padron wrote:

I think it's OK. In a perfect world libraries like this would come ready-rolled with API methods to let you do this kind of thing from tests, but for now you can either wrap the library, and add that kind of functionality to your library, or get a bit more violent as you've done.

One thing to watch out for, I *think* that patch will live on in the code after the scenario is finished, so you need to bear that in mind. It's much better if scenarios leave no trace, otherwise you can end up with weird dependencies between scenarios.

You could try something like this instead, which decorates the recpatcha module with some extra behaviour, and should leave things a little cleaner.

Joaquin Rivera Padron

unread,
Jun 9, 2010, 4:24:01 AM6/9/10
to cu...@googlegroups.com
thanks for your answer. That short circuit trick is really nice, will give those a try

joaquin

2010/6/8 Matt Wynne <ma...@mattwynne.net>



--
www.least-significant-bit.com
Reply all
Reply to author
Forward
0 new messages