Return Function Tests
Students writes a function named add_five() that takes an integer as a parameter and returns 5 plus the parameter value.

Grading Tests:

1
require 'rspec'
2
require 'stringio'
3
require '/usercode/exampleb'
4
​
5
RSpec.describe "CodingRoomsUnitTests" do
6
​
7
describe "Run add_five() with parameter 5" do
8
it "expect the function to return 10" do
9
expect(add_five(5)).to eq(10)
10
end
11
end
12
​
13
describe "Run add_five() with parameter 0" do
14
it "expect the function to return 5" do
15
expect(add_five(0)).to eq(5)
16
end
17
end
18
​
19
describe "Run add_five() with parameter 6" do
20
it "expect the function to return 11" do
21
expect(add_five(6)).to eq(11)
22
end
23
end
24
​
25
end
Copied!

Sample Solution:

example.rb
1
def add_five(number)
2
number += 5
3
return number
4
end
5
​
6
puts add_five(5)rub
Copied!
Export as PDF
Copy link
Contents