forked from TheOdinProject/learn_ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
160 lines (118 loc) · 4.34 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<html>
<head>
<title>Test-First Teaching: learn_ruby: hello</title>
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="header">
<h1><a href="http://testfirst.org">TestFirst.org</a></h1>
<h2>the home of test-first teaching</h2>
</div>
<div class="nav">
<h2><a href="../index.html">learn_ruby</a></h2>
<b>Labs:</b>
<ul>
<li>00 Hello</li>
<li><a href="../01_temperature/index.html">01 Temperature</a></li>
<li><a href="../02_calculator/index.html">02 Calculator</a></li>
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li>
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li>
<li><a href="../05_book_titles/index.html">05 Book Titles</a></li>
<li><a href="../06_timer/index.html">06 Timer</a></li>
</ul>
</div>
<h1>hello</h1>
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Hello!</h1>
<p>This lab teaches basic Ruby function syntax.</p>
<h2>Open a terminal in this directory</h2>
<pre><code>cd 00_hello
</code></pre>
<p>This directory is the starting point for this exercise. It contains a spec file and a ruby file to (eventually) make the specs pass.</p>
<h2>Run the test</h2>
<pre><code>rake
</code></pre>
<h2>Watch it fail</h2>
<p>you should see an error like this:</p>
<pre><code>the hello function
says hello (FAILED - 1)
Failures:
1) the hello function says hello
Failure/Error: expect(hello).to eq("Hello!")
NameError:
undefined local variable or method `hello' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001009b8808>
# ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
</code></pre>
<h2>Create the hello function</h2>
<p>Fix this by opening <code>hello.rb</code> and creating an empty function:</p>
<pre><code>def hello
end
</code></pre>
<p>Save it. Run the test again.</p>
<h2>Watch it fail</h2>
<p>Now you should see an error like this:</p>
<pre><code>the hello function
says hello (FAILED - 1)
Failures:
1) the hello function says hello
Failure/Error: expect(hello).to eq("Hello!")
expected: "Hello!"
got: nil (compared using ==)
# ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
</code></pre>
<p>This means that while it found the file, and it found the function, it's not returning anything! ("nil" is the Ruby way of saying "not anything".)</p>
<h2>Make it return something</h2>
<p>Inside the "hello" function, put a single line containing a string that is <em>not</em> "Hello!". (Here we are simulating you making an honest mistake, so we can see what the error message looks like.)</p>
<pre><code>def hello
"whuh?"
end
</code></pre>
<p>Save it. Run the test again.</p>
<h2>Watch it fail</h2>
<p>Now you should see an error like this:</p>
<pre><code>1) the hello function says hello
Failure/Error: expect(hello).to eq("Hello!")
expected: "Hello!"
got: "whuh?" (compared using ==)
# ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
</code></pre>
<p>Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.</p>
<h2>Watch it pass!</h2>
<p>Hooray! Finally! It works!</p>
<h2>Give yourself a high five</h2>
<p>Also, sing a song and do a little dance.</p>
<h2>And then...</h2>
<p>Fix the next failure! <code>:-)</code></p>
<pre><code>the hello function
says hello
the greet function
says hello to someone (FAILED - 1)
</code></pre>
<p>In order to get the next test to pass, your function will need to accept an <em>argument</em>.</p>
<pre><code>def greet(who)
"Hello, #{who}!"
end
</code></pre>
</div>
<div class="tests">
<h1>Tests</h1>
<a class="raw_file" href="hello_spec.rb">hello_spec.rb</a>
<pre>require "hello"
describe "the hello function" do
it "says hello" do
expect(hello).to eq("Hello!")
end
end
describe "the greet function" do
it "says hello to someone" do
expect(greet("Alice")).to eq("Hello, Alice!")
end
it "says hello to someone else" do
expect(greet("Bob")).to eq("Hello, Bob!")
end
end</pre>
</div>
</div>
</div>
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div>
</body>
</html>