{"id":2035,"date":"2015-12-20T14:41:42","date_gmt":"2015-12-20T05:41:42","guid":{"rendered":"http:\/\/daily.belltail.jp\/?p=2035"},"modified":"2016-08-19T15:17:26","modified_gmt":"2016-08-19T06:17:26","slug":"%e5%ab%81%e3%81%ae%e9%a1%94%e5%bf%98%e3%82%8c%e3%81%a6%e3%82%82timecop-return%e3%81%af%e5%bf%98%e3%82%8c%e3%81%aa%e3%81%84%e3%81%a7%e3%81%ad%e3%81%a8%e3%81%84%e3%81%86%e8%a9%b1","status":"publish","type":"post","link":"https:\/\/daily.belltail.jp\/?p=2035","title":{"rendered":"\u5ac1\u306e\u9854\u5fd8\u308c\u3066\u3082Timecop.return\u306f\u5fd8\u308c\u306a\u3044\u3067\u306d\u3068\u3044\u3046\u8a71"},"content":{"rendered":"<p>\u591c\u91e3\u308a\u3067\u306f\u521d\u5fc3\u8005\u5411\u3051\u306e\u72d9\u3044\u76ee\u3068\u3044\u3048\u3070\u30a2\u30ca\u30b4\u306a\u3093\u3060\u305d\u3046\u3067\u3059\u3002\u5cb8\u58c1\u3067\u91e3\u308c\u3061\u3083\u3046\u3093\u3060\u3068\u304b\u3002\u30a6\u30ca\u30ae\u306f\u304a\u9ad8\u3044\u306e\u3067\u30a2\u30ca\u30b4\u3067\u4e00\u676f\u3001\u3068\u304b\u3042\u308b\u3093\u3060\u308d\u3046\u304b\u3002<br \/>\n\u3055\u3066\u3001Ruby\u3067\u3044\u308d\u3044\u308d\u958b\u767a\u3057\u3066\u3044\u3066\u6642\u9593\uff08\u6642\u523b\u30fb\u671f\u9593\u2026\uff09\u304c\u7d61\u3080\u30c6\u30b9\u30c8\u3092\u3059\u308b\u3068\u304dTimecop\u304c\u4fbf\u5229\u3067\u5e83\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<br \/>\n[https:\/\/github.com\/travisjeffery\/timecop:title=travisjeffery\/timecop \u2013 GitHub]<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\n# \u73fe\u5728\u6642\u523b\u3092\u5909\u3048\u308b\r\n&gt; Timecop.travel(Date.parse('1998\/12\/1'))\r\n=&gt; 1998-12-01 00:00:00 +0900\r\n&gt; Date.today\r\n=&gt; Tue, 01 Dec 1998\r\n \r\n# \u6642\u9593\u306e\u9032\u884c\u3092\u6b62\u3081\u308b\r\n&gt; Timecop.freeze(Time.parse('1998\/12\/1 0:00:00'))\r\n=&gt; 1998-12-01 00:00:00 +0900\r\n&gt; sleep(10)\r\n&gt; Time.now\r\n=&gt; 1998-12-01 00:00:00 +0900  # it's still 0:00:00\r\n \r\n# \u6642\u9593\u306e\u9032\u884c\u3092\u65e9\u3081\u308b\r\n&gt; Timecop.travel(Time.parse('1998\/12\/1 0:00:00'))\r\n&gt; Timecop.scale(3600)\r\n&gt; sleep(2)\r\n&gt; Time.now\r\n=&gt; 1998-12-01 02:00:19 +0900  # it took 2 hours although only slept for 2 seconds\r\n<\/pre>\n<p>\u4fbf\u5229\u3067\u3059\u306d\u3002<br \/>\n\u6642\u9593\u3092\u3044\u3058\u304f\u308b\u306e\u3067\u3001<\/p>\n<p>&#8211; \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u5468\u308a\u3092\u30df\u30b9\u3063\u3066\u306a\u3044\u304b<br \/>\n&#8211; DBMS\u306e\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3084redis\u306eexpire\u306e\u3088\u3046\u306bruby\u51e6\u7406\u7cfb\u306e\u6642\u9593\u3092\u4f7f\u308f\u306a\u3044\u3082\u306e\u3067\u306f\u52b9\u304b\u306a\u3044<br \/>\n&#8211; \u2026<br \/>\n\u3053\u3093\u306a\u304b\u3093\u3058\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u306a\u306e\u306f\u5f53\u7136\u306a\u306e\u3067\u3059\u304c\u3001\u4e00\u756a\u3057\u3093\u3069\u3044\u306e\u306fTimecop\u3067\u5909\u3048\u305f\u6642\u9593\u3092\u623b\u3057\u5fd8\u308c\u305f\u3068\u304d\u306e\u6319\u52d5\u4e0d\u5be9\u306a\u304b\u3093\u3058\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u30c6\u30b9\u30c8\u3067Timecop\u3092\u4f7f\u3046\u5834\u5408\u3001\u3053\u306e\u30c6\u306e\u30df\u30b9\u3092\u3059\u308b\u3068\u305f\u3044\u3066\u3044\u5225\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306b\u5f71\u97ff\u3057\u307e\u3059\u306d\u3002\u9806\u5e8f\u4f9d\u5b58\u3067\u52b9\u3044\u3066\u304f\u308b\u3057\u717d\u308a\u3092\u98df\u3063\u305f\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u81ea\u4f53\u306f\u4f55\u3082\u60aa\u304f\u7121\u3044\u3053\u3068\u304c\u307b\u3068\u3093\u3069\u306a\u306e\u3067\u3001\u5fc3\u795e\u8017\u5f31\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>&#8211; \u306a\u305c\u304bCapybara\u306eCookie\u304c\u53d6\u308c\u306a\u304f\u306a\u3063\u3066\u3044\u308b<br \/>\n&#8211; redis\u3067\u306f\u3046\u307e\u304f\u3044\u304f\u306e\u306bredis_mock\u3067\u30c6\u30b9\u30c8\u3059\u308b\u3068\u60f3\u5b9a\u5916\u306e\u6319\u52d5\u306b\u306a\u308b<br \/>\n&#8211; Timeout\u304c\u72c2\u3046<br \/>\n&#8211; \u2026<\/p>\n<p>\u3053\u3093\u306a\u3053\u3068\u3067\u6642\u9593\u3092\u30e0\u30c0\u306b\u3059\u308b\u306e\u306f\u3042\u307b\u3089\u3057\u3044\u306e\u3067\u3001Timecop.return\u3092\u547c\u3076\u306e\u306f\u7d76\u5bfe\u306b\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\n&gt; Timecop.travel(Time.parse('1998\/12\/1 0:00:00'))\r\n&gt; Timecop.return\r\n&gt; Date.today\r\n=&gt; Sun, 20 Dec 2015\r\n<\/pre>\n<p>\u300c\u5fd8\u308c\u306a\u3044\u3067\u306d\u300d\u300c\u6c17\u3092\u3064\u3051\u3066\u306d\u300d\u306f\u3082\u306e\u3054\u3068\u306e\u89e3\u6c7a\u7b56\u3068\u3057\u3066\u306f\u6700\u60aa\u306a\u601d\u8003\u505c\u6b62\u306a\u306e\u3067\u3001<br \/>\nRails\/RSpec\u3092\u304a\u4f7f\u3044\u306a\u3089\u3001spec\/spec_helper.rb\u306b\u3066<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\nconfig.after(:each) do\r\n  Timecop.return\r\nend\r\n<\/pre>\n<p>\u306a\u308b\u8a2d\u5b9a\u3092\u3057\u3066\u304a\u304f\u3079\u304d\u3067\u3059\u3002<br \/>\n\u307e\u305f\u3001\u5225\u306e\u5b89\u5168\u7b56\u3068\u3057\u3066\u3001Timecop\u306esafe_mode\u3068\u3044\u3044\u3001Timecop\u3092\u4f7f\u3046\u3068\u304d\u306fblock\u3092\u4e0e\u3048\u308b\u3053\u3068\u3092\u5f37\u5236\u3057\u3001block\u672b\u5c3e\u3067return\u304c\u81ea\u52d5\u3067\u884c\u308f\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u4ed5\u7d44\u307f\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\nblock\u3092\u6e21\u3055\u305a\u306b\u547c\u3076\u3068\u4f8b\u5916\u304c\u98db\u3076\u306e\u3067\u3001\u3059\u3050\u306b\u6c17\u3065\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\n&gt; Timecop.safe_mode = true\r\n&gt; Timecop.travel(Time.parse('1998\/12\/1 0:00:00'))\r\nTimecop::SafeModeException: Safe mode is enabled, only calls passing a block are allowed.\r\n...\r\n&gt; Timecop.travel(Time.parse('1998\/12\/1 0:00:00')) do\r\n&gt;   Date.today\r\n&gt; end\r\n=&gt; Tue, 01 Dec 1998\r\n&gt; Date.today\r\n=&gt; Sun, 20 Dec 2015\r\n<\/pre>\n<p>Rails\/RSpec\u306e\u307f\u3067\u4f7f\u3046\u306a\u3089\u3001spec_helper\u306eafter\u3067\u30b1\u30a2\u3059\u308b\u306e\u304c\u30b7\u30f3\u30d7\u30eb\u306b\u3057\u3066\u5b89\u5168\u5341\u5206\u304b\u3068\u3002<br \/>\n\u30c6\u30b9\u30c8\u4ee5\u5916\u3067\u3082\u4f7f\u3046\u306a\u3089\u3001safe_mode\u306b\u3059\u308b\u3088\u3046initializer\u306a\u3069\u3067\u8a2d\u5b9a\u3057\u3066\u304a\u304f\u307b\u3046\u304c\u5b89\u5168\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u5168\u90e8Github\u306b\u66f8\u3044\u3066\u3042\u308b\u3093\u3067\u3059\u3051\u3069\u3082\u30011\u30f6\u6708\u8fd1\u304f\u3053\u308c\u306b\u30cf\u30de\u3063\u3066\u3057\u307e\u3063\u305f\u81ea\u5206\u304c\u672c\u5f53\u306b\u3042\u307b\u3089\u3057\u304b\u3063\u305f\u306e\u3067\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u2026\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u591c\u91e3\u308a\u3067\u306f\u521d\u5fc3\u8005\u5411\u3051\u306e\u72d9\u3044\u76ee\u3068\u3044\u3048\u3070\u30a2\u30ca\u30b4\u306a\u3093\u3060\u305d\u3046\u3067\u3059\u3002\u5cb8\u58c1\u3067\u91e3\u308c\u3061\u3083\u3046\u3093\u3060\u3068\u304b\u3002\u30a6\u30ca\u30ae\u306f\u304a\u9ad8\u3044\u306e\u3067\u30a2\u30ca\u30b4\u3067\u4e00\u676f\u3001\u3068\u304b\u3042\u308b\u3093\u3060\u308d\u3046\u304b\u3002 \u3055\u3066\u3001Ruby\u3067\u3044\u308d\u3044\u308d\u958b\u767a\u3057\u3066\u3044\u3066\u6642\u9593\uff08\u6642\u523b\u30fb\u671f\u9593\u2026\uff09\u304c\u7d61\u3080\u30c6\u30b9\u30c8\u3092\u3059\u308b\u3068\u304dTi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[23,49],"class_list":["post-2035","post","type-post","status-publish","format-standard","hentry","category-1","tag-ruby","tag-49"],"_links":{"self":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts\/2035","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2035"}],"version-history":[{"count":0,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=\/wp\/v2\/posts\/2035\/revisions"}],"wp:attachment":[{"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daily.belltail.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}