📋
Auto-Grading for Teachers
  • Learn How to Auto-Grade
  • Assertions and Unit Testing
  • Request / Submit Examples
  • 🐍Python Examples
    • Check Variable Values
    • Output Tests
    • Input / Output Tests
    • Print Function Tests
    • Return Function Tests
    • Random Number Tests
    • Parse Student Code
  • ☕Java Examples
    • Check Variable Values
    • Output Tests
    • Input / Output Tests
    • Return Method Tests
    • Class - .toString() and Void Method Tests
    • Random Numbers Tests
    • Array and ArrayList Tests
    • Parse Student Code
  • 💎Ruby Examples
    • Output Tests
    • Input / Output Tests
    • Print Function Tests
    • Return Function Tests
    • Parse Student Code
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Ruby Examples

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
PreviousPrint Function TestsNextParse Student Code

Last updated 3 years ago

Was this helpful?

💎