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:

require 'rspec'
require 'stringio'
require '/usercode/exampleb'
​
RSpec.describe "CodingRoomsUnitTests" do
​
describe "Run add_five() with parameter 5" do
it "expect the function to return 10" do
expect(add_five(5)).to eq(10)
end
end
​
describe "Run add_five() with parameter 0" do
it "expect the function to return 5" do
expect(add_five(0)).to eq(5)
end
end
​
describe "Run add_five() with parameter 6" do
it "expect the function to return 11" do
expect(add_five(6)).to eq(11)
end
end
​
end

Sample Solution:

example.rb
def add_five(number)
number += 5
return number
end
​
puts add_five(5)rub
Export as PDF
Copy link
On this page