How to test a method that return random values

Hi,

How can I test this method using rspec ?

def self.generate_calculation number1, number2, operation
number1 = rand(number1)
number2 = rand(number2)

end

This method return an operation with those random numbers.

Any tip ?

On Jul 6, 2010, at 1:35 PM, Guilherme wrote:

This method return an operation with those random numbers.

Any tip ?

Something like this:

OperationGenerator.stub(:rand).with(1).and_return(1)
OperationGenerator.stub(:rand).with(2).and_return(2)

expected = Addition.new(1,2)
actual = OperationGenerator.generate_calculation 1, 2, Addition

actual.should eq(expected)

HTH,
David

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs