Prev: RVM Snow Leopard
Next: rdoc-data 2.5.1 Released
From: Jesús Gabriel y Galán on 10 Jun 2010 12:30 Hi, I have a class that keeps track of its subclasses using the self.inherited hook: module GameFramework class Game attr_accessor :event_handler @available_games = [] class << self attr_reader :available_games end def self.inherited subclass @available_games << subclass end end end I want to test this class, but I have a problem testing both the case when there are no classes inheriting from Game and the case where there are. I made this naive approach: class TestGame < MiniTest::Unit::TestCase def test_available_games_is_empty assert_empty GameFramework::Game.available_games end def test_available_games_has_one Class.new(GameFramework::Game) assert_equal 1, GameFramework::Game.available_games.size end end When I run these tests, the second one fails, probably is running before the other one, defining the class, I guess. Is there a good way to test these cases that I'm not seeing? Is the above strategy a good one to keep track of existing subclasses of the Game class? I am using the available games to create a menu for the user to choose which game to play. Thanks, Jesus.
From: Rein Henrichs on 10 Jun 2010 12:35 On 2010-06-10 09:30:24 -0700, Jes�s Gabriel y Gal�n said > When I run these tests, the second one fails, probably is running > before the other one, defining the class, I guess. Is there a good way > to test these cases that I'm not seeing? Is the above strategy a good > one to keep track of existing subclasses of the Game class? I am using > the available games to create a menu for the user to choose which game > to play. > > Thanks, > > Jesus. Write a method to clear your available_games array for testing and use it in the setup. -- Rein Henrichs http://puppetlabs.com http://reinh.com
From: Jesús Gabriel y Galán on 10 Jun 2010 13:16 On Thu, Jun 10, 2010 at 6:40 PM, Rein Henrichs <reinh(a)reinh.com> wrote: > On 2010-06-10 09:30:24 -0700, Jesús Gabriel y Galán said > >> When I run these tests, the second one fails, probably is running >> before the other one, defining the class, I guess. Is there a good way >> to test these cases that I'm not seeing? Is the above strategy a good >> one to keep track of existing subclasses of the Game class? I am using >> the available games to create a menu for the user to choose which game >> to play. >> >> Thanks, >> >> Jesus. > > Write a method to clear your available_games array for testing and use it in > the setup. Doh, that's pretty straightforward !!!! Thanks :-) Jesus.
From: Jesús Gabriel y Galán on 10 Jun 2010 13:17 On Thu, Jun 10, 2010 at 6:40 PM, Rein Henrichs <reinh(a)reinh.com> wrote: > On 2010-06-10 09:30:24 -0700, Jesús Gabriel y Galán said > >> When I run these tests, the second one fails, probably is running >> before the other one, defining the class, I guess. Is there a good way >> to test these cases that I'm not seeing? Is the above strategy a good >> one to keep track of existing subclasses of the Game class? I am using >> the available games to create a menu for the user to choose which game >> to play. >> >> Thanks, >> >> Jesus. > > Write a method to clear your available_games array for testing and use it in > the setup. Doh, that's pretty straightforward !!!! Thanks :-) Jesus.
|
Pages: 1 Prev: RVM Snow Leopard Next: rdoc-data 2.5.1 Released |