[rspec-users] Problems with Set after upgrade to RSpec 1.2.9

Shot (Piotr Szotkowski) shot at hot.pl
Sun Oct 11 07:25:01 EDT 2009


David Chelimsky:

>> RSpec 1.2.9 adds ./lib and ./spec (from the project root) to the load
>> path. So it sounds it's loading your custom 'set' before the one in
>> stdlib.

That would explain that backtrace. Thanks for the clarification!

>> I've run into load order problems like this before, and found that
>> the safest bet is to have the extension at a different path than that
>> of the core lib. So in this case, I'd recommend putting the 'set'
>> extensions in ./lib/extensions/set (or something similar - anything
>> other than ./lib/set), and then require 'set' _from that file_.

I was waiting a bit to see whether there emerges any common naming of
the directory carrying patches for core/stdlib classes (core? base?
core-ext? stdlib?) before breaking my ‘file path maps 1:1 to class name’
rule. But you’re right that having ‘require 'set'’ and ‘require_relative
'set'’ next to each other and actually *wanting* them to load two
different files does not feel like following the path of least surprise.

> FYI - from http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices:

> <snip>
> It may seem harmless to call files whatever you’d like in your package
> because you are “namespaced” in your own package. But if lib/ is
> prepended to $LOAD_PATH it will clobber Ruby’s built in erb and
> set libs. require 'erb' would no longer require Ruby’s builtin erb
> library, but this package’s version of it.

> The safe (and correct) way would be to namespace your files under
> another directory. Its conventional to create a folder within lib
> with the same name as your gem. Then we would put all our dependency
> files under lib/foo/ instead of at lib/ root.
> </snip>

> I agree, and I think this applies to extensions to stdlib
> and core classes as I mentioned in my previous post.

Ah, right – I actually remembered reading
this somewhere, but forgot the source. Thanks!

— Shot
-- 
When I die, I want my last words to be some harsh call that will
haunt some poor bastard forever. Like, just say to the doctor ‘your
shirt is terrible; one of us will have to go’, then die.   [bossan]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091011/3826f5aa/attachment.bin>


More information about the rspec-users mailing list