📋
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

Output Tests

This is an example of how you can test the output stream of student code.

This test makes sure the student's code prints "Hello World". It assumes the student's file name is example.rb. Replace the require with whatever your student's file name is.

Note: This code converts the output to all lowercase and removes spaces to compare against the correct value.

Grading Tests:

require 'rspec'
require 'stringio'

RSpec.describe "CodingRoomsUnitTests" do

    describe 'Checking file output' do
        it "output should equal 'Hello World'" do
            io = StringIO.new()
            $stdout = io
            load '/usercode/example.rb'
            $stdout = STDOUT
            expect(io.string).to eq("Hello World\n")
        end
    end
    
end

Sample Solution:

example.rb
puts 'Hello World'
PreviousParse Student CodeNextInput / Output Tests

Last updated 3 years ago

Was this helpful?

💎