# Print Function Tests

This is an example of how you can test the output stream of a student defined function.&#x20;

Ruby makes this super easy with the `output` matcher.&#x20;

`expect { print 'foo' }.to output('foo').to_stdout`

This test makes sure the student's function named `prints_name()` that takes a name as a parameter and prints `"Hello, {name provided}!"` to standard output.  It assumes the student's file name is `example.rb`.  Replace the `require` with whatever your student's file name is.&#x20;

#### **Grading Tests:**

```ruby
require 'rspec'
require 'stringio'
require '/usercode/example'

RSpec.describe "CodingRoomsUnitTests" do

    describe "Run prints_name() with 'Jane'" do
        it "expects output to be 'Hello, Jane!'" do
            expect{prints_name("Jane")}.to output("Hello, Jane!\n").to_stdout
        end
    end

    describe "Run prints_name() with 'Fred'" do
        it "expects output to be 'Hello, Fred!'" do
            expect{prints_name("Fred")}.to output("Hello, Fred!\n").to_stdout
        end
    end

end

```

#### Sample Solution:

{% code title="example.rb" %}

```ruby
def prints_name(name)
    puts 'Hello, ' + name + "!"
end

prints_name("Jane")
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auto-grade.joemazzone.net/ruby-examples/print-function-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
