2013-10-10 74 views
0

我對RSPEC和Ruby非常新穎如何創建一個測試,如果數字介於0和36之間,就會通過測試?RSPEC:隨機數期望

在此先感謝。

describe "Roulette" do 
    context "Randomiser:" do 
     it 'randomises a number between 0 and 36' 
      expect(randomiser).to eq XXXX 
     end 
    end 
end 

回答

0

這很簡單。

expect(randomiser).to be > 0 
expect(randomiser).to be < 36 

randomiser.should be > 0 
randomiser.should be < 36 

乾杯,humbroll。

0

由於輪盤包括36和門牌號碼,這裏是一個人爲的例子:

describe "Roulette" do 
    it 'randomizes a number between 0 and 36' do 
    num = Random.new 
    r_num = num.rand(36) 
    r_num.should be >= 0 
    r_num.should be <= 36 
    end 
end