You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 00_hello/hello_spec.rb
+116Lines changed: 116 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,119 @@
1
+
# # Hello!
2
+
#
3
+
# This lab teaches basic Ruby function syntax.
4
+
#
5
+
# ## Open a terminal in this directory
6
+
#
7
+
# cd 00_hello
8
+
#
9
+
# 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.
10
+
#
11
+
# ## Run the test
12
+
#
13
+
# rake
14
+
#
15
+
# ## Watch it fail
16
+
#
17
+
# You should see an error. **Don't get scared!** Try to read it and figure out what the computer wants to tell you. Somewhere on the first line it should say something like
18
+
#
19
+
# no such file to load -- test-first-teaching/hello/hello (LoadError)
20
+
#
21
+
# That means that it is looking for a file called `hello.rb` and can't find it.
22
+
#
23
+
# ## Create hello.rb
24
+
#
25
+
# Open up `hello.rb` in a text editor. Save it. Run the test again.
26
+
#
27
+
# rake
28
+
#
29
+
# ## Watch it fail
30
+
#
31
+
# Now you should see an error like this:
32
+
#
33
+
# the hello function
34
+
# says hello (FAILED - 1)
35
+
#
36
+
# Failures:
37
+
#
38
+
# 1) the hello function says hello
39
+
# Failure/Error: hello.should == "Hello!"
40
+
# NameError:
41
+
# undefined local variable or method `hello' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001009b8808>
42
+
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
43
+
#
44
+
# ## Create the hello function
45
+
#
46
+
# Fix this by opening `hello.rb` and creating an empty function:
47
+
#
48
+
# def hello
49
+
# end
50
+
#
51
+
# Save it. Run the test again.
52
+
#
53
+
# ## Watch it fail
54
+
#
55
+
# Now you should see an error like this:
56
+
#
57
+
# the hello function
58
+
# says hello (FAILED - 1)
59
+
#
60
+
# Failures:
61
+
#
62
+
# 1) the hello function says hello
63
+
# Failure/Error: hello().should == "Hello!"
64
+
# expected: "Hello!"
65
+
# got: nil (using ==)
66
+
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
67
+
#
68
+
# 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".)
69
+
#
70
+
# ## Make it return something
71
+
#
72
+
# Inside the "hello" function, 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.)
73
+
#
74
+
# def hello
75
+
# "whuh?"
76
+
# end
77
+
#
78
+
# Save it. Run the test again.
79
+
#
80
+
# ## Watch it fail
81
+
#
82
+
# Now you should see an error like this:
83
+
#
84
+
# 1) the hello function says hello
85
+
# Failure/Error: hello().should == "Hello!"
86
+
# expected: "Hello!"
87
+
# got: "whuh?" (using ==)
88
+
# # ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
89
+
#
90
+
# Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.
91
+
#
92
+
# ## Watch it pass!
93
+
#
94
+
# Hooray! Finally! It works!
95
+
#
96
+
# ## Give yourself a high five
97
+
#
98
+
# Also, sing a song and do a little dance.
99
+
#
100
+
# ## And then...
101
+
#
102
+
# Fix the next failure! `:-)`
103
+
#
104
+
# the hello function
105
+
# says hello
106
+
#
107
+
# the greet function
108
+
# says hello to someone (FAILED - 1)
109
+
#
110
+
# In order to get the next test to pass, your function will need to accept an *argument*.
<divclass="nav"><h2><ahref="../index.html">learn_ruby</a></h2><b>Labs:</b><ul><li>00 Hello</li><li><ahref="../01_temperature/index.html">01 Temperature</a></li><li><ahref="../02_calculator/index.html">02 Calculator</a></li><li><ahref="../03_mega_calculator/index.html">03 Mega Calculator</a></li><li><ahref="../04_simon_says/index.html">04 Simon Says</a></li><li><ahref="../05_pig_latin/index.html">05 Pig Latin</a></li><li><ahref="../06_silly_blocks/index.html">06 Silly Blocks</a></li><li><ahref="../07_performance_monitor/index.html">07 Performance Monitor</a></li><li><ahref="../08_hello_friend/index.html">08 Hello Friend</a></li><li><ahref="../09_temperature_object/index.html">09 Temperature Object</a></li><li><ahref="../10_book_titles/index.html">10 Book Titles</a></li><li><ahref="../11_timer/index.html">11 Timer</a></li><li><ahref="../12_dictionary/index.html">12 Dictionary</a></li><li><ahref="../13_rpn_calculator/index.html">13 Rpn Calculator</a></li><li><ahref="../14_xml_document/index.html">14 Xml Document</a></li><li><ahref="../15_array_extensions/index.html">15 Array Extensions</a></li><li><ahref="../16_in_words/index.html">16 In Words</a></li></ul></div>
<p>This lab teaches basic Ruby function syntax.</p>
17
37
@@ -22,7 +42,7 @@ <h2>Open a terminal in this directory</h2>
22
42
23
43
<p>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.</p>
24
44
25
-
<h2>Run the spec</h2>
45
+
<h2>Run the test</h2>
26
46
27
47
<pre><code>rake
28
48
</code></pre>
@@ -38,7 +58,7 @@ <h2>Watch it fail</h2>
38
58
39
59
<h2>Create hello.rb</h2>
40
60
41
-
<p>Open up <code>hello.rb</code> in a text editor. Save it. Run the spec again.</p>
61
+
<p>Open up <code>hello.rb</code> in a text editor. Save it. Run the test again.</p>
42
62
43
63
<pre><code>rake
44
64
</code></pre>
@@ -67,7 +87,7 @@ <h2>Create the hello function</h2>
67
87
end
68
88
</code></pre>
69
89
70
-
<p>Save it. Run the spec again.</p>
90
+
<p>Save it. Run the test again.</p>
71
91
72
92
<h2>Watch it fail</h2>
73
93
@@ -96,7 +116,7 @@ <h2>Make it return something</h2>
96
116
end
97
117
</code></pre>
98
118
99
-
<p>Save it. Run the spec again.</p>
119
+
<p>Save it. Run the test again.</p>
100
120
101
121
<h2>Watch it fail</h2>
102
122
@@ -109,7 +129,7 @@ <h2>Watch it fail</h2>
109
129
# ./hello/hello_spec.rb:5:in `block (2 levels) in <top (required)>'
110
130
</code></pre>
111
131
112
-
<p>Correct this by changing "whuh?" to "Hello!". Save it. Run the spec again.</p>
132
+
<p>Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.</p>
<divclass="nav"><h2><ahref="../index.html">learn_ruby</a></h2><b>Labs:</b><ul><li><ahref="../00_hello/index.html">00 Hello</a></li><li>01 Temperature</li><li><ahref="../02_calculator/index.html">02 Calculator</a></li><li><ahref="../03_mega_calculator/index.html">03 Mega Calculator</a></li><li><ahref="../04_simon_says/index.html">04 Simon Says</a></li><li><ahref="../05_pig_latin/index.html">05 Pig Latin</a></li><li><ahref="../06_silly_blocks/index.html">06 Silly Blocks</a></li><li><ahref="../07_performance_monitor/index.html">07 Performance Monitor</a></li><li><ahref="../08_hello_friend/index.html">08 Hello Friend</a></li><li><ahref="../09_temperature_object/index.html">09 Temperature Object</a></li><li><ahref="../10_book_titles/index.html">10 Book Titles</a></li><li><ahref="../11_timer/index.html">11 Timer</a></li><li><ahref="../12_dictionary/index.html">12 Dictionary</a></li><li><ahref="../13_rpn_calculator/index.html">13 Rpn Calculator</a></li><li><ahref="../14_xml_document/index.html">14 Xml Document</a></li><li><ahref="../15_array_extensions/index.html">15 Array Extensions</a></li><li><ahref="../16_in_words/index.html">16 In Words</a></li></ul></div>
Copy file name to clipboardExpand all lines: 01_temperature/temperature_spec.rb
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,20 @@
1
+
# # Topics:
2
+
# * functions
3
+
# * floating-point math
4
+
#
5
+
# # Hints
6
+
#
7
+
# Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit.
8
+
#
9
+
# In integer math, there **are no fractions**. So if you are using integer literals, you will be using integer math, which means, for example...
10
+
#
11
+
# 1 / 2 => 0
12
+
#
13
+
# In floating point math, there **are** fractions. So...
0 commit comments