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.
You are using rails 4.1.5, ActiveJob is introduced in rails 4.2
This issue is resolved by using the gem "gem 'activejob_backport'
Related
I tried to install Cucumber, but rails g cucumber:install shows an error in the terminal:
[WARNING] Could not load generator "generators/cucumber/install/install_generator". Error: uninitialized constant Cucumber::Generators::InstallBase::Config.
Here is the part of my Gemfile with cucumber-rails:
group :test do
gem 'faker'
gem 'capybara'
gem 'guard-rspec'
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'selenium-webdriver'
gem 'gherkin'
gem "launchy", "~> 2.1.2"
end
Here's my entire Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes gem 'therubyracer', platforms: :ruby
gem 'devise'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'therubyracer'
gem 'cancan'
gem 'roo'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
# Use Unicorn as the app server
# gem 'unicorn'
gem 'birthday'
gem 'pry-nav'
gem 'unread'
gem 'week_of_month'
gem 'city-state'
gem 'carmen-rails'
gem "nested_form"
gem 'prawn'
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
gem 'prawn-table', '~> 0.1.0'
gem 'rails_12factor', group: :production
gem 'whenever', require: false
gem 'simplecov', :require => false, :group => :test
#Image uploading
gem 'carrierwave'
gem 'carrierwave-dropbox'
gem 'client_side_validations'
#Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'bootstrap-datepicker-rails', :require => 'bootstrap-datepicker-rails',
:git => 'git://github.com/Nerian/bootstrap-datepicker-rails.git'
gem 'fullcalendar-rails'
gem 'simple_form'
gem 'momentjs-rails'
gem 'google-api-client'
gem 'omniauth'
gem 'omniauth-google-oauth2', :git => 'https://github.com/zquestz/omniauth-google-oauth2.git'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
#gem "rspec-rails"
gem 'factory_girl_rails'
end
group :test do
gem 'faker'
gem 'capybara'
gem 'guard-rspec'
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'selenium-webdriver'
gem 'gherkin'
gem "launchy", "~> 2.1.2"
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
gem 'will_paginate'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
gem 'bootstrap-sass', '~> 3.3.5'
gem 'bootstrap-timepicker-rails-addon', :require => 'bootstrap-timepicker-rails-addon',
:git => 'git://github.com/ywjno/bootstrap-timepicker-rails-addon.git'
It's possible that spring is started and is unable to load the generator. Try
DISABLE_SPRING=1 rails g cucumber:install
my spec :
require 'spec_helper'
RSpec.describe Category, type: :model do
before { #category = FactoryGirl.build(:category) }
subject { #category }
...
my factory :
FactoryGirl.define do
factory :category do
title { FFaker::Lorem.word }
picture { FFaker::Avatar.image }
end
end
my gem file :
source 'https://rubygems.org'
gem 'rails', '4.2.4'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'sdoc', '~> 0.4.0', group: :doc
gem "devise"
gem 'font-awesome-rails'
gem 'simple_form'
gem 'sabisu_rails', github: "IcaliaLabs/sabisu-rails"
gem 'furatto', github: "IcaliaLabs/furatto-rails"
gem 'active_model_serializers', github: 'rails-api/active_model_serializers', branch: '0-8-stable'
gem "paperclip", "~> 4.3"
gem 'open_uri_redirections'
group :development, :test do
gem 'byebug'
gem 'factory_girl_rails'
gem 'ffaker'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'sqlite3'
group :test do
gem 'rspec-rails'
gem 'shoulda-matchers', '2.5.0', require: false
gem 'rspec-collection_matchers'
end
end
what I got running this command =>
bundle exec rspec spec/models/category_spec.rb is :
Randomized with seed 44232 FFFFF Failures:
1) Category
Failure/Error: before { #category = FactoryGirl.build(:category) }
RuntimeError: redirection forbidden: robohash.org/debitismagnamodio.png?size=300x300 -> robohash.org/debitismagnamodio.png?size=300x300
the factory can't create the object because it calls FFake::Avatar.image which is an url (I think, I'm not sure). I already required open-uri and open_uri_redirections both in the factory and the spec but it doesn't work.
any suggestions please ?
Try this in to you Gemfile
gem 'open_uri_redirections', git: 'git#github.com:open-uri-redirections/open_uri_redirections.git'
after
bundle update open_uri_redirections
I tried to deploy the ruby on rails project from a github folder. However, I got such an error when I run cap production deploy
/home/deploy/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in
'require': cannot load such file -- capistrano/cli (LoadError) from /home/deploy/.rbenv/
versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in 'require'
from /usr/bin/cap:3:in '<main>'
I have deploy.rb starting with:
# config valid only for Capistrano 3.1
lock '3.1.0'
And I installed Capistrano v.3.1 with the following command-line:
gem install capistrano -v 3.1.0
Anybody has ideas why I still got an error?
Attached Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.1.0'
# Frontend
gem 'simple_form'
gem 'nested_form', github: 'ryanb/nested_form'
gem 'turbolinks'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'kaminari'
# Javascript
gem 'gon'
gem 'angularjs-rails'
gem 'selectize-rails'
gem 'js-routes'
# Backend
gem 'pg'
gem 'mongoid', github: 'mongoid/mongoid'
gem 'mongoid_geospatial'
gem "active_model_serializers"
gem 'devise'
gem 'state_machine'
gem "rolify"
gem "pundit"
gem 'enumerize'
gem 'simple-rss'
gem 'tweetstream'
gem 'swagger-docs', path: "vendor/gems/swagger-docs-0.1.5"
gem 'wkhtmltopdf-binary'
gem 'wicked_pdf'
gem 'paper_trail', '~> 3.0.3'
# Temporary
gem 'faker'
gem 'factory_girl_rails'
# Asset gems
gem 'haml-rails'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'sass-rails', '~> 4.0.3'
gem 'compass-rails'
group :development do
gem 'spring' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'switch_user'
gem 'better_errors'
gem 'binding_of_caller'
gem 'sextant'
gem 'guard-livereload', require: false
gem 'capistrano', '~> 3.1.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1.1'
gem 'capistrano-rbenv', github: "capistrano/rbenv"
end
group :test do
gem 'rspec-rails'
gem 'spring-commands-rspec'
gem 'guard-rspec'
gem 'fuubar'
gem 'capybara'
gem 'capybara-webkit'
gem 'capybara-email'
gem 'capybara-screenshot'
gem 'database_cleaner'
end
group :test, :darwin do
gem 'rb-fsevent'# if `uname` =~ /Darwin/
end
group :development, :test do
gem 'pry-rails'
gem 'pry-remote'
end
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Thanks!
I am using doorkeeper for OAuth functionality on my ruby on rails application. Suddenly doorkeeper became unable to create token in production mode for some Doorkeeper::Application (i have three Doorkeeper::Application settings) without writing in the production log file, but yesterday it worked normally.
Every time on POST "/oauth/token" doorkeeper returns 500 page for this Doorkeeper::Application, but 201 for another one.
When I recreated Doorkeeper::Application configuration in database without changing parameters, doorkeeper began to work normally with this new record.
I am using postgres with doorkeeper v 0.6.7.
Here is my gemfile:
source 'https://rubygems.org'
def darwin_only(require_as)
RUBY_PLATFORM.include?('darwin') && require_as
end
def linux_only(require_as)
RUBY_PLATFORM.include?('linux') && require_as
end
gem 'rails', '3.2.16'
gem 'jquery-rails'
gem 'pg'
gem 'slim-rails'
gem 'inherited_resources'
gem 'simple_form'
gem 'twitter-bootstrap-rails'
gem 'airbrake', '3.1.2'
gem 'devise'
gem 'httparty'
gem 'ledermann-rails-settings', :require => 'rails-settings'
gem 'carrierwave', git: 'git://github.com/jnicklas/carrierwave.git', ref: '809e86b697'
gem 'mini_magick'
gem 'ruby-progressbar'
gem 'doorkeeper', '~> 0.6.7'
gem 'jsonify-rails'
gem 'less-rails'
gem 'therubyracer', '0.12.1'
gem 'cancan'
gem 'push-core', git: 'git://github.com/tompesman/push-core.git', ref: '980ddc107f'
gem 'push-apns'
gem 'push-gcm'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'recaptcha', require: 'recaptcha/rails'
gem 'validates_timeliness'
gem 'paper_trail'
gem 'oj'
gem 'kaminari'
gem 'newrelic_rpm'
gem 'russian'
gem 'nested_form', '~> 0.3.2'
gem 'select2-rails'
gem 'jquery-ui-rails'
gem 'bourbon'
gem 'axlsx_rails'
gem 'sanitize'
gem 'gilenson'
gem 'ace-rails-ap'
gem 'activerecord-postgres-hstore'
gem 'geocoder'
gem 'rest-client'
gem 'figaro'
gem 'rails-erd'
gem 'acts_as_singleton'
gem 'carrierwave-processing'
group :development do
gem 'thin'
gem 'capistrano'
gem 'capistrano-ext'
gem 'rvm-capistrano'
gem 'yard'
gem 'quiet_assets'
gem 'pry-rails'
gem 'pry-plus'
gem 'ZenTest', '4.9.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-datatables-rails', git: 'git://github.com/rweng/jquery-datatables-rails.git'
end
group :test, :development do
gem 'rspec-rails', '~> 2.0'
gem 'spork-rails'
# Guard
gem 'guard-rspec'
gem 'guard-spork'
# File changes
gem 'rb-fsevent', require: darwin_only('rb-fsevent')
gem 'rb-inotify', require: linux_only('rb-inotify')
# Notifications
gem 'terminal-notifier-guard', require: darwin_only('terminal-notifier-guard')
end
group :test do
gem 'factory_girl_rails'
gem 'shoulda-matchers'
gem 'autotest-rails'
gem 'ffaker'
gem 'webmock'
gem 'vcr'
gem 'capybara'
gem 'json_spec'
gem 'simplecov', require: false
gem 'simplecov-sublime-ruby-coverage', require: false
gem 'test_after_commit'
end
What can be wrong with doorkeeper?
my rails server seems like it is logging everything twice, not sure what is going on here, what should I do to investigate this ?
my gemfile
source 'https://rubygems.org'
ruby '2.1.0'
gem 'rails', '4.0.1'
gem 'haml-rails'
gem 'pg', '~> 0.17.1'
gem 'redis'
gem 'redis-namespace'
gem 'thin', '~> 1.6.1'
gem 'rabl'
gem 'underscore-rails'
#assets
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'foundation-rails'
gem 'font-awesome-rails'
#javascript
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 1.2'
gem 'angularjs-rails', '~> 1.2.7'
gem 'ngmin-rails', '~> 0.4.0'
#user auth
gem 'devise', '3.0.0'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'uuidtools'
#misc tools
gem 'twitter'
#heroku
gem 'rails_12factor'
group :development, :test do
gem 'capybara-webkit', github: 'thoughtbot/capybara-webkit', branch: 'master'
gem 'rspec-rails', '~> 2.14.1'
gem 'factory_girl_rails', '4.2.1'
gem 'mocha', '~> 1.0.0'
gem 'pry'
gem 'pry-debugger'
gem 'quiet_assets'
gem 'parallel_tests'
gem 'zeus-parallel_tests'
gem 'guard-rspec'
gem 'rb-fsevent'
end
group :development do
gem 'guard-livereload'
gem 'rack-livereload'
gem 'better_errors'
gem 'terminal-notifier-guard'
end
group :test do
gem 'launchy', '>= 2.1.2'
gem 'capybara', '>= 1.1.3'
gem 'database_cleaner', '~> 1.2.0'
gem 'zeus', :require => false
gem 'shoulda-matchers'
gem 'pdf-inspector'
gem 'selenium-webdriver'
gem "mock_redis", "~> 0.11.0"
end
In my case this was caused by the rails_12factor gem. This gem adds the rails_stdout_logging gem which sends the logs to standard output. This can be useful in a production environment but not in development when Rails already does it by default.
https://github.com/heroku/rails_12factor#rails-4-logging
The solution is to only add this gem in production:
gem 'rails_12factor', group: :production
Have a look at this issue
Try adding the following code to you config/application.rb
if Rails.env.development?
# Don't log to STDOUT, by default rails s will handle it
config.logger = Logger.new('/dev/null')
else
# Don't log to file, sending everything to unicorn file.
config.logger = Logger.new(STDOUT)
end
Do you have your logger set to anything in either config/application.rb or config/environments/development.rb?
If nothing, try adding this line to config/environments/development.rb:
config.logger = Logger.new('/dev/null')
I had success with this in development.rb:
config.logger = ActiveSupport::Logger.new('/dev/null')