Forum: RSpec cucumber rake file question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-01-15 14:06
(Received via mailing list)
Real beginner question here. I don't really know rake, so I'm stumbling.

As I set a dir to hold my feature files, etc., I'm simply copying the
files structure I see in
/usr/lib/ruby/gems/1.8/gems/cucumber-0.1.13/examples/i18n/en/

I know we need a Rake file ME little dir tree, but I don't think I can
just copy the one in the examples tree - or rather, I think I have to
alter the first line:

$:.unshift(File.dirname(__FILE__) + '/../../../lib')

I don't know if this is bash or some ruby thing I haven't figured out,
but mostly I don't know what to do with the '/../../../lib') part. It
looks like its trying to locate the source dir, but if so, why not just
specify + 'lib'...? After staring at it a bit, I have to admit I don't
grasp what's going on.

Can someone clue me in?

Tom

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2009-01-15 18:14
(Received via mailing list)
On Thu, Jan 15, 2009 at 4:07 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
> $:.unshift(File.dirname(__FILE__) + '/../../../lib')
>
> I don't know if this is bash or some ruby thing I haven't figured out, but
> mostly I don't know what to do with the '/../../../lib') part. It looks like
> its trying to locate the source dir, but if so, why not just specify +
> 'lib'...? After staring at it a bit, I have to admit I don't grasp what's
> going on.
>
> Can someone clue me in?

It has to find the source dir relative to that file.  '/../../../lib'
means to go back up the dir structure three levels and then look for
lib there.

Pat
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-01-15 19:03
(Received via mailing list)
On Thu, Jan 15, 2009 at 4:16 PM, Pat Maddox <pergesu@gmail.com> wrote:

> > copy the one in the examples tree - or rather, I think I have to alter
> the
> > first line:
> >
> > $:.unshift(File.dirname(__FILE__) + '/../../../lib')
> >
>

This is a very, very common idiom in Ruby.

$: is a global variable. It's an alias for $LOAD_PATH. This is an Array
of
directories where Ruby scans for libraries when you do a require.
Similar to
Java's CLASSPATH.

File.dirname(__FILE__) returns the directory of the current script

unshift puts an element at position 0 in an Array.


>
> It has to find the source dir relative to that file.  '/../../../lib'
> means to go back up the dir structure three levels and then look for
> lib there.
>

When you have cucumber as a gem you can delete that line.
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-01-15 19:19
(Received via mailing list)
On Thu, Jan 15, 2009 at 9:16 AM, Pat Maddox <pergesu@gmail.com> wrote:
>>
>> $:.unshift(File.dirname(__FILE__) + '/../../../lib')
>>
>> I don't know if this is bash or some ruby thing I haven't figured out, but
>> mostly I don't know what to do with the '/../../../lib') part.

That line is there because these examples are in the cucumber
directory tree, and that ensures that the features are run with the
code in that tree (and not an installed cucumber gem). So you should
be able to blow that line away.

HTH,
David
D15a45a973443d4562051eb675b60474?d=identicon&s=25 Tom Cloyd (Guest)
on 2009-01-19 03:41
(Received via mailing list)
David Chelimsky wrote:
>>> I know we need a Rake file ME little dir tree, but I don't think I can just
> directory tree, and that ensures that the features are run with the
>>> 'lib'...? After staring at it a bit, I have to admit I don't grasp what's
>> rspec-users mailing list
>> rspec-users@rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
Thanks to all for the generosity of response to my query, which I only
just now noticed.

I did figure out all the details in that "$:" line, when I finally had a
chance to study it.

I did NOT know that the line was optional, though. It's not documented
anywhere that I've seen, although I suppose that to those more
knowledgeable than I that fact may be obvious.

Thanks again!

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-01-19 16:10
Tom Cloyd wrote:
>
>
> I did NOT know that the line was optional, though. It's not documented
> anywhere that I've seen, although I suppose that to those more
> knowledgeable than I that fact may be obvious.

My experience is that, while copious, Ruby documentation suffers from
excessive terseness of expression.  It is almost as if the brevity of
Ruby code influences the writers' ability to express themselves in
English.

If you have not done so already then I suggest that you obtain a couple
of books on Ruby.  Two that I have found extremely well written and
valuable are:

 The Ruby Way, Second Edition: Solutions and Techniques in Ruby
Programming by Hal Fulton (2006); and

 Ruby for Rails: Ruby Techniques for Rails Developers by David Black
(2006).

Despite its title, Ruby for Rails is an expansive look at Ruby with the
Rails framework providing an example of how Ruby is meant to be used
(and sometimes misused).

The Ruby canon of course is the pickaxe book, now revised for Ruby
1.9/2.0.  You would find the second edition very useful.

  Programming Ruby: The Pragmatic Programmers' Guide, Second Edition by
Fowler, Hunt and Thomas (2005)

Myself, I prefer David Black's book to all the rest.  His work is
perhaps the best written textbook that I have ever encountered.
This topic is locked and can not be replied to.