Q:

How to set variables inside a mocha test

I am having trouble understanding how to set variables for use in my tests.  For example I have a function called spark.isTriple() that takes a number and looks at an array called dice and returns true if the value occurs three or more times or false if it doesn't. 
#In game.coffee

window.spark =  
  isTriple: (n)->        
    triples = _.filter dice, (i)->
      n is i
    if triples.length >= 3
      true
    else
      false

And I have a test that looks like this. 
# In game_spec.coffee

describe 'spark.isTriple', ->
  it "Should return true if the given value is found 3 or more times in the dice roll", ->
    dice = [1,2,2,2,4,5]
    spark.isTriple(2).should.be.true

The problem is that 'dice' is also being set in an earlier test that is actually testing a rollDice() function.  In that test dice is being set to a random array of values which is what it should be doing and testing.  But for this particular test I want to be able to set 'dice' to a specific array in order to test my isTriple() function.  I've tried placing the "dice = [1,2,2,2,3,4]" in a before() call and a beforeEach() call but it doesn't seem to make any difference. 
If anyone can give me some help or pointers on this it would be much appreciated. 

A:

I'm gonna disagree with Peter here.  I think depending on a variable across tests is a bad idea -- it sets you up for intermittent and weird failures in tests.  Anything that's going to change as a result of the test should be contained only in that test.  To that end, I'd write your re-write your code like so (from the coffee console): 
window.spark = hasTriple: (dice, n) ->
  ld.filter(dice, ((i) -> n is i)).length >= 3 
{ hasTriple: [Function] }
coffee> window.spark.hasTriple([1,2,1,2,5,6], 2) 
false
coffee> window.spark.hasTriple([1,2,2,2,5,6], 2) 
true

I renamed _ to ld (aka Lodash) because _ has a special meaning in the console so I think it's a good practice to avoid using it. 