3 Replies - 788 Views - Last Post: 06 June 2014 - 06:34 PM Rate Topic: -----

#1 heaphyg  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 85
  • Joined: 30-August 13

testing question

Posted 01 June 2014 - 07:01 PM

How might I write a test for the prompt method?

class TicTacToe
  attr_accessor :user_name
  def initialize
    @user_name
  end

  def prompt
    puts "Welcome to Tic Tac Toe!"
    puts "what is your name?"
    self.user_name = gets.chomp.capitalize
  end
end


Is This A Good Question/Topic? 0
  • +

Replies To: testing question

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4359
  • View blog
  • Posts: 12,179
  • Joined: 18-April 07

Re: testing question

Posted 01 June 2014 - 07:07 PM

Create an instance of the class, call prompt and then print the value of user_name to prove it was set properly. :)
Was This Post Helpful? 0
  • +
  • -

#3 heaphyg  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 85
  • Joined: 30-August 13

Re: testing question

Posted 01 June 2014 - 08:11 PM

user_name is undefined in this test. Not sure how to handle testing the dynamic input received from the user .

describe "TicTacToe" do
  context "when prompt is called" do
      it "returns the user's name" do
        tic_tac_toe = TicTacToe.new
        expect(tic_tac_toe.prompt).to eq(user_name)
      end
    end
end


This post has been edited by heaphyg: 01 June 2014 - 08:12 PM

Was This Post Helpful? 0
  • +
  • -

#4 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1377
  • View blog
  • Posts: 3,501
  • Joined: 28-November 09

Re: testing question

Posted 06 June 2014 - 06:34 PM

http://stackoverflow...tdin-with-rspec
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1