alexch/learn_ruby

require vs. require_relative - hello exercise

ianalexh opened this issue · 7 comments

https://github.com/alexch/learn_ruby/tree/master/00_hello

This is for everyone's benefit:

I think this is partially because I'm running Ruby 2.0.0, not 1.8.7

When I try "rspec hello_spec.rb" from the Terminal, I get that it can't load the "hello" file, with a listing of directories that it tried to load it from.

I did not define those directories, nor do I know if I can change them.

However, a little research shows me that I can use the "require_relative" method instead of simply "require." Then, if I put "hello.rb" in the same folder as "hello_spec.rb", I can run the test and everything works out.

That took me an hour, so I hope this post saves somebody some time!

  • ianalexh

Did you try just running "rake"? That should take care of the path stuff; if it doesn't then I'd like to know!

On May 13, 2013, at 8:33 AM, ianalexh notifications@github.com wrote:

This is for everyone's benefit:

I think this is partially because I'm running Ruby 2.0.0, not 1.8.7

When I try "rspec hello_spec.rb" from the Terminal, I get that it can't load the "hello" file, with a listing of directories that it tried to load it from.

I did not define those directories, nor do I know if I can change them.

However, a little research shows me that I can use the "require_relative" method instead of simply "require." Then, if I put "hello.rb" in the same folder as "hello_spec.rb", I can run the test and everything works out.

That took me an hour, so I hope this post saves somebody some time!

ianalexh

Reply to this email directly or view it on GitHub.

Well, I couldn't get "rake" to work, but I probably don't know how to use it correctly. The instruction in the file is:

## Run the test

rake

## Watch it fail

I took that to mean that I should type "rake" into the Terminal (I'm a noob, so forgive me).

I also tried "rake hello_spec.rb" and "rake hello.rb" from within the file's directory, but I still can't get the file to load until I use require_relative.

Tried reading about the "rake" command and can't quite make sense of it just yet, so that also makes it harder to know just how to use it.

Any pointers appreciated!

Thanks,
ianalexh

Can you provide the output of the error that arises from running 'rake'?

I took that to mean that I should type "rake" into the Terminal (I'm a
noob, so forgive me).

Yes, that's correct. It's supposed to set up the path and a few other
things (like making rspec only show the first failure, not all of them).
How does it fail?

Here is one I ran on pig-latin, from inside the directory I had set up (rake pig_latin_spec.rb):

rake aborted!
Don't know how to build task 'pig_latin_spec.rb'

By the way, these challenges are very cool and extremely challenging. Each time I pass one, I dance around and feel like a king. Then I go to the next and begin feeling like a fool all over again. Each one takes me 3-5 hours, I think.... (and I REFUSE to google an answer, though I do google methods along the way that I think might help).

Um no, just run "rake". That's r, a, k, e, return. (That's the ruby-world
equivalent of "make" which means "do whatever it takes to build the
project" which usually means "run all the tests".) You could also do "rake
spec" but that's the default.

I'm glad you're enjoying Hard Mode! :-)

Ah, I get it now.... rake works now, but it didn't seem to work before - I think because I hadn't built the *.rb file yet, and didn't understand the "rake" purpose at the time.

Hard Mode?!!? I think I missed "Easy Mode!" (or at least I missed "Intermediate mode").

I'm trying to get accepted into App Academy, with only a smudge of experience writing javascript (maybe 10 hours total). I feel that I'm trying to go from 0-60 in 3 seconds. They say these Test-First exercises should take 10-15 hours in total, but for me, each one is a monumental task.

I'm pretty sure I'm on the right track with "Pig Latin," but I just don't have quite the skills to easily express what I want to say.

I was even trying to write my own "shift" method on an array before I realized that there already is a shift method!

Thanks again,
Ian