Skip to content

Commit

Permalink
fixup! Refactor to use class consts
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Dec 11, 2019
1 parent 1dc7cf4 commit 3ad3f0a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/rspec/rails/matchers/active_job.rb
Expand Up @@ -11,9 +11,7 @@ module ActiveJob
# rubocop: disable Metrics/ClassLength
# @private
class Base < RSpec::Rails::Matchers::BaseMatcher
def initialize(verb_present_tense, verb_past_tense)
@verb_present_tense = verb_present_tense
@verb_past_tense = verb_past_tense
def initialize
@args = []
@queue = nil
@at = nil
Expand Down Expand Up @@ -69,7 +67,7 @@ def thrice
end

def failure_message
"expected to #{@verb_present_tense} #{base_message}".tap do |msg|
"expected to #{self.class::VERB_PRESENT_TENSE} #{base_message}".tap do |msg|
if @unmatching_jobs.any?
msg << "\nQueued jobs:"
@unmatching_jobs.each do |job|
Expand All @@ -80,7 +78,7 @@ def failure_message
end

def failure_message_when_negated
"expected not to #{@verb_present_tense} #{base_message}"
"expected not to #{self.class::VERB_PRESENT_TENSE} #{base_message}"
end

def message_expectation_modifier
Expand Down Expand Up @@ -121,7 +119,7 @@ def base_message
msg << " with #{@args}," if @args.any?
msg << " on queue #{@queue}," if @queue
msg << " at #{@at.inspect}," if @at
msg << " but #{@verb_past_tense} #{@matching_jobs_count}"
msg << " but #{self.class::VERB_PAST_TENSE} #{@matching_jobs_count}"
end
end

Expand Down Expand Up @@ -195,8 +193,11 @@ def queue_adapter

# @private
class HaveEnqueuedJob < Base
VERB_PRESENT_TENSE = 'enqueue'
VERB_PAST_TENSE = 'enqueued'

def initialize(job)
super("enqueue", "enqueued")
super()
@job = job
end

Expand All @@ -219,9 +220,8 @@ def does_not_match?(proc)

# @private
class HaveBeenEnqueued < Base
def initialize
super("enqueue", "enqueued")
end
VERB_PRESENT_TENSE = 'enqueue'
VERB_PAST_TENSE = 'enqueued'

def matches?(job)
@job = job
Expand All @@ -237,8 +237,11 @@ def does_not_match?(proc)

# @private
class HavePerformedJob < Base
VERB_PRESENT_TENSE = 'perform'
VERB_PAST_TENSE = 'performed'

def initialize(job)
super("perform", "performed")
super()
@job = job
end

Expand All @@ -255,9 +258,8 @@ def matches?(proc)

# @private
class HaveBeenPerformed < Base
def initialize
super("perform", "performed")
end
VERB_PRESENT_TENSE = 'perform'
VERB_PAST_TENSE = 'performed'

def matches?(job)
@job = job
Expand Down

0 comments on commit 3ad3f0a

Please sign in to comment.