ImageManager.check_enable_timerspec;如何測試這個功能?
def check_enable_time
# get current time
now_time = Time.now
# UTC to JST convestion JST = UTC + 9 hours
hour = now_time.in_time_zone("Asia/Tokyo").hour
(hour != 23) ? true : false
末
該函數返回true,如果當前時間JST!= 23否則返回false。
我想測試這個功能。
我的嘗試:
describe ImageManager do
describe "Test check_enable_time() function" do
context "When current time in JST != 23" do
it 'should return true' do
image_manager = ImageManager.new
result = image_manager.check_enable_time
result.should eql(true)
end
end
end
end
如何使now_time.in_time_zone("Asia/Tokyo").hour
超過23回23等?
請幫助我是新的rails和rspec。
只是立方米rious - 爲什麼要使用'Time.now'然後在「亞洲/東京」區域轉換?你知道你可以在rails設置中設置默認的時區,然後簡單地使用'Time.current'而不用轉換? – MikDiet
對不起,我不知道。你能告訴我該怎麼做嗎? – RajSharma
您可以從http://guides.rubyonrails.org/active_support_core_extensions.html#calculations和http://guides.rubyonrails.org/configuring.html#rails-general-configuration指南 – MikDiet