• Stars
    star
    19
  • Rank 1,125,535 (Top 23 %)
  • Language
    Crystal
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A testing library that allows "time travel," "freezing time," and "time acceleration". Inspired by the ruby-timecop library.

timecop.cr

CI Releases License

A timecop inspired library to allow easy manipulation of time in tests. Originally authored by TobiasGSmollett.

Installation

Add this to your application's shard.yml:

dependencies:
+  timecop:
+    github: crystal-community/timecop.cr

Usage

require "timecop"

Timecop.freeze

time = Time.local(2008, 10, 10, 10, 10, 10)
Timecop.freeze(time) do |frozen_time|
  frozen_time == Time.local # => true
end

Timecop.travel

Timecop.travel(Time.local(2014, 1, 1, 0, 0, 0)) do
  Time.local # => "2014-01-01 00:00:00 +0900"
  sleep(5.seconds)
  Time.local # => "2014-01-01 00:00:05 +0900"
end

Timecop.scale

# seconds will now seem like hours
Timecop.scale(3600)

Time.local # => "2017-08-28 23:50:06 +0900"

sleep(2.seconds)
# 2 seconds later, hours have passed and it's gone from
# 23pm at night to 1am in the morning

Time.local # => "2017-08-29 01:50:21 +0900"

Timecop.safe_mode

Timecop.safe_mode? # => false
Timecop.safe_mode = true

# using method without block
Timecop.freeze Time.local(2008, 10, 10, 10, 10, 10)
# => raises Timecop::SafeModeException

Development

Pull Requests Welcome!

Contributing

  1. Fork it (https://github.com/TobiasGSmollett/timecop.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Thanks

Thanks to Travis Jeffery for his awesome work on timecop.

More Repositories

1

icr

Interactive console for Crystal programming language
Crystal
500
star
2

crystal-patterns

πŸ“– Examples of GOF patterns written in Crystal
Crystal
291
star
3

jwt

JWT implementation in Crystal
Crystal
204
star
4

crystal-libraries-needed

A list of libraries that are needed or wanted for the Crystal-Language
141
star
5

msgpack-crystal

MessagePack implementation in Crystal msgpack.org[Crystal]
Crystal
133
star
6

cossack

Simple and flexible HTTP client for Crystal with middleware and test support.
Crystal
105
star
7

hardware

Get CPU, Memory and Network informations of the running OS and its processes
Crystal
71
star
8

kiwi

A unified Crystal interface for key-value stores.
Crystal
61
star
9

toml.cr

TOML parser for Crystal
Crystal
58
star
10

zeromq-crystal

Crystal
46
star
11

crystal-ann

Web site to announce new Crystal projects, blog posts, updates and other work activities
CSS
45
star
12

leveldb

Crystal binding for LevelDB
Crystal
38
star
13

future.cr

Crystal
34
star
14

bloom_filter

Bloom filter implementation in Crystal lang
Crystal
34
star
15

crystal-kcov

Crystal
16
star
16

autolink.cr

πŸ”— Auto link for Crystal
Crystal
16
star
17

crystal-notifications

A library for notifications, this started as a port from ActiveSupport::Notifications
Crystal
16
star
18

bluetooth

Bluetooth Bluez binding in Crystal
Crystal
10
star
19

community

The crystal community
10
star
20

cr-config

An all-in-one configuration library to handle any possible configuration need
Crystal
9
star
21

snappy-crystal

Snappy bindings for Crystal
Crystal
6
star
22

cr-i18n

Crystal
3
star
23

kilt-components

Crystal
2
star