how to disable warning message with sidekiq in rspec - ruby-on-rails

I'm fairly new to rails and testing. Documentation says to add this code to spec_helper.rb:
RSpec::Sidekiq.configure do |config|
config.warn_when_jobs_not_processed_by_sidekiq = false
end
but when I do, i get an error:
uninitialized constant RSpec::Sidekiq (NameError)

If you have rspec 3, then you should try to add following code to rails_helper.rb instead of spec_helper.rb

Related

How to add "config.include FactoryBot::Syntax::Methods" to rspec config block in spec_helper.rb?

If I add:
config.include FactoryBot::Syntax::Methods
under
RSpec.configure do |config|
and run rspec, I see this error:
/Users/perry_mac/rails_projects/mymri/spec/spec_helper.rb:21:in `block
in ': uninitialized constant FactoryBot (NameError)
my gemfile.lock can be seen in this pastebin
my gemfile can be seen in this pastebin
If I omit the Rspec.configure statement, my tests all run fine. I'd like to make use of the abbreviated syntax, but am not sure what I am doing wrong here.
Note: FactoryBot was previously called FactoryGirl
Got it.
This link showed me the way.
The required addition should be made in spec/support/factory_bot.rb and it should look like this:
# RSpec
# spec/support/factory_bot.rb
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
Note: FactoryBot was previously called FactoryGirl
You must add this string in file 'spec/RAILS_helper.rb' not in 'spec_helper.rb'
Also make sure to require 'factory_bot' in spec/support/factory_bot.rb
That's what ended up being the issue for me.
Make sure to include require 'support/factory_girl' in spec/rails_helper.rb after require 'rspec/rails'.
I was getting this error after putting it right after require 'spec_helper'.
This answer is compiled and tested from previous comments and factory_bot.
Create spec/support/factory_bot.rb file.
Paste inside spec/support/factory_bot.rb file:
require 'factory_bot'
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
Add require 'support/factory_bot.rb' in spec/rails_helper.rb file.
Write tests with pleasure.
I think it's worth mentioning here that, going forward, if using FactoryGirl, you will receive a deprecation message:
The factory_girl gem has been deprecated and has been replaced by factory_bot. Please switch to factory_bot as soon as possible.
Just a note for developers in the future that are trying to use FactoryGirl.

How To Use Spree Route Helpers in RSpec

I am trying to use the Spree 2.3 route helpers in Rspec 3.0. In the main app, I can access them by prefixing spree., like so:
spree.admin_login_path => 'spree/admin/user_sessions#new'
However I can't seem to access them in Rspec.
#rspec error
undefined local variable or method `spree_admin_login_path'
I've found reference to including the helpers in the rails_helper file, but this throws an error
# app/spec/rails_helper.rb
RSpec.configure do |config|
config.include Spree::Core::UrlHelpers
end
# configuring the above results in the following
app/spec/rails_helper.rb:21:in `block in <top (required)>': uninitialized constant Spree (NameError)
How do I access the spree routes given in $ rake routes in my tests?
After digging through the Spree code I was able to put together this setup for my rails_helper file that lets me use spree routes such as spree.admin_login_path in my spec files:
# app/spec/rails_helper.rb
require 'spree/testing_support/url_helpers'
RSpec.configure do |config|
config.include Spree::TestingSupport::UrlHelpers
end
I'm sure there's a smoother way to include all of Spree's test helpers, and I'd love to hear about it from someone who knows.

Devise 3.2 + Rspec 3

I'm trying to build some tests with Rspec and I'm getting the following error:
Failure/Error: get :index
NoMethodError:
undefined method `authenticate!' for nil:NilClass
Then I made some searchs and I realized that I had to include this line in the spec_helper.rb:
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
end
It seems that this code worked for most people but not for me. Now i'm getting the following error:
/home/bruna/Dropbox/Rails/academico/spec/spec_helper.rb:18:in `block in <top (required)>': uninitialized constant Devise (NameError)
I think this might be some error in this version of rspec and/or devise. Has anyone seen this error? Please, help me :'(
RSpec 3 configuration is different from earlier versions, with the addition of a spec/rails_helper.rb file that must be included for each spec file. Add the Devise TestHelpers to the spec/rails_helper.rb file.
If you need more information about RSpec 3 configuration, I've written an RSpec Tutorial. There's also information about testing Devise with RSpec, including advice about session helpers for feature testing, in my Rails Devise Tutorial.

FactoryGirl error : rspec

I cannot run rpsec after merging my code from Github.
I keep getting FactoryGirl error :
uninitialized constant ControllerMacros::FactoryGirl
1) Question has a valid factory
Failure/Error: expect(FactoryGirl.build(:question)).to be_valid
NameError:
uninitialized constant FactoryGirl
# ./spec/models/question_spec.rb:14:in `block (2 levels) in '
Please help.
It appears that FactoryGirl may be missing some definitions. Try declaring the following in your spec_helper:
# spec/spec_helper.rb
require 'factory_girl'
FactoryGirl.find_definitions
If this is for a Rails project, you can avoid finding definitions manually by using factory_girl_rails, which will automatically load your definitions for you.

Zeus + FactoryGirl::Syntax::Methods. undefined method `create'

I have:
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
which properly work with simple rspec spec/model/user_spec.rb (allows me to use create(:user), not FactoryGirl.create(:user)).
But if I use zeus rspec spec/model/user_spec.rb to speed up my specs, it troughs me an error:
Failure/Error: #user = create(:user)
NoMethodError:
undefined method `create' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0x007fc8618e4960>
How I can use this syntax with zeus?
Remove either of these lines in spec/spec_helper.rb if they exist:
require 'rspec/autorun'
require 'rspec/autotest'
Did you previously use spork on this project? If so, you have to remove the parts that Spork changed in your spec_helper. Like #ilake-chang said, you have to remove the require 'rspec/autorun' and you'll also want to remove Spork.prefork and Spork.each_run.
See the Zeus wiki on Spork

Resources