Skip to content

Commit 488749d

Browse files
committed
Merge pull request #131 from trayo/130_move_getting_started
Moves the 'file not found' and getting_started from hamming and updates the getting_started.md
2 parents 6567c97 + b3af9b4 commit 488749d

File tree

2 files changed

+155
-5
lines changed

2 files changed

+155
-5
lines changed

hello-world/GETTING_STARTED.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Getting Started
2+
3+
These exercises lean on Test-Driven Development (TDD), but they're not an
4+
exact match.
5+
6+
The following steps assume that you are in the same directory as the test
7+
suite.
8+
9+
You must have the `minitest` gem installed:
10+
11+
$ gem install minitest
12+
13+
## Step 1
14+
15+
Run the test suite. It's written using the Minitest framework, and can be
16+
run with ruby:
17+
18+
$ ruby hello_world_test.rb
19+
20+
This will fail, complaining that there is no file called `hello_world`.
21+
22+
To fix the error create an empty file called `hello_world.rb` in the same
23+
directory as the `hello_world_test.rb` file.
24+
25+
## Step 2
26+
27+
Run the test again. It will give you a new error.
28+
29+
1) Error:
30+
HelloWorldTest#test_no_name:
31+
NameError: uninitialized constant HelloWorldTest::HelloWorld
32+
hello-world/hello_world_test.rb:5:in `test_no_name'
33+
34+
Within the first test, we are referencing a constant named `HelloWorld` when
35+
we say `HelloWorld.hello`. When Ruby sees a capitalized name like
36+
`HelloWorld`, it looks it up in a big huge list of all the constants it knows about,
37+
to see what it points to. It could point to anything, and often in Ruby we have
38+
constants that point to definitions of classes or modules.
39+
40+
When it looks `HelloWorld` up in it's list, it doesn't find anything, so we need
41+
to make one.
42+
43+
There are several ways that this error message can be made to go
44+
away, one of which is to define a `HelloWorld` class.
45+
46+
Open up the hello_world.rb file and add the following code:
47+
48+
class HelloWorld
49+
end
50+
51+
## Step 3
52+
53+
Run the test again.
54+
55+
1) Error:
56+
HelloWorldTest#test_no_name:
57+
NoMethodError: undefined method `hello' for HelloWorld:Class
58+
hello_world_test.rb:5:in `test_no_name'
59+
60+
This time we have a `HelloWorld`, but we're trying tell it to `hello`, and
61+
`HelloWorld` doesn't understand that message.
62+
63+
Open up hello_world.rb and add a method definition inside the class:
64+
65+
class HelloWorld
66+
def self.hello
67+
end
68+
end
69+
70+
## Step 4
71+
72+
Run the test again.
73+
74+
1) Failure:
75+
HelloWorldTest#test_no_name [hello_world_test.rb:11]:
76+
When given no name, we should greet the world!.
77+
Expected: "Hello, world!"
78+
Actual: nil
79+
80+
Up until now we've been getting errors, this time we get a failure.
81+
82+
An error means that Ruby cannot even run properly because of things like missing
83+
files or syntax errors, or referring to things that don't exist.
84+
85+
A failure is different. A failure is when Ruby is running just fine
86+
and the test is expecting one outcome, but getting another.
87+
88+
The test is expecting the `hello` method to return the string `"Hello, world!"`. The easiest way
89+
to make it pass, is to simply stick the string `"Hello, world!"` inside the method definition.
90+
91+
## Step 6
92+
93+
Run the test again.
94+
95+
If it fails you're going to need to read the error message carefully to figure
96+
out what went wrong, and then try again.
97+
98+
If it passes, then you're ready to move to the next step.
99+
100+
Open the hello_world_test.rb file, and find the word "skip". All but the first test
101+
start with "skip", which tells Minitest to ignore the test. This is so that
102+
you don't have to deal with all the failures at once.
103+
104+
To activate the next test, delete the "skip", and run the test suite again.
105+
106+
## Wash, Rinse, Repeat
107+
108+
Delete one "skip" at a time, and make each test pass before you move to the
109+
next one.
110+
111+
## Submit
112+
113+
When everything is passing, you can submit your code with the following
114+
command:
115+
116+
$ exercism submit hello_world.rb
117+

hello-world/hello_world_test.rb

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
11
require 'minitest/autorun'
2-
require_relative 'hello_world'
3-
class HelloWorldTest < Minitest::Test
4-
def test_no_strange_name
5-
assert_equal 'Hello, !', HelloWorld.hello(''), 'When giving an empty string, it is strange, but should have a space and punctuation'
6-
end
2+
begin
3+
require_relative 'hello_world'
4+
rescue LoadError => e
5+
puts "\n\n#{e.backtrace.first} #{e.message}"
6+
puts DATA.read
7+
exit 1
8+
end
79

10+
class HelloWorldTest < Minitest::Test
811
def test_no_name
912
assert_equal 'Hello, world!', HelloWorld.hello, 'When giving no name, we should greet the world!'
1013
end
1114

1215
def test_sample_name
16+
skip
1317
assert_equal 'Hello, Alice!', HelloWorld.hello('Alice'), 'When giving "Alice" we should greet Alice!'
1418
end
1519

1620
def test_other_sample_name
21+
skip
1722
assert_equal 'Hello, Bob!', HelloWorld.hello('Bob'), 'When giving "Bob" we should greet Bob!'
1823
end
24+
25+
def test_no_strange_name
26+
skip
27+
assert_equal 'Hello, !', HelloWorld.hello(''), 'When giving an empty string, it is strange, but should have a space and punctuation'
28+
end
1929
end
30+
31+
__END__
32+
33+
*****************************************************
34+
You got an error, which is exactly as it should be.
35+
This is the first step in the Test-Driven Development
36+
(TDD) process.
37+
38+
The most important part of the error is
39+
40+
cannot load such file
41+
42+
It's looking for a file named hello_world.rb that doesn't
43+
exist yet.
44+
45+
To fix the error, create an empty file named hello_world.rb
46+
in the same directory as the hello_world_test.rb file.
47+
48+
Then run the test again.
49+
50+
For more guidance as you work on this exercise, see
51+
GETTING_STARTED.md.
52+
*****************************************************

0 commit comments

Comments
 (0)