human_time 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -3
- data/lib/human_time/rspec_matchers.rb +37 -0
- data/lib/human_time/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e76c8a096b55e718422e36e0c2b8ded0122fb352
|
4
|
+
data.tar.gz: e51307e3dec9173b69327a324be3ec7aa659c6a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46703899e29a8b35ed2c542dda379fcf9064cd41b3e91075caab5639990cd0048098b05a386e15c5e425e693905377f7c5feda2e9898c27fbb8ba6ef19111ff9
|
7
|
+
data.tar.gz: b56dee21a8731b58a56a9bc11abb760b4094835d40b880af5d0416a91b918f31f4c6c5ee13d16cc4bb7b4c7f2df319100ae1aea04f8ef70a7bf3219fcf58a1a4
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# human_time
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/allenan/human_time.svg?branch=master)](https://travis-ci.org/allenan/human_time)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/human_time.svg)](https://badge.fury.io/rb/human_time)
|
5
|
+
|
6
|
+
Have you ever struggled to understand what a piece of code like this is trying to say?
|
4
7
|
|
5
8
|
```ruby
|
6
9
|
some_time > another_time
|
@@ -83,6 +86,30 @@ newer_date.newer_than?(older_date)
|
|
83
86
|
- `older_than_or_equal_to?`
|
84
87
|
- `before_or_equal_to?`
|
85
88
|
|
89
|
+
## RSpec Matchers
|
90
|
+
|
91
|
+
human_time also provides RSpec matchers for more understandable time comparisons in your tests.
|
92
|
+
|
93
|
+
To use these, include the following in your `spec_helper.rb` file:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
require 'human_time/rspec_matchers'
|
97
|
+
```
|
98
|
+
|
99
|
+
And then you can use the following matchers:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
older_date = Date.parse('2016-01-01')
|
103
|
+
newer_date = Date.parse('2016-01-02')
|
104
|
+
|
105
|
+
expect(newer_date).to be_more_recent_than(older_date)
|
106
|
+
expect(newer_date).to be_newer_than(older_date)
|
107
|
+
expect(newer_date).to be_more_recent_than_or_equal_to(older_date)
|
108
|
+
expect(newer_date).to be_newer_than_or_equal_to(newer_date)
|
109
|
+
expect(older_date).to be_older_than(newer_date)
|
110
|
+
expect(older_date).to be_older_than_or_equal_to(older_date)
|
111
|
+
```
|
112
|
+
|
86
113
|
## Development
|
87
114
|
|
88
115
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -91,8 +118,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
91
118
|
|
92
119
|
## Contributing
|
93
120
|
|
94
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
95
|
-
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/allenan/human_time. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
96
122
|
|
97
123
|
## License
|
98
124
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :be_more_recent_than do |expected|
|
4
|
+
match do |actual|
|
5
|
+
actual > expected
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec::Matchers.define :be_newer_than do |expected|
|
10
|
+
match do |actual|
|
11
|
+
actual > expected
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec::Matchers.define :be_more_recent_than_or_equal_to do |expected|
|
16
|
+
match do |actual|
|
17
|
+
actual >= expected
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec::Matchers.define :be_newer_than_or_equal_to do |expected|
|
22
|
+
match do |actual|
|
23
|
+
actual >= expected
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec::Matchers.define :be_older_than do |expected|
|
28
|
+
match do |actual|
|
29
|
+
actual < expected
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
RSpec::Matchers.define :be_older_than_or_equal_to do |expected|
|
34
|
+
match do |actual|
|
35
|
+
actual <= expected
|
36
|
+
end
|
37
|
+
end
|
data/lib/human_time/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Allen
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- human_time.gemspec
|
101
101
|
- lib/human_time.rb
|
102
|
+
- lib/human_time/rspec_matchers.rb
|
102
103
|
- lib/human_time/version.rb
|
103
104
|
homepage: https://github.com/allenan/human_time
|
104
105
|
licenses:
|