On 7 Aug 2010, at 23:18, David Chelimsky wrote:

> On Aug 7, 2010, at 4:37 PM, Ashley Moran wrote:
> 
>> On 7 Aug 2010, at 22:10, David Chelimsky wrote:
>> 
>>> So - what should we do? I don't think changing Minitest is really an 
>>> option, as too many assertion libraries already wrap Minitest assertions. I 
>>> don't think RSpec should be in the business of monitoring methods end-users 
>>> define to make sure they're not overriding pre-existing methods (what if 
>>> you override a method intentionally?). The only thing I'm left with is 
>>> document this particular case and hope for the best, but that feels 
>>> unsatisfactory as well.
>> 
>> While I fully agree if you `def` a method that already exists, you should be 
>> expected to deal with it yourself (that's just the way things are in Ruby), 
>> does the same apply to `let`?  I can actually see an argument that you 
>> should only be able to `let` a method that doesn't already exist, and also 
>> only do it once (which is just a consequence of not being able to override a 
>> method, given the current implementation). 
> 
>> Can you think of any downsides of preventing RSpec users from overriding 
>> existing methods with `let`?
> 
> Yes. Let's say I write a shared example group with this:
> 
> def foo
>  raise "you need to define a foo method in the block passed to 
> it_should_behave_like"
> end
> 
> And you override it using let(:foo), which would be a perfectly reasonable 
> way to handle it. In fact, it would be the way I would handle in 
> instinctively, because now I don't have to wrote my own memoization handling 
> into the method.

I instinctively agree with ashley, but I see your point too David.

Would it be awful to make let even more magic, and do something with #caller to 
forward the message to MiniTest if it didn't come from the code in your example 
block? Maybe the method defined by let could even have a __hidden name, and 
then RSpec can forward the message to that __hidden method if the message was 
sent from within the example block.

Sounds pretty horrible, doesn't it?

> 
>> Are there any popular names already taken?  Or other problems?
>> 
>> To me, `let` is magic.  I don't think of it, first and foremost, of defining 
>> a method.
> 
>> From the RDoc: Generates a method whose return value is memoized after the 
>> first call.
> 
>> I see the things it creates as more like local variables, and just remind 
>> myself that they're methods if I wonder why it works.
>> 
>> I'm not sold either way on this, but I think it's one worth a debate.
> 
> The debate is on! Any other opinions out there?
> 
>> Ash
> 
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users

cheers,
Matt

http://blog.mattwynne.net
+44(0)7974 430184

_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to