Module: Appydays::SpecHelpers

Defined in:
lib/appydays/spec_helpers.rb

Defined Under Namespace

Classes: HaveALineMatching, MatchTime

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.have_a_line_matching(regexp) ⇒ Object

RSpec matcher – set up the expectation that the lefthand side is Enumerable, and that at least one of the objects yielded while iterating matches regexp when converted to a String.



52
53
54
# File 'lib/appydays/spec_helpers.rb', line 52

module_function def have_a_line_matching(regexp)
  return HaveALineMatching.new(regexp)
end

.have_length(x) ⇒ Object



56
57
58
# File 'lib/appydays/spec_helpers.rb', line 56

module_function def have_length(x)
  return RSpec::Matchers::BuiltIn::HaveAttributes.new(length: x)
end

.trunc_time(t) ⇒ Object

Zero out nsecs to t can be compared to one from the database.



13
14
15
# File 'lib/appydays/spec_helpers.rb', line 13

module_function def trunc_time(t)
  return t.change(nsec: t.usec * 1000)
end

Instance Method Details

#match_time(expected) ⇒ Object

Matcher that will compare a string or time expected against a string or time actual, within a tolerance (default to 1 millisecond).

Use match_time(:now) to automatically ‘match_time(Time.now).within(5.seconds)`.

expect(last_response).to have_json_body.that_includes(
    closes_at: match_time('2025-12-01T00:00:00.000+00:00').within(1.second))


116
117
118
# File 'lib/appydays/spec_helpers.rb', line 116

def match_time(expected)
  return MatchTime.new(expected)
end