[rspec-users] spec'ing views, mock_model associations

Andrew WC Brown omen.king at gmail.com
Sat Oct 6 14:31:55 EDT 2007


I writing a spec that returns the count of how many players in a game:

it "should how many players in a link to all players" do
 render :partial =>"games/game", :object => @game
 response.should have_tag('a',"(2) Players")
end

I'm not sure how to do the mock model, I think it would be done two ways but
unsure of the syntax:


1: add players in

@game = mock_model(Game,
  :name => 'The Battle for Blaze',
  :salt_grains => '5000000',
  :people => '5000000',
  :days => nil,
  :created_at => "Mon Oct 01 00:02:44 -0400 2007",
  :enabled => true,
  :players => {

  })

2: assign them to players

  @game = mock_model(Game,
    :name => 'The Battle for Blaze',
    :salt_grains => '5000000',
    :people => '5000000',
    :days => nil,
    :created_at => "Mon Oct 01 00:02:44 -0400 2007",
    :enabled => true)

  player_1 = mock_model(Player, :salt_grains => '500')
  player_2 = mock_model(Player, :salt_grains => '900')

  @game.players = [ player_1, player_2 ]

How do I write this? I would need an example
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071006/053aebb6/attachment.html 


More information about the rspec-users mailing list