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 7672267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:14:46+00:00 2026-05-31T16:14:46+00:00

I want to develop a card-base game in Ruby, and I want to do

  • 0

I want to develop a card-base game in Ruby, and I want to do it in TDD way.

The first class I want to write is Player.
Each player has a hand with 13 cards and on his/her turn can choose and play 1 card to pass.

I have not developed any other classes (like card, hand, ..), I want to know how I can test this subject which has dependency to other classes?

I know about Mocks but I don’t know how can I use them.

For example in this scenario we know that when a player plays one card that card should have to be removed from his/her hand.

This is my code :

require "rspec"
require "lib/player"

describe Player do
  before(:each) do
    hand=mock("Hand")
    hand.should_receive(:count).and_return(13)
    subject.hand=hand
  end

  it "should choose and play a card from her/his hand" do
      subject.hand.count.should==13
      card_selected=subject.play(2)      # card #2 in his/her hand
      subject.hand.count.should=12
   end
end

Also, in the implementation we are dependent to the Hand class, how can I handle it ?

  • 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-05-31T16:14:48+00:00Added an answer on May 31, 2026 at 4:14 pm

    I’ve seen my share of mocking and stubbing, and I’ve seen huge test suites pass even though the app was broken beyond belief because half the code didn’t even exist anymore.

    I’ve come to the conclusion that stubbing and mocking should be used with extreme care. That, and the fact that it should be introduced as late as possible.

    This is one of the cases where it’s too early to mock. You’re mocking just because you don’t have the class Hand yet.

    As a sidenote, the test itself needs improvement. Take a closer look at these lines:

    hand.should_receive(:count).and_return(13)
    subject.hand=hand
    subject.hand.count.should==13
    subject.hand.count.should=12
    

    Of course, subject.hand.count.should==13 passes, you just stubbed it to this value. And of course, subject.hand.count.should=12 passes because you didn’t call ==. If you changed it to a real expectation, you’d be wondering why it fails. It fails because you stubbed Hand#count to always return 13.

    What you’re actually doing here is mocking part of the API under test. Don’t do this. Instead, start with baby steps. This could mean:

    • You start on the inside and work your way out. So start with the innermost class, Hand in this case. Once you get to Player, all the pieces will fit together just fine without mocking.

    • You start with Player until you absolutely need the other class (do that if the argument of a “meaningful API” appeals to you). This means: Wait for a NameError on Hand. Then implement just as much of the Hand class as necessary. Then get back to Player

    Also, looking at your code raises the question: Just out of curiosity, why would you want to separate a player and her hand in the first place?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop a very simple 2D game in Python. Pygame is the
I want to develop ASP.NET C# based MMOG (Massively multiplayer online game). I would
I want to develop a Business card reader or OCR Library (Open Source) for
I want to develop some kind of utility bar. I can position each element
I have to develop an in-browser card game using silverlight. The game requires exactly
I want to develop a windows application. If I use native C++ and MFC
I want to develop Java apps, real quick, what IDE should I choose?
I want to develop simple Serverless LAN Chat program just for fun. How can
I want to develop a mobile web application using asp.net 3.5 that can be
I want to develop an iPhone application using the utility template, where the flip

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.