So one of the gems we use a lot in our Ruby on Rails applications is Resque. For those who don't know, it's a library that allows you to run background tasks that are separate from the main web thread.
This gets especially useful when your web applications get big enough that they are doing long, complex tasks. There are alternatives like Sidekiq and Delayed Job, but Resque was the first one we came across and it's been serving us well for years.
However, one thing that became really annoying to deal with was automated tests (or specs). We use rspec, and when we would run our tests, a lot of the times our tests would fail because it would run into some code similar to
Resque.enqueue which requires that your Redis server be running.
One way to deal with this was to simply start up your Redis server and then run your specs. However, this didn't feel right. With stubs, and mocks, and whatever else you use to fake logic, it seems that it should be easy to stub out any call that Resque makes.
Luckily, there is an easy solution.
resque_spec and its repo can be found here.
It can actually do a bunch of stuff, but the key thing for us, is that it basically stubs out the real Resque calls so it doesn't actually queue up jobs, and doesn't require Redis to be running. What's more, the setup is as simple as including it in your Gemfile. Warning: As they mention, only include this in your test group, as it does override the default Resque functionality
# Gemfile ... group :test do gem 'resque_spec' end ...
What's more, if you're using Resque Scheduler, it works with that as well (with a little extra configuration).
resque_spec in place, running specs became a lot simpler. Hope this helps some peeps out!