Class: Appydays::SpecHelpers::MatchTime
- Inherits:
-
Object
- Object
- Appydays::SpecHelpers::MatchTime
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/appydays/spec_helpers.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected) ⇒ MatchTime
constructor
A new instance of MatchTime.
- #matches?(actual) ⇒ Boolean
- #time(s) ⇒ Object
- #within(tolerance) ⇒ Object
Constructor Details
#initialize(expected) ⇒ MatchTime
Returns a new instance of MatchTime.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/appydays/spec_helpers.rb', line 63 def initialize(expected) @expected = expected if expected == :now @expected_t = Time.now @tolerance = 5 else @expected_t = self.time(expected) @tolerance = 0.001 end end |
Instance Method Details
#failure_message ⇒ Object
103 104 105 |
# File 'lib/appydays/spec_helpers.rb', line 103 def return "expected %s to be within %s of %s" % [@actual_t, @tolerance, @expected_t] end |
#matches?(actual) ⇒ Boolean
81 82 83 84 85 |
# File 'lib/appydays/spec_helpers.rb', line 81 def matches?(actual) @actual_t = self.time(actual) @actual_t = self.change_tz(@actual_t, @expected_t.zone) if @actual_t return RSpec::Matchers::BuiltIn::BeWithin.new(@tolerance).of(@expected_t).matches?(@actual_t) end |
#time(s) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/appydays/spec_helpers.rb', line 74 def time(s) return nil if s.nil? return Time.parse(s) if s.is_a?(String) return Time.at(s) if s.is_a?(Numeric) return s.to_time end |
#within(tolerance) ⇒ Object
98 99 100 101 |
# File 'lib/appydays/spec_helpers.rb', line 98 def within(tolerance) @tolerance = tolerance return self end |