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