forked from TheOdinProject/learn_ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_spec.rb
118 lines (115 loc) · 2.87 KB
/
hello_spec.rb
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
# # Hello!
#
# This lab teaches basic Ruby function syntax.
#
# ## Open a terminal in this directory
#
# cd 00_hello
#
# This directory is the starting point for this exercise. It contains a spec file and a ruby file to (eventually) make the specs pass.
#
# ## Run the test
#
# rake
#
# ## Watch it fail
#
# you should see an error like this:
#
# 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)>'
#
# ## Create the hello function
#
# Fix this by opening `hello.rb` and creating an empty function:
#
# def hello
# end
#
# Save it. Run the test again.
#
# ## Watch it fail
#
# Now you should see an error like this:
#
# 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)>'
#
# 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".)
#
# ## Make it return something
#
# 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.)
#
# def hello
# "whuh?"
# end
#
# Save it. Run the test again.
#
# ## Watch it fail
#
# Now you should see an error like this:
#
# 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)>'
#
# Correct this by changing "whuh?" to "Hello!". Save it. Run the test again.
#
# ## Watch it pass!
#
# Hooray! Finally! It works!
#
# ## Give yourself a high five
#
# Also, sing a song and do a little dance.
#
# ## And then...
#
# Fix the next failure! `:-)`
#
# the hello function
# says hello
#
# the greet function
# says hello to someone (FAILED - 1)
#
# In order to get the next test to pass, your function will need to accept an *argument*.
#
# def greet(who)
# "Hello, #{who}!"
# end
#
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