skip to Main Content

I have installed a gem rspec-rails. Everything is working fine except ActiveJob.
I have tried to implement the ActiveJob in RSpec with:

include ActiveJob::TestHelper

and here’s the code for the RSsec Job Controller:

describe "#perform_later" do
  it "Send Invoice Reminder" do
    ActiveJob::Base.queue_adapter = :test
    InvoiceReminderJob.perform_later
    expect(InvoiceReminderJob).to have_enqueued_job
  end
end

spec_helper.rb:

require 'rails_helper'
RSpec.describe InvoiceReminderJob, type: :job do
  include ActiveJob::TestHelper
  # pending "add some examples to (or delete) #{__FILE__}"

  describe "#perform_later" do
    it "Send Invoice Reminder" do
      ActiveJob::Base.queue_adapter = :test
      InvoiceReminderJob.perform("test")
      expect(InvoiceReminderJob).to have_enqueued_job
    end
  end
end

invoice_reminder_job_spec.rb:

require 'rails_helper'

RSpec.describe InvoiceReminderJob, type: :job do
  # include ActiveJob::TestHelper
  # pending "add some examples to (or delete) #{__FILE__}"

  describe "#perform_later" do
    it "Send Invoice Reminder" do
      ActiveJob::Base.queue_adapter = :test
      InvoiceReminderJob.perform_later
      expect(InvoiceReminderJob).to have_enqueued_job
    end
  end
end

When I am trying to run rspec with the command rspec I am getting the following error:

uninitialized constant ActiveJob (NameError)

Here is my Gemfile:

Here is the gemfile included for my project:

source 'https://rubygems.org'
ruby '2.1.2'

gem 'acts-as-taggable-on', '~> 3.4'
gem 'acts_as_tenant'
gem 'audited', '~> 4.0'
gem 'audited-activerecord'
gem 'aws-sdk', '~> 1.6'
gem 'axlsx'
gem 'best_in_place', '~> 3.0.1'
gem 'bootstrap-generators'
gem 'bootstrap-sass'
gem 'bullet', group: 'development'
gem 'cancancan', '~> 1.10'
gem 'clockwork'
gem 'coffee-rails', '~> 4.1.0'
gem 'daemons'
gem 'delayed_job_active_record'
gem 'devise'
gem 'eefgilm'
gem 'exception_notification'
gem 'figaro'
gem 'font-awesome-rails'
gem 'i18n-js', '>= 3.0.0.rc11'
gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'mailman'
gem 'net-ssh'
gem 'paperclip', '~> 4.2'
gem 'pg'
gem 'protected_attributes'
gem 'puma'
gem 'rails', '4.1.5'
gem 'rails-console-tweaks'
gem 'rails-i18n'
gem 'rails_best_practices'
gem 'redcarpet'
gem 'rest-client'
gem 'roo'
gem 'roo-google'
gem 'roo-xls'
gem 'rubocop', require: false
gem 'sass-rails', '~> 5.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'seed_dump'
gem 'simple_form'
gem 'therubyracer', platforms: :ruby
gem 'traceroute'
gem 'twitter-bootstrap-rails'
gem 'uglifier', '>= 1.3.0'
gem 'whenever', :require => false
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
gem 'zip'

group :development do
  gem 'capistrano'
  gem 'capistrano3-puma'
  gem 'capistrano-bundler', require: false
  gem 'capistrano-rails', require: false
  gem 'capistrano-rvm'
  gem 'rails-erd'
  gem 'capistrano-rails-console', require: false
  gem 'capistrano-maintenance', '~> 1.0', require: false
  gem 'letter_opener'
  gem 'rspec-rails'
  gem 'faker'
end

group :production do
  gem 'rails_12factor'
end

group :test do
  gem 'shoulda-matchers'
  gem 'database_cleaner'
  gem 'simplecov'
end

group :development, :test do
  gem 'byebug'
  gem 'hirb'
  gem 'mocha'
  gem 'activejob'
  gem 'factory_bot_rails'
end

And here is the output of bundle show activejob:

/Users/221/.rvm/gems/ruby-2.1.2/gems/activejob-0

I have tried to search with lots of solution but I am not able to resolve this issue. If anyone could help me with it, I would be really grateful.

2

Answers


  1. Chosen as BEST ANSWER

    This issue is resolved by using the gem "gem 'activejob_backport'


  2. You are using rails 4.1.5, ActiveJob is introduced in rails 4.2

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search