Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial import.

git-svn-id: http://svn.notahat.com/time_travel/trunk@1 2d22d90e-4cf0-48bb-8127-0f41054a30bf
  • Loading branch information...
commit 2c7350ef2e8f0fcf3e7f680906a219836cd27973 0 parents
pete authored
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Peter Yandell
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 README
@@ -0,0 +1,17 @@
+= TimeTravel
+
+This lets you set the current time in your tests or specs, so you can do
+things like:
+
+ at_time("1 April 2020 2:32 UTC") do
+ # some fancy code
+ end
+
+Inside the block, Time.now will return the time you provide. The time will
+be restored to normal system time when the block exits, even if it throws
+an exception.
+
+The at_time function can take a Time object, or a string to parse into a time.
+
+TimeTravel is only loaded in the Rails test environment. If you need it in
+your development environment, just require 'time_travel'.
14 Rakefile
@@ -0,0 +1,14 @@
+require 'rake'
+require 'spec/rake/spectask'
+require 'rake/rdoctask'
+
+desc "Default: run specs"
+task :default => :spec
+
+desc "Run all the specs for the time_travel plugin."
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = ['--colour']
+ t.rcov = true
+ t.rcov_opts = ["--exclude \"spec/*,gems/*\""]
+end
251 coverage/index.html
@@ -0,0 +1,251 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><title>C0 code coverage information</title>
+ <style type='text/css'>body { background-color: rgb(240, 240, 245); }</style>
+ <style type='text/css'>span.cross-ref-title {
+ font-size: 140%;
+}
+span.cross-ref a {
+ text-decoration: none;
+}
+span.cross-ref {
+ background-color:#f3f7fa;
+ border: 1px dashed #333;
+ margin: 1em;
+ padding: 0.5em;
+ overflow: hidden;
+}
+a.crossref-toggle {
+ text-decoration: none;
+}
+span.marked0 {
+ background-color: rgb(185, 210, 200);
+ display: block;
+}
+span.marked1 {
+ background-color: rgb(190, 215, 205);
+ display: block;
+}
+span.inferred0 {
+ background-color: rgb(175, 200, 200);
+ display: block;
+}
+span.inferred1 {
+ background-color: rgb(180, 205, 205);
+ display: block;
+}
+span.uncovered0 {
+ background-color: rgb(225, 110, 110);
+ display: block;
+}
+span.uncovered1 {
+ background-color: rgb(235, 120, 120);
+ display: block;
+}
+span.overview {
+ border-bottom: 8px solid black;
+}
+div.overview {
+ border-bottom: 8px solid black;
+}
+body {
+ font-family: verdana, arial, helvetica;
+}
+div.footer {
+ font-size: 68%;
+ margin-top: 1.5em;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin-bottom: 0.5em;
+}
+h5 {
+ margin-top: 0.5em;
+}
+.hidden {
+ display: none;
+}
+div.separator {
+ height: 10px;
+}
+/* Commented out for better readability, esp. on IE */
+/*
+table tr td, table tr th {
+ font-size: 68%;
+}
+td.value table tr td {
+ font-size: 11px;
+}
+*/
+table.percent_graph {
+ height: 12px;
+ border: #808080 1px solid;
+ empty-cells: show;
+}
+table.percent_graph td.covered {
+ height: 10px;
+ background: #00f000;
+}
+table.percent_graph td.uncovered {
+ height: 10px;
+ background: #e00000;
+}
+table.percent_graph td.NA {
+ height: 10px;
+ background: #eaeaea;
+}
+table.report {
+ border-collapse: collapse;
+ width: 100%;
+}
+table.report td.heading {
+ background: #dcecff;
+ border: #d0d0d0 1px solid;
+ font-weight: bold;
+ text-align: center;
+}
+table.report td.heading:hover {
+ background: #c0ffc0;
+}
+table.report td.text {
+ border: #d0d0d0 1px solid;
+}
+table.report td.value,
+table.report td.lines_total,
+table.report td.lines_code {
+ text-align: right;
+ border: #d0d0d0 1px solid;
+}
+table.report tr.light {
+ background-color: rgb(240, 240, 245);
+}
+table.report tr.dark {
+ background-color: rgb(230, 230, 235);
+}
+</style>
+ <script type='text/javascript'>
+// <![CDATA[
+ function toggleCode( id ) {
+ if ( document.getElementById )
+ elem = document.getElementById( id );
+ else if ( document.all )
+ elem = eval( "document.all." + id );
+ else
+ return false;
+
+ elemStyle = elem.style;
+
+ if ( elemStyle.display != "block" ) {
+ elemStyle.display = "block"
+ } else {
+ elemStyle.display = "none"
+ }
+
+ return true;
+ }
+
+ // Make cross-references hidden by default
+ document.writeln( "<style type=\"text/css\">span.cross-ref { display: none }</style>" )
+ // ]]>
+</script>
+ </head>
+ <body><h3>C0 code coverage information</h3>
+ <p>Generated on Sun Mar 09 15:12:41 +1100 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
+ </p>
+ <hr/>
+ <table class='report'><thead><tr><td class='heading'>Name</td>
+ <td class='heading'>Total lines</td>
+ <td class='heading'>Lines of code</td>
+ <td class='heading'>Total coverage</td>
+ <td class='heading'>Code coverage</td>
+ </tr>
+ </thead>
+ <tbody><tr class='light'><td>TOTAL</td>
+ <td class='lines_total'><tt>43</tt>
+ </td>
+ <td class='lines_code'><tt>34</tt>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr class='dark'><td><a href='lib-time_travel_rb.html'>lib/time_travel.rb</a>
+ </td>
+ <td class='lines_total'><tt>12</tt>
+ </td>
+ <td class='lines_code'><tt>10</tt>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr class='light'><td><a href='lib-time_travel-time_extensions_rb.html'>lib/time_travel/time_extensions.rb</a>
+ </td>
+ <td class='lines_total'><tt>31</tt>
+ </td>
+ <td class='lines_code'><tt>24</tt>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+<hr/>
+ <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
+ version 0.8.1.2.</p>
+<p><a href='http://validator.w3.org/check/referer'><img src='http://www.w3.org/Icons/valid-xhtml11' height='31' alt='Valid XHTML 1.1!' width='88'/>
+ </a>
+ <a href='http://jigsaw.w3.org/css-validator/check/referer'><img src='http://jigsaw.w3.org/css-validator/images/vcss' alt='Valid CSS!' style='border:0;width:88px;height:31px'/>
+ </a>
+ </p>
+ </body>
+ </html>
640 coverage/lib-time_travel-time_extensions_rb.html
@@ -0,0 +1,640 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><title>lib/time_travel/time_extensions.rb - C0 code coverage information</title>
+ <style type='text/css'>body { background-color: rgb(240, 240, 245); }</style>
+ <style type='text/css'>span.cross-ref-title {
+ font-size: 140%;
+}
+span.cross-ref a {
+ text-decoration: none;
+}
+span.cross-ref {
+ background-color:#f3f7fa;
+ border: 1px dashed #333;
+ margin: 1em;
+ padding: 0.5em;
+ overflow: hidden;
+}
+a.crossref-toggle {
+ text-decoration: none;
+}
+span.marked0 {
+ background-color: rgb(185, 210, 200);
+ display: block;
+}
+span.marked1 {
+ background-color: rgb(190, 215, 205);
+ display: block;
+}
+span.inferred0 {
+ background-color: rgb(175, 200, 200);
+ display: block;
+}
+span.inferred1 {
+ background-color: rgb(180, 205, 205);
+ display: block;
+}
+span.uncovered0 {
+ background-color: rgb(225, 110, 110);
+ display: block;
+}
+span.uncovered1 {
+ background-color: rgb(235, 120, 120);
+ display: block;
+}
+span.overview {
+ border-bottom: 8px solid black;
+}
+div.overview {
+ border-bottom: 8px solid black;
+}
+body {
+ font-family: verdana, arial, helvetica;
+}
+div.footer {
+ font-size: 68%;
+ margin-top: 1.5em;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin-bottom: 0.5em;
+}
+h5 {
+ margin-top: 0.5em;
+}
+.hidden {
+ display: none;
+}
+div.separator {
+ height: 10px;
+}
+/* Commented out for better readability, esp. on IE */
+/*
+table tr td, table tr th {
+ font-size: 68%;
+}
+td.value table tr td {
+ font-size: 11px;
+}
+*/
+table.percent_graph {
+ height: 12px;
+ border: #808080 1px solid;
+ empty-cells: show;
+}
+table.percent_graph td.covered {
+ height: 10px;
+ background: #00f000;
+}
+table.percent_graph td.uncovered {
+ height: 10px;
+ background: #e00000;
+}
+table.percent_graph td.NA {
+ height: 10px;
+ background: #eaeaea;
+}
+table.report {
+ border-collapse: collapse;
+ width: 100%;
+}
+table.report td.heading {
+ background: #dcecff;
+ border: #d0d0d0 1px solid;
+ font-weight: bold;
+ text-align: center;
+}
+table.report td.heading:hover {
+ background: #c0ffc0;
+}
+table.report td.text {
+ border: #d0d0d0 1px solid;
+}
+table.report td.value,
+table.report td.lines_total,
+table.report td.lines_code {
+ text-align: right;
+ border: #d0d0d0 1px solid;
+}
+table.report tr.light {
+ background-color: rgb(240, 240, 245);
+}
+table.report tr.dark {
+ background-color: rgb(230, 230, 235);
+}
+</style>
+ <script type='text/javascript'>
+// <![CDATA[
+ function toggleCode( id ) {
+ if ( document.getElementById )
+ elem = document.getElementById( id );
+ else if ( document.all )
+ elem = eval( "document.all." + id );
+ else
+ return false;
+
+ elemStyle = elem.style;
+
+ if ( elemStyle.display != "block" ) {
+ elemStyle.display = "block"
+ } else {
+ elemStyle.display = "none"
+ }
+
+ return true;
+ }
+
+ // Make cross-references hidden by default
+ document.writeln( "<style type=\"text/css\">span.cross-ref { display: none }</style>" )
+ // ]]>
+</script>
+ <style type='text/css'>span.run0 {
+ background-color: rgb(178, 204, 255);
+ display: block;
+}
+span.run1 {
+ background-color: rgb(178, 206, 255);
+ display: block;
+}
+span.run2 {
+ background-color: rgb(178, 209, 255);
+ display: block;
+}
+span.run3 {
+ background-color: rgb(178, 211, 255);
+ display: block;
+}
+span.run4 {
+ background-color: rgb(178, 214, 255);
+ display: block;
+}
+span.run5 {
+ background-color: rgb(178, 218, 255);
+ display: block;
+}
+span.run6 {
+ background-color: rgb(178, 220, 255);
+ display: block;
+}
+span.run7 {
+ background-color: rgb(178, 223, 255);
+ display: block;
+}
+span.run8 {
+ background-color: rgb(178, 225, 255);
+ display: block;
+}
+span.run9 {
+ background-color: rgb(178, 228, 255);
+ display: block;
+}
+span.run10 {
+ background-color: rgb(178, 232, 255);
+ display: block;
+}
+span.run11 {
+ background-color: rgb(178, 234, 255);
+ display: block;
+}
+span.run12 {
+ background-color: rgb(178, 237, 255);
+ display: block;
+}
+span.run13 {
+ background-color: rgb(178, 239, 255);
+ display: block;
+}
+span.run14 {
+ background-color: rgb(178, 242, 255);
+ display: block;
+}
+span.run15 {
+ background-color: rgb(178, 246, 255);
+ display: block;
+}
+span.run16 {
+ background-color: rgb(178, 248, 255);
+ display: block;
+}
+span.run17 {
+ background-color: rgb(178, 251, 255);
+ display: block;
+}
+span.run18 {
+ background-color: rgb(178, 253, 255);
+ display: block;
+}
+span.run19 {
+ background-color: rgb(178, 255, 253);
+ display: block;
+}
+span.run20 {
+ background-color: rgb(178, 255, 249);
+ display: block;
+}
+span.run21 {
+ background-color: rgb(178, 255, 247);
+ display: block;
+}
+span.run22 {
+ background-color: rgb(178, 255, 244);
+ display: block;
+}
+span.run23 {
+ background-color: rgb(178, 255, 242);
+ display: block;
+}
+span.run24 {
+ background-color: rgb(178, 255, 239);
+ display: block;
+}
+span.run25 {
+ background-color: rgb(178, 255, 235);
+ display: block;
+}
+span.run26 {
+ background-color: rgb(178, 255, 233);
+ display: block;
+}
+span.run27 {
+ background-color: rgb(178, 255, 230);
+ display: block;
+}
+span.run28 {
+ background-color: rgb(178, 255, 228);
+ display: block;
+}
+span.run29 {
+ background-color: rgb(178, 255, 225);
+ display: block;
+}
+span.run30 {
+ background-color: rgb(178, 255, 221);
+ display: block;
+}
+span.run31 {
+ background-color: rgb(178, 255, 219);
+ display: block;
+}
+span.run32 {
+ background-color: rgb(178, 255, 216);
+ display: block;
+}
+span.run33 {
+ background-color: rgb(178, 255, 214);
+ display: block;
+}
+span.run34 {
+ background-color: rgb(178, 255, 211);
+ display: block;
+}
+span.run35 {
+ background-color: rgb(178, 255, 207);
+ display: block;
+}
+span.run36 {
+ background-color: rgb(178, 255, 205);
+ display: block;
+}
+span.run37 {
+ background-color: rgb(178, 255, 202);
+ display: block;
+}
+span.run38 {
+ background-color: rgb(178, 255, 200);
+ display: block;
+}
+span.run39 {
+ background-color: rgb(178, 255, 197);
+ display: block;
+}
+span.run40 {
+ background-color: rgb(178, 255, 193);
+ display: block;
+}
+span.run41 {
+ background-color: rgb(178, 255, 191);
+ display: block;
+}
+span.run42 {
+ background-color: rgb(178, 255, 188);
+ display: block;
+}
+span.run43 {
+ background-color: rgb(178, 255, 186);
+ display: block;
+}
+span.run44 {
+ background-color: rgb(178, 255, 183);
+ display: block;
+}
+span.run45 {
+ background-color: rgb(178, 255, 179);
+ display: block;
+}
+span.run46 {
+ background-color: rgb(179, 255, 178);
+ display: block;
+}
+span.run47 {
+ background-color: rgb(182, 255, 178);
+ display: block;
+}
+span.run48 {
+ background-color: rgb(184, 255, 178);
+ display: block;
+}
+span.run49 {
+ background-color: rgb(187, 255, 178);
+ display: block;
+}
+span.run50 {
+ background-color: rgb(191, 255, 178);
+ display: block;
+}
+span.run51 {
+ background-color: rgb(193, 255, 178);
+ display: block;
+}
+span.run52 {
+ background-color: rgb(196, 255, 178);
+ display: block;
+}
+span.run53 {
+ background-color: rgb(198, 255, 178);
+ display: block;
+}
+span.run54 {
+ background-color: rgb(201, 255, 178);
+ display: block;
+}
+span.run55 {
+ background-color: rgb(205, 255, 178);
+ display: block;
+}
+span.run56 {
+ background-color: rgb(207, 255, 178);
+ display: block;
+}
+span.run57 {
+ background-color: rgb(210, 255, 178);
+ display: block;
+}
+span.run58 {
+ background-color: rgb(212, 255, 178);
+ display: block;
+}
+span.run59 {
+ background-color: rgb(215, 255, 178);
+ display: block;
+}
+span.run60 {
+ background-color: rgb(219, 255, 178);
+ display: block;
+}
+span.run61 {
+ background-color: rgb(221, 255, 178);
+ display: block;
+}
+span.run62 {
+ background-color: rgb(224, 255, 178);
+ display: block;
+}
+span.run63 {
+ background-color: rgb(226, 255, 178);
+ display: block;
+}
+span.run64 {
+ background-color: rgb(229, 255, 178);
+ display: block;
+}
+span.run65 {
+ background-color: rgb(233, 255, 178);
+ display: block;
+}
+span.run66 {
+ background-color: rgb(235, 255, 178);
+ display: block;
+}
+span.run67 {
+ background-color: rgb(238, 255, 178);
+ display: block;
+}
+span.run68 {
+ background-color: rgb(240, 255, 178);
+ display: block;
+}
+span.run69 {
+ background-color: rgb(243, 255, 178);
+ display: block;
+}
+span.run70 {
+ background-color: rgb(247, 255, 178);
+ display: block;
+}
+span.run71 {
+ background-color: rgb(249, 255, 178);
+ display: block;
+}
+span.run72 {
+ background-color: rgb(252, 255, 178);
+ display: block;
+}
+span.run73 {
+ background-color: rgb(255, 255, 178);
+ display: block;
+}
+span.run74 {
+ background-color: rgb(255, 252, 178);
+ display: block;
+}
+span.run75 {
+ background-color: rgb(255, 248, 178);
+ display: block;
+}
+span.run76 {
+ background-color: rgb(255, 246, 178);
+ display: block;
+}
+span.run77 {
+ background-color: rgb(255, 243, 178);
+ display: block;
+}
+span.run78 {
+ background-color: rgb(255, 240, 178);
+ display: block;
+}
+span.run79 {
+ background-color: rgb(255, 238, 178);
+ display: block;
+}
+span.run80 {
+ background-color: rgb(255, 234, 178);
+ display: block;
+}
+span.run81 {
+ background-color: rgb(255, 232, 178);
+ display: block;
+}
+span.run82 {
+ background-color: rgb(255, 229, 178);
+ display: block;
+}
+span.run83 {
+ background-color: rgb(255, 226, 178);
+ display: block;
+}
+span.run84 {
+ background-color: rgb(255, 224, 178);
+ display: block;
+}
+span.run85 {
+ background-color: rgb(255, 220, 178);
+ display: block;
+}
+span.run86 {
+ background-color: rgb(255, 218, 178);
+ display: block;
+}
+span.run87 {
+ background-color: rgb(255, 215, 178);
+ display: block;
+}
+span.run88 {
+ background-color: rgb(255, 212, 178);
+ display: block;
+}
+span.run89 {
+ background-color: rgb(255, 210, 178);
+ display: block;
+}
+span.run90 {
+ background-color: rgb(255, 206, 178);
+ display: block;
+}
+span.run91 {
+ background-color: rgb(255, 204, 178);
+ display: block;
+}
+span.run92 {
+ background-color: rgb(255, 201, 178);
+ display: block;
+}
+span.run93 {
+ background-color: rgb(255, 198, 178);
+ display: block;
+}
+span.run94 {
+ background-color: rgb(255, 196, 178);
+ display: block;
+}
+span.run95 {
+ background-color: rgb(255, 192, 178);
+ display: block;
+}
+span.run96 {
+ background-color: rgb(255, 189, 178);
+ display: block;
+}
+span.run97 {
+ background-color: rgb(255, 187, 178);
+ display: block;
+}
+span.run98 {
+ background-color: rgb(255, 184, 178);
+ display: block;
+}
+span.run99 {
+ background-color: rgb(255, 182, 178);
+ display: block;
+}
+span.run100 {
+ background-color: rgb(255, 178, 178);
+ display: block;
+}
+</style>
+ </head>
+ <body><h3>C0 code coverage information</h3>
+ <p>Generated on Sun Mar 09 15:12:41 +1100 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
+ </p>
+ <hr/>
+ <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
+</span><span class='marked1'>and this: this line is also marked as covered.
+</span><span class='inferred0'>Lines considered as run by rcov, but not reported by Ruby, look like this,
+</span><span class='inferred1'>and this: these lines were inferred by rcov (using simple heuristics).
+</span><span class='uncovered0'>Finally, here&apos;s a line marked as not executed.
+</span></pre>
+<table class='report'><thead><tr><td class='heading'>Name</td>
+ <td class='heading'>Total lines</td>
+ <td class='heading'>Lines of code</td>
+ <td class='heading'>Total coverage</td>
+ <td class='heading'>Code coverage</td>
+ </tr>
+ </thead>
+ <tbody><tr class='light'><td><a href='lib-time_travel-time_extensions_rb.html'>lib/time_travel/time_extensions.rb</a>
+ </td>
+ <td class='lines_total'><tt>31</tt>
+ </td>
+ <td class='lines_code'><tt>24</tt>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+<pre><span class="marked1"><a name="line1"></a> 1 require 'time'
+</span><span class="inferred0"><a name="line2"></a> 2
+</span><span class="marked1"><a name="line3"></a> 3 module TimeTravel
+</span><span class="marked0"><a name="line4"></a> 4 module TimeExtensions
+</span><span class="inferred1"><a name="line5"></a> 5
+</span><span class="marked0"><a name="line6"></a> 6 def self.included(base)
+</span><span class="marked1"><a name="line7"></a> 7 base.extend(ClassMethods)
+</span><span class="marked0"><a name="line8"></a> 8 base.class_eval do
+</span><span class="marked1"><a name="line9"></a> 9 class &lt;&lt; self
+</span><span class="marked0"><a name="line10"></a>10 alias_method :immutable_now, :now
+</span><span class="marked1"><a name="line11"></a>11 alias_method :now, :mutable_now
+</span><span class="inferred0"><a name="line12"></a>12 end
+</span><span class="inferred1"><a name="line13"></a>13 end
+</span><span class="marked0"><a name="line14"></a>14 base.now = nil
+</span><span class="inferred1"><a name="line15"></a>15 end
+</span><span class="inferred0"><a name="line16"></a>16
+</span><span class="marked1"><a name="line17"></a>17 module ClassMethods
+</span><span class="inferred0"><a name="line18"></a>18
+</span><span class="marked1"><a name="line19"></a>19 def now=(time)
+</span><span class="marked0"><a name="line20"></a>20 time = Time.parse(time) if time.instance_of?(String)
+</span><span class="marked1"><a name="line21"></a>21 @@now = time
+</span><span class="inferred0"><a name="line22"></a>22 end
+</span><span class="inferred1"><a name="line23"></a>23
+</span><span class="marked0"><a name="line24"></a>24 def mutable_now #:nodoc:
+</span><span class="marked1"><a name="line25"></a>25 @@now || immutable_now
+</span><span class="marked0"><a name="line26"></a>26 end
+</span><span class="inferred1"><a name="line27"></a>27
+</span><span class="inferred0"><a name="line28"></a>28 end
+</span><span class="inferred1"><a name="line29"></a>29
+</span><span class="inferred0"><a name="line30"></a>30 end
+</span><span class="inferred1"><a name="line31"></a>31 end
+</span></pre><hr/>
+ <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
+ version 0.8.1.2.</p>
+<p><a href='http://validator.w3.org/check/referer'><img src='http://www.w3.org/Icons/valid-xhtml10' height='31' alt='Valid XHTML 1.0!' width='88'/>
+ </a>
+ <a href='http://jigsaw.w3.org/css-validator/check/referer'><img src='http://jigsaw.w3.org/css-validator/images/vcss' alt='Valid CSS!' style='border:0;width:88px;height:31px'/>
+ </a>
+ </p>
+ </body>
+ </html>
621 coverage/lib-time_travel_rb.html
@@ -0,0 +1,621 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><title>lib/time_travel.rb - C0 code coverage information</title>
+ <style type='text/css'>body { background-color: rgb(240, 240, 245); }</style>
+ <style type='text/css'>span.cross-ref-title {
+ font-size: 140%;
+}
+span.cross-ref a {
+ text-decoration: none;
+}
+span.cross-ref {
+ background-color:#f3f7fa;
+ border: 1px dashed #333;
+ margin: 1em;
+ padding: 0.5em;
+ overflow: hidden;
+}
+a.crossref-toggle {
+ text-decoration: none;
+}
+span.marked0 {
+ background-color: rgb(185, 210, 200);
+ display: block;
+}
+span.marked1 {
+ background-color: rgb(190, 215, 205);
+ display: block;
+}
+span.inferred0 {
+ background-color: rgb(175, 200, 200);
+ display: block;
+}
+span.inferred1 {
+ background-color: rgb(180, 205, 205);
+ display: block;
+}
+span.uncovered0 {
+ background-color: rgb(225, 110, 110);
+ display: block;
+}
+span.uncovered1 {
+ background-color: rgb(235, 120, 120);
+ display: block;
+}
+span.overview {
+ border-bottom: 8px solid black;
+}
+div.overview {
+ border-bottom: 8px solid black;
+}
+body {
+ font-family: verdana, arial, helvetica;
+}
+div.footer {
+ font-size: 68%;
+ margin-top: 1.5em;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin-bottom: 0.5em;
+}
+h5 {
+ margin-top: 0.5em;
+}
+.hidden {
+ display: none;
+}
+div.separator {
+ height: 10px;
+}
+/* Commented out for better readability, esp. on IE */
+/*
+table tr td, table tr th {
+ font-size: 68%;
+}
+td.value table tr td {
+ font-size: 11px;
+}
+*/
+table.percent_graph {
+ height: 12px;
+ border: #808080 1px solid;
+ empty-cells: show;
+}
+table.percent_graph td.covered {
+ height: 10px;
+ background: #00f000;
+}
+table.percent_graph td.uncovered {
+ height: 10px;
+ background: #e00000;
+}
+table.percent_graph td.NA {
+ height: 10px;
+ background: #eaeaea;
+}
+table.report {
+ border-collapse: collapse;
+ width: 100%;
+}
+table.report td.heading {
+ background: #dcecff;
+ border: #d0d0d0 1px solid;
+ font-weight: bold;
+ text-align: center;
+}
+table.report td.heading:hover {
+ background: #c0ffc0;
+}
+table.report td.text {
+ border: #d0d0d0 1px solid;
+}
+table.report td.value,
+table.report td.lines_total,
+table.report td.lines_code {
+ text-align: right;
+ border: #d0d0d0 1px solid;
+}
+table.report tr.light {
+ background-color: rgb(240, 240, 245);
+}
+table.report tr.dark {
+ background-color: rgb(230, 230, 235);
+}
+</style>
+ <script type='text/javascript'>
+// <![CDATA[
+ function toggleCode( id ) {
+ if ( document.getElementById )
+ elem = document.getElementById( id );
+ else if ( document.all )
+ elem = eval( "document.all." + id );
+ else
+ return false;
+
+ elemStyle = elem.style;
+
+ if ( elemStyle.display != "block" ) {
+ elemStyle.display = "block"
+ } else {
+ elemStyle.display = "none"
+ }
+
+ return true;
+ }
+
+ // Make cross-references hidden by default
+ document.writeln( "<style type=\"text/css\">span.cross-ref { display: none }</style>" )
+ // ]]>
+</script>
+ <style type='text/css'>span.run0 {
+ background-color: rgb(178, 204, 255);
+ display: block;
+}
+span.run1 {
+ background-color: rgb(178, 206, 255);
+ display: block;
+}
+span.run2 {
+ background-color: rgb(178, 209, 255);
+ display: block;
+}
+span.run3 {
+ background-color: rgb(178, 211, 255);
+ display: block;
+}
+span.run4 {
+ background-color: rgb(178, 214, 255);
+ display: block;
+}
+span.run5 {
+ background-color: rgb(178, 218, 255);
+ display: block;
+}
+span.run6 {
+ background-color: rgb(178, 220, 255);
+ display: block;
+}
+span.run7 {
+ background-color: rgb(178, 223, 255);
+ display: block;
+}
+span.run8 {
+ background-color: rgb(178, 225, 255);
+ display: block;
+}
+span.run9 {
+ background-color: rgb(178, 228, 255);
+ display: block;
+}
+span.run10 {
+ background-color: rgb(178, 232, 255);
+ display: block;
+}
+span.run11 {
+ background-color: rgb(178, 234, 255);
+ display: block;
+}
+span.run12 {
+ background-color: rgb(178, 237, 255);
+ display: block;
+}
+span.run13 {
+ background-color: rgb(178, 239, 255);
+ display: block;
+}
+span.run14 {
+ background-color: rgb(178, 242, 255);
+ display: block;
+}
+span.run15 {
+ background-color: rgb(178, 246, 255);
+ display: block;
+}
+span.run16 {
+ background-color: rgb(178, 248, 255);
+ display: block;
+}
+span.run17 {
+ background-color: rgb(178, 251, 255);
+ display: block;
+}
+span.run18 {
+ background-color: rgb(178, 253, 255);
+ display: block;
+}
+span.run19 {
+ background-color: rgb(178, 255, 253);
+ display: block;
+}
+span.run20 {
+ background-color: rgb(178, 255, 249);
+ display: block;
+}
+span.run21 {
+ background-color: rgb(178, 255, 247);
+ display: block;
+}
+span.run22 {
+ background-color: rgb(178, 255, 244);
+ display: block;
+}
+span.run23 {
+ background-color: rgb(178, 255, 242);
+ display: block;
+}
+span.run24 {
+ background-color: rgb(178, 255, 239);
+ display: block;
+}
+span.run25 {
+ background-color: rgb(178, 255, 235);
+ display: block;
+}
+span.run26 {
+ background-color: rgb(178, 255, 233);
+ display: block;
+}
+span.run27 {
+ background-color: rgb(178, 255, 230);
+ display: block;
+}
+span.run28 {
+ background-color: rgb(178, 255, 228);
+ display: block;
+}
+span.run29 {
+ background-color: rgb(178, 255, 225);
+ display: block;
+}
+span.run30 {
+ background-color: rgb(178, 255, 221);
+ display: block;
+}
+span.run31 {
+ background-color: rgb(178, 255, 219);
+ display: block;
+}
+span.run32 {
+ background-color: rgb(178, 255, 216);
+ display: block;
+}
+span.run33 {
+ background-color: rgb(178, 255, 214);
+ display: block;
+}
+span.run34 {
+ background-color: rgb(178, 255, 211);
+ display: block;
+}
+span.run35 {
+ background-color: rgb(178, 255, 207);
+ display: block;
+}
+span.run36 {
+ background-color: rgb(178, 255, 205);
+ display: block;
+}
+span.run37 {
+ background-color: rgb(178, 255, 202);
+ display: block;
+}
+span.run38 {
+ background-color: rgb(178, 255, 200);
+ display: block;
+}
+span.run39 {
+ background-color: rgb(178, 255, 197);
+ display: block;
+}
+span.run40 {
+ background-color: rgb(178, 255, 193);
+ display: block;
+}
+span.run41 {
+ background-color: rgb(178, 255, 191);
+ display: block;
+}
+span.run42 {
+ background-color: rgb(178, 255, 188);
+ display: block;
+}
+span.run43 {
+ background-color: rgb(178, 255, 186);
+ display: block;
+}
+span.run44 {
+ background-color: rgb(178, 255, 183);
+ display: block;
+}
+span.run45 {
+ background-color: rgb(178, 255, 179);
+ display: block;
+}
+span.run46 {
+ background-color: rgb(179, 255, 178);
+ display: block;
+}
+span.run47 {
+ background-color: rgb(182, 255, 178);
+ display: block;
+}
+span.run48 {
+ background-color: rgb(184, 255, 178);
+ display: block;
+}
+span.run49 {
+ background-color: rgb(187, 255, 178);
+ display: block;
+}
+span.run50 {
+ background-color: rgb(191, 255, 178);
+ display: block;
+}
+span.run51 {
+ background-color: rgb(193, 255, 178);
+ display: block;
+}
+span.run52 {
+ background-color: rgb(196, 255, 178);
+ display: block;
+}
+span.run53 {
+ background-color: rgb(198, 255, 178);
+ display: block;
+}
+span.run54 {
+ background-color: rgb(201, 255, 178);
+ display: block;
+}
+span.run55 {
+ background-color: rgb(205, 255, 178);
+ display: block;
+}
+span.run56 {
+ background-color: rgb(207, 255, 178);
+ display: block;
+}
+span.run57 {
+ background-color: rgb(210, 255, 178);
+ display: block;
+}
+span.run58 {
+ background-color: rgb(212, 255, 178);
+ display: block;
+}
+span.run59 {
+ background-color: rgb(215, 255, 178);
+ display: block;
+}
+span.run60 {
+ background-color: rgb(219, 255, 178);
+ display: block;
+}
+span.run61 {
+ background-color: rgb(221, 255, 178);
+ display: block;
+}
+span.run62 {
+ background-color: rgb(224, 255, 178);
+ display: block;
+}
+span.run63 {
+ background-color: rgb(226, 255, 178);
+ display: block;
+}
+span.run64 {
+ background-color: rgb(229, 255, 178);
+ display: block;
+}
+span.run65 {
+ background-color: rgb(233, 255, 178);
+ display: block;
+}
+span.run66 {
+ background-color: rgb(235, 255, 178);
+ display: block;
+}
+span.run67 {
+ background-color: rgb(238, 255, 178);
+ display: block;
+}
+span.run68 {
+ background-color: rgb(240, 255, 178);
+ display: block;
+}
+span.run69 {
+ background-color: rgb(243, 255, 178);
+ display: block;
+}
+span.run70 {
+ background-color: rgb(247, 255, 178);
+ display: block;
+}
+span.run71 {
+ background-color: rgb(249, 255, 178);
+ display: block;
+}
+span.run72 {
+ background-color: rgb(252, 255, 178);
+ display: block;
+}
+span.run73 {
+ background-color: rgb(255, 255, 178);
+ display: block;
+}
+span.run74 {
+ background-color: rgb(255, 252, 178);
+ display: block;
+}
+span.run75 {
+ background-color: rgb(255, 248, 178);
+ display: block;
+}
+span.run76 {
+ background-color: rgb(255, 246, 178);
+ display: block;
+}
+span.run77 {
+ background-color: rgb(255, 243, 178);
+ display: block;
+}
+span.run78 {
+ background-color: rgb(255, 240, 178);
+ display: block;
+}
+span.run79 {
+ background-color: rgb(255, 238, 178);
+ display: block;
+}
+span.run80 {
+ background-color: rgb(255, 234, 178);
+ display: block;
+}
+span.run81 {
+ background-color: rgb(255, 232, 178);
+ display: block;
+}
+span.run82 {
+ background-color: rgb(255, 229, 178);
+ display: block;
+}
+span.run83 {
+ background-color: rgb(255, 226, 178);
+ display: block;
+}
+span.run84 {
+ background-color: rgb(255, 224, 178);
+ display: block;
+}
+span.run85 {
+ background-color: rgb(255, 220, 178);
+ display: block;
+}
+span.run86 {
+ background-color: rgb(255, 218, 178);
+ display: block;
+}
+span.run87 {
+ background-color: rgb(255, 215, 178);
+ display: block;
+}
+span.run88 {
+ background-color: rgb(255, 212, 178);
+ display: block;
+}
+span.run89 {
+ background-color: rgb(255, 210, 178);
+ display: block;
+}
+span.run90 {
+ background-color: rgb(255, 206, 178);
+ display: block;
+}
+span.run91 {
+ background-color: rgb(255, 204, 178);
+ display: block;
+}
+span.run92 {
+ background-color: rgb(255, 201, 178);
+ display: block;
+}
+span.run93 {
+ background-color: rgb(255, 198, 178);
+ display: block;
+}
+span.run94 {
+ background-color: rgb(255, 196, 178);
+ display: block;
+}
+span.run95 {
+ background-color: rgb(255, 192, 178);
+ display: block;
+}
+span.run96 {
+ background-color: rgb(255, 189, 178);
+ display: block;
+}
+span.run97 {
+ background-color: rgb(255, 187, 178);
+ display: block;
+}
+span.run98 {
+ background-color: rgb(255, 184, 178);
+ display: block;
+}
+span.run99 {
+ background-color: rgb(255, 182, 178);
+ display: block;
+}
+span.run100 {
+ background-color: rgb(255, 178, 178);
+ display: block;
+}
+</style>
+ </head>
+ <body><h3>C0 code coverage information</h3>
+ <p>Generated on Sun Mar 09 15:12:41 +1100 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
+ </p>
+ <hr/>
+ <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
+</span><span class='marked1'>and this: this line is also marked as covered.
+</span><span class='inferred0'>Lines considered as run by rcov, but not reported by Ruby, look like this,
+</span><span class='inferred1'>and this: these lines were inferred by rcov (using simple heuristics).
+</span><span class='uncovered0'>Finally, here&apos;s a line marked as not executed.
+</span></pre>
+<table class='report'><thead><tr><td class='heading'>Name</td>
+ <td class='heading'>Total lines</td>
+ <td class='heading'>Lines of code</td>
+ <td class='heading'>Total coverage</td>
+ <td class='heading'>Code coverage</td>
+ </tr>
+ </thead>
+ <tbody><tr class='light'><td><a href='lib-time_travel_rb.html'>lib/time_travel.rb</a>
+ </td>
+ <td class='lines_total'><tt>12</tt>
+ </td>
+ <td class='lines_code'><tt>10</tt>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>100.0%</tt>
+ &nbsp;</td>
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='100'/>
+ <td class='uncovered' width='0'/>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+<pre><span class="marked1"><a name="line1"></a> 1 require 'time_travel/time_extensions'
+</span><span class="inferred0"><a name="line2"></a> 2
+</span><span class="marked1"><a name="line3"></a> 3 Time.send(:include, TimeTravel::TimeExtensions)
+</span><span class="inferred0"><a name="line4"></a> 4
+</span><span class="marked1"><a name="line5"></a> 5 def at_time(time)
+</span><span class="marked0"><a name="line6"></a> 6 Time.now = time
+</span><span class="marked1"><a name="line7"></a> 7 begin
+</span><span class="marked0"><a name="line8"></a> 8 yield
+</span><span class="inferred1"><a name="line9"></a> 9 ensure
+</span><span class="marked0"><a name="line10"></a>10 Time.now = nil
+</span><span class="inferred1"><a name="line11"></a>11 end
+</span><span class="inferred0"><a name="line12"></a>12 end
+</span></pre><hr/>
+ <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
+ version 0.8.1.2.</p>
+<p><a href='http://validator.w3.org/check/referer'><img src='http://www.w3.org/Icons/valid-xhtml10' height='31' alt='Valid XHTML 1.0!' width='88'/>
+ </a>
+ <a href='http://jigsaw.w3.org/css-validator/check/referer'><img src='http://jigsaw.w3.org/css-validator/images/vcss' alt='Valid CSS!' style='border:0;width:88px;height:31px'/>
+ </a>
+ </p>
+ </body>
+ </html>
1  init.rb
@@ -0,0 +1 @@
+require 'time_travel' if ENV["RAILS_ENV"] == "test"
12 lib/time_travel.rb
@@ -0,0 +1,12 @@
+require 'time_travel/time_extensions'
+
+Time.send(:include, TimeTravel::TimeExtensions)
+
+def at_time(time)
+ Time.now = time
+ begin
+ yield
+ ensure
+ Time.now = nil
+ end
+end
31 lib/time_travel/time_extensions.rb
@@ -0,0 +1,31 @@
+require 'time'
+
+module TimeTravel
+ module TimeExtensions
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ base.class_eval do
+ class << self
+ alias_method :immutable_now, :now
+ alias_method :now, :mutable_now
+ end
+ end
+ base.now = nil
+ end
+
+ module ClassMethods
+
+ def now=(time)
+ time = Time.parse(time) if time.instance_of?(String)
+ @@now = time
+ end
+
+ def mutable_now #:nodoc:
+ @@now || immutable_now
+ end
+
+ end
+
+ end
+end
62 spec/time_travel_spec.rb
@@ -0,0 +1,62 @@
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
+require 'time_travel'
+require 'time'
+
+describe TimeTravel, "assigning to Time.now" do
+
+ before do
+ @future = Time.parse("1 April 2020")
+ end
+
+ it "should set the time" do
+ Time.now = @future
+ Time.now.should == @future
+ end
+
+ it "should return time to system time assigning nil" do
+ Time.now = @future
+ Time.now = nil
+ Time.now.should_not be_nil
+ Time.now.should_not == @future
+ end
+
+ it "should accept a string" do
+ Time.now = "1 April 2020"
+ Time.now.should == Time.parse("1 April 2020")
+ end
+
+ after do
+ Time.now = nil
+ end
+
+end
+
+describe TimeTravel, "at_time method" do
+
+ before do
+ @future = Time.parse("1 April 2020")
+ end
+
+ it "should change the time within the block" do
+ at_time(@future) do
+ Time.now.should == @future
+ end
+ end
+
+ it "should restore the system time after the block" do
+ at_time(@future) do
+ end
+ Time.now.should_not == @future
+ end
+
+ it "should restore the system time after an exception" do
+ begin
+ at_time(@future) do
+ raise "Uh oh"
+ end
+ rescue
+ end
+ Time.now.should_not == @future
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.