Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:04:04+00:00 2026-06-11T06:04:04+00:00

I’ve spent 3 hrs starring at this and need some help. I’m pretty new

  • 0

I’ve spent 3 hrs starring at this and need some help.

I’m pretty new to RSpec and I’m trying to write test for my behavior of a class called “game”

I want to test that when called game.play sends a 3×3 grid to the output….that’s all I want to do. I have the RSpec book and I’m trying real hard to figure this out but I’m stumped.
I’ve marked the places I think are key as “FIXME”

here are my test so far…

require_relative '../spec_helper'

# the universe is vast and infinite....and...it is empty

describe "the game class" do
  it "must output a 3x3 game grid on the CLI" do
    player_h = double('human', :player_h => "X") # FIXME - do I stub or mock this?
    player_c = double('computer', :player_c => "O")# FIXME - do I stub or mock this?
    game = Game.new(player_h, player_c)

    #FIXME - how do I get the line below to read this as if it where coming from SDOUT on the cli?
    should_receive(:puts).with("a #{$thegrid[:a1]}|#{$thegrid[:a2]}|#{$thegrid[:a3]} \n")
    game.play
  end
  it "must have a human player" do
    pending "human is X"
  end
  it "must have a computer player" do
    pending "ai is O"
  end
end

and here is the class I’m building this test for (yes I know that’s backwards…I should be writing the test and THEN the code…but like I said, I’m a noob at this…the entire game code is already written…I’m really just tying to understand RSpec now.)…

require_relative "player"
#
#Just a Tic Tac Toe game class
class Game
  #create players
  def initialize(player_h, player_c)
    #bring into existence the board and the players
    @player_h = player_h
    @player_c = player_c
    #value hash for the grid lives here
    $thegrid = {
        :a1=>" ", :a2=>" ", :a3=>" ",
        :b1=>" ", :b2=>" ", :b3=>" ",
        :c1=>" ", :c2=>" ", :c3=>" "
    }
    #make a global var for drawgrid used by player
    $gamegrid = drawgrid

  end
  #display grid on console
  def drawgrid

    board = "\n"
    board << "a #{$thegrid[:a1]}|#{$thegrid[:a2]}|#{$thegrid[:a3]} \n"
    board << "----------\n"
    board << "b #{$thegrid[:b1]}|#{$thegrid[:b2]}|#{$thegrid[:b3]} \n"
    board << "----------\n"
    board << "c #{$thegrid[:c1]}|#{$thegrid[:c2]}|#{$thegrid[:c3]} \n"
    board << "----------\n"
    board << "  1 2 3 \n"
    return board

  end
  #start the game
  def play
    #draw the board
    puts drawgrid
    #make a move
    #alternate player turns
  end

end

Any guidance is much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:04:06+00:00Added an answer on June 11, 2026 at 6:04 am

    IIRC in the RSpec book they pass in an IO object, which is mocked in the tests, but it should also work if you expect STDOUT to receive the puts:

    STDOUT.should_receive(:puts).with("foo")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.