cd hello
This directory is the starting point for this exercise. It contains a spec file and you'll be adding a ruby file to (eventually) make the specs pass.
spec hello_spec.rb
You should see an error. Don't just ignore it! Try to read it and figure out what it's telling you. Somewhere on the first line it should say something like
no such file to load -- test-first-teaching/hello/hello (LoadError)
That means that it is looking for a file called "hello.rb" and can't find it.
Open up hello.rb in a text editor. Save it. Run the spec again.
spec hello_spec.rb
Now you should see an error like this:
./hello_spec.rb:3: uninitialized constant Hello (NameError)
Fix this by opening hello.rb and creating an empty class:
class Hello
end
Save it. Run the spec again.
Now you should see an error like this:
$ spec hello_spec.rb
F
1)
NoMethodError in 'Hello says hello'
undefined method `message' for #<Hello:0x1180f3c>
./hello_spec.rb:5:
Finished in 0.002132 seconds
1 example, 1 failure
This means that while it found the file, and it found the class, it couldn't find the method named "message".
In hello.rb, add the following inside the class (before the "end").
def message
end
Save it. Run the spec again.
Now you should see an error like this:
'Hello says hello' FAILED
expected: "hello",
got: nil (using ==)
./hello_spec.rb:5:
This means that there is a method, but it's not returning anything! ("nil" is the Ruby way of saying "not anything".)
Inside the "message" method, put a single line containing a string that is not "hello". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.)
def message
"whuh?"
end
Save it. Run the spec again.
Now you should see an error like this:
'Hello says hello' FAILED
expected: "hello",
got: "whuh?" (using ==)
./hello_spec.rb:5:
Correct this by changing "whuh?" to "hello". Save it. Run the spec again.
Hooray! Finally! It works!
Also, sing a song and do a little dance.