Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9245153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:12:04+00:00 2026-06-18T09:12:04+00:00

How would you test this class? Would you integrate it with Resque and check

  • 0

How would you test this class? Would you integrate it with Resque and check that the job gets put in the queue or would you mock it, and if you would mock it how would you avoid just duplicating the code like shown in example spec.

class BookingReminderEnqueuer
  def initialize(user, booking, worker = BookingReminder)
    @user, @booking, @worker = user, booking, worker
  end

  def enqueue
    Resque.enqueue_at(
      remind_user_at,
      @worker,
      booking_id: @booking.id,
      user_id: @user.id
    ) if @booking.remind_user?
  end

  private
  def remind_user_at
    @booking.start_time - 6.hours
  end
end

require 'spec_helper'
describe BookingReminderEnqueuer
  describe "#enqueue" do
    context "when the user should have a reminder" do
      it "enqueues the reminder" do
        booking.stub(:remind_user?) { true }
        Resque.should_receive(:enqueue_at).with(
          booking.start_time - 6.hours,
          BookingReminder,
          booking_id: booking.id,
          user_id: user.id
        ).once
        booking_reminder_enqueuer.enqueue
      end
    end

    context "when the user shouldn't have a reminder" do
      it "does not enqueue the reminder" do
        booking.stub(:remind_user?) { false }
        Resque.should_not_receive(:enqueue_at)
      end
    end
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:12:06+00:00Added an answer on June 18, 2026 at 9:12 am

    I would use a gem like fakeredis to create a test redis db. This will create an isolated in-memory Redis instance for testing that can be cleared around test runs. Then you can verify that the job is enqueued properly with the right parameters vs. mocking the enqueue method (since getting the enqueue parameters to work properly is the heart of this method.

        # Gemfile
        group :test do
          gem "rspec"
          gem "fakeredis", :require => "fakeredis/rspec"
        end
    
    
        # Spec
        describe BookingReminderEnqueuer
          describe "#enqueue" do
            context "when the user should have a reminder" do
              it "enqueues the reminder" do
                booking.stub(:remind_user?) { true }
                booking_reminder_enqueuer.enqueue
                resque_job = Resque.peek(:queue_name)
                resque_job.should be_present
                # add assertions about job content/scheduling here
              end
            end
            ...
         end
       end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an example XML file that would come from the Android Client. <test>
So I have installed pymox and I would like to test this method: class
Let's say that I have this class case class Test (id: Long, name: String)
How would you test this scenario? I've just started looking into NHibernate and having
We are running a test automation suite and would like to prevent this message
Can anyone tell me why this code would not be working? $('body').on('test', function() {
I have this: $(document).ready(function() { $(input[type=button]).click(function () { $(#test).html(W3Schools); alert(Would submit: + $(this).siblings(input[type=text]).val()); $.ajax({
How could you write a unittest in Python that would test that the output
I'm curious, how would you test a string and say yep, that is a
I have put together a simple ASP.NET MVC 3 test web app that uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.