GithubHelp home page GithubHelp logo

lsylvester / rspec-sidekiq Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wspurgin/rspec-sidekiq

0.0 0.0 0.0 150 KB

RSpec for Sidekiq

Home Page: https://github.com/philostler/rspec-sidekiq

License: MIT License

rspec-sidekiq's Introduction

RSpec for Sidekiq

RubyGems Code Climate Travis CI Coveralls Gemnasium coderwall

Simple testing of Sidekiq jobs via a collection of matchers and common tasks

RubyGems | Code Climate | GitHub | Travis CI | Coveralls | Gemnasium | RubyDoc | Ruby Toolbox

Installation

# Gemfile
group :test do
  gem "rspec-sidekiq"
end

rspec-sidekiq requires sidekiq/testing by default so there is no need to include the line require "sidekiq/testing" inside your spec_helper.rb.

This has the effect of not pushing enqueued jobs to Redis but to a job array to enable testing (see Sidekiq's testing wiki). Thus, only include gem "rspec-sidekiq" in environments where this behaviour is required, such as the test group.

If you are using Sidekiq Batches (Sidekiq Pro feature), rspec-sidekiq replaces the implementation (using the NullObject pattern) enabling testing without a Redis instance. Mocha and RSpec stubbing is supported here.

Configuration

If you wish to modify the default behaviour, add the following to your spec_helper.rb file

RSpec::Sidekiq.configure do |config|
  # Clears all job queues before each example
  config.clear_all_enqueued_jobs = false # default => true
end

Matchers

be_processed_in

Describes the queue that the job should be processed in

sidekiq_options queue: :download # job option

it { should be_processed_in :download } # one liner
expect(AwesomeJob).to be_processed_in :download # new expect syntax

be_retryable

Describes if the job retries when there is a failure in it's execution

sidekiq_options retry: 5 # job option

it { should be_retryable true } # one liner
expect(AwesomeJob).to be_retryable true # new expect syntax
# ...or alternatively specifiy the number of times it should be retried
it { should be_retryable 5 } # one liner
expect(AwesomeJob).to be_retryable 5 # new expect syntax

be_unique

Describes if the job should be unique within it's queue

sidekiq_options unique: true # job option

it { should be_unique } # one liner
expect(AwesomeJob).to be_unique # new expect syntax

have_enqueued_job

Evaluates that there is an enqueued job with the specified arguments

expect(AwesomeJob).to have_enqueued_job("Awesome", true) # new expect syntax

have_enqueued_jobs

Evaluates the number of enqueued jobs for a specified job class

expect(AwesomeJob).to have_enqueued_jobs(1) # new expect syntax
# ...but you could just use
expect(AwesomeJob).to have(1).jobs
# ...or even
expect(AwesomeJob).to have(1).enqueued.jobs

be_a_delayed_job

Describes if the job was called on a class using the delay extension for sidekiq

expect("user_welcome_email").to be_a_delayed_job
# verifying the delay amount
expect("user_welcome_email").to be_a_delayed_job(1.hour)

Example

require "spec_helper"

describe AwesomeJob do
  it { should be_processed_in :download }
  it { should be_retryable false }
  it { should be_unique }

  it "enqueues another awesome job" do
    subject.perform

    expect(AnotherAwesomeJob).to have_enqueued_job("Awesome", true)
  end
end

Testing

bundle exec rspec spec

Contribute

Please do! If there's a feature missing that you'd love to see then get in on the action!

Issues/Pull Requests/Comments bring them on...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.