Rails 6.1 upgrade: undefined method `assert_nothing_raised' - ruby-on-rails

I'm running into this error when upgrading from Rails 6.0.3 to 6.1:
NoMethodError:
undefined method `assert_nothing_raised' for #<RSpec::ExampleGroups::EmailJob:0x00005572d8a00758>
Did you mean? assert_raises
This happens every time a test calls perform_enqueued_jobs.
I'm using RSpec 3.9.

Apparently assert_nothing_raised is a helper method defined by ActiveSupport. I was able to solve this issue by explicitly including the helper in spec/rails_helper.rb:
RSpec.configure do |config|
config.include(ActiveSupport::Testing::Assertions)
# ...

Related

how do I alias Minitest spec methods

I'm using Minitest spec in a rails project and I want to use must as an alias for must_be and wont as an alias for wont_be
in April 2015 Chris Kottom gave an example of this by doing this:
module Minitest::Expectations
alias_method :must, :must_be
end
But when I try the same it doesn't work. I put that code before my test class and this test:
it 'uses the alias' do
user = User.take
_(user).must(:valid?)
end
gives this error:
Minitest::UnexpectedError: NoMethodError: undefined method `valid?' for #<Minitest::Expectation:0x0055b830595608>
(when I change must to must_be the test passes)
What am I doing wrong?

Kaminari undefined method `page' with Rails 4.2

I am using Kaminari 0.16.3 with Rails 4.2.0. Not sure what is going wrong, I have pasted code run by me in console, which proves kaminari gem is loaded but page method is undefined on ActiveRecord model.
abhishek#abhishek ~/my_app (master●●)$ rails c [ruby-2.1.5p273]
Loading development environment (Rails 4.2.0)
irb(main):001:0> Kaminari
=> Kaminari
irb(main):002:0> User.page
NoMethodError: undefined method `page' for User (call 'User.connection' to establish a connection):Class
Please note: I am intentionally calling page without any arguments to reproduce the issue.
Due to an issue with will_paginate and rails_admin I had this in my codebase causing the page method to be renamed to per_page_kaminari.
I have realized this late and fixed.
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
Have a look at this tutorial https://github.com/amatsuda/kaminari
This is how it works
User.page(page_number).per(records_per_page)

Capybara undefined method `expect' for Capybara:Module

I am using /ruby-1.9.3-p545/gems/capybara-2.4.4 and /ruby-1.9.3-p545/gems/selenium-webdriver-2.44.0.
My Capybara config:
config.default_driver = :selenium
config.run_server = false
config.default_selector = :css
config.default_wait_time = 60
I can assure you following methods work fine
Capybara.visit
find(:css, "#checkbox-selectall").set(true)
The only thing that is not working is the 'expect'
expect(page).to have_css('.screen-reader-text')
or
Capybara.expect(page).to have_css('.screen-reader-text')
I get the following error
undefined method `expect' for Capybara:Module (NoMethodError)
I can clearly see in the documentation that this version of capybara does support the expect method but i am unable to understand why it is saying NoMethodError as if i am not calling it from the right scope or something.
Capybara Docs: http://www.rubydoc.info/gems/capybara/Capybara
Install RSpec -- put it in your gemfile, next to Capybara
gem 'rspec'
run bundle install
Generate an install
rails generate rspec:install, more info here https://github.com/rspec/rspec-rails
Be sure to include capybara and your capybara settings in the new helper file (spec_helper or rails_helper).

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.

undefined method `isolation_level' for ActiveRecord::Base:Class

Where does the call to the isolation_level come from?
My module fails at a.save!
module AppsHelpers
def self.create_app!
a = App.new
a.save!
a
end
end
The specific NoMethodError:
Failure/Error: #app = AppsHelpers::create_app!
NoMethodError:
undefined method `isolation_level' for ActiveRecord::Base:Class
What could possibly cause this failure?
System:
ruby 1.9.3p448
Rails 3.2.8
This was simple. I was calling a method defined in the Transactional Isolation gem: The stacktrace was not helpful because I was calling it from an installed gem and this was a missing dependency.

Resources