Guilherme
2010-Jul-06 18:35 UTC
[rspec-users] 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 ?
David Chelimsky
2010-Jul-12 01:59 UTC
[rspec-users] How to test a method that return random values
On Jul 6, 2010, at 1:35 PM, Guilherme wrote:> 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 ?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