Class: RuboCop::Cop::Discourse::TimeEqMatcher

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/discourse/time_eq_matcher.rb

Overview

Use ‘eq_time` matcher with timestamps in specs.

Examples:

# bad
expect(user.created_at).to eq(Time.zone.now)

# good
expect(user.created_at).to eq_time(Time.zone.now)

Constant Summary collapse

MSG =
"Use eq_time when testing timestamps"

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



31
32
33
34
35
# File 'lib/rubocop/cop/discourse/time_eq_matcher.rb', line 31

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.children.last.loc.selector, "eq_time")
  end
end

#on_send(node) ⇒ Object



25
26
27
28
29
# File 'lib/rubocop/cop/discourse/time_eq_matcher.rb', line 25

def on_send(node)
  return unless using_eq_matcher_with_timestamp?(node)

  add_offense(node, message: MSG)
end