How to display rspec errors faster? - ruby-on-rails

My rspec test suite is slow. It takes about half a decade to run all the tests. While it's running, I see only that tests are failing.
.......................................................................
.......FFFFFFFFFFFFFFF....F..........FFFFFFFFF.........................
................FFFFFFFFFFFFFFF.....................FF.................
..........................FFF..........................................
.............FFFFFFFFFFFFFFFFFFFFFF....................................
................................................................FFFF...
.......FFFFFFFFF..........................
Then, after staring at this for a few years, I finally get a listing of what is wrong.
Failures:
172481) Foobar should barfoo the barbaz while quux is set to narf
Failure/Error: before { click_link "Enable narf" }
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/helpers/foobar_helper.rb:22:in `gobble'
# ./app/controllers/barbaz_controller.rb:18:in `omgwtf'
# (eval):2:in `click_link'
# ./spec/requests/metasyntactic_spec.rb:43:in `block (5 levels) in <top (required)>'
Is there a way to tell rspec it should display the errors directly - while running the test suite?

You can use the fuubar format, see the doc here : https://github.com/jeffkreeftmeijer/fuubar/

Related

Rails Upgrade to 6.1.4.6 Active Record Exception

After upgrading the rails from "6.1.3.1" to "6.1.4.6" I started to receive a lot of errors of the same kind but in different places in a project (777 tests had errors). Not able to get error trace. The error is always the same:
ArgumentError: wrong number of arguments (given 0, expected 1)
Backend::TasksControllerTest::IndexFilterTest#test_#index_can_filter_on_lead_status:
ArgumentError: wrong number of arguments (given 0, expected 1)
app/models/campaign.rb:133:in `update_schedules'
test/controllers/backend/tasks_controller_test.rb:137:in `block in <class:IndexFilterTest>'
725) Error:
DeleteModelImportJobTest#test_removes_model_import_and_all_associated_rows:
ArgumentError: wrong number of arguments (given 0, expected 1)
app/models/office/model_import/row.rb:15:in `remove_imported_object'
app/jobs/delete_model_import_job.rb:6:in `block in perform'
app/jobs/delete_model_import_job.rb:5:in `perform'
test/jobs/delete_model_import_job_test.rb:11:in `block (2 levels) in <class:DeleteModelImportJobTest>'
test/jobs/delete_model_import_job_test.rb:10:in `block in <class:DeleteModelImportJobTest>'
726) Error:
Backend::Leads::CampaignLeadsControllerTest#test_new_includes_users_from_ponds_as_well_as_team_for_selection:
ArgumentError: wrong number of arguments (given 0, expected 1)
test/controllers/backend/leads/campaign_leads_controller_test.rb:5:in `block in <class:CampaignLeadsControllerTest>'
727) Error:
Backend::Leads::CampaignLeadsControllerTest#test_new_determines_users_without_firepoint_phone_numbers:
ArgumentError: wrong number of arguments (given 0, expected 1)
test/controllers/backend/leads/campaign_leads_controller_test.rb:5:in `block in <class:CampaignLeadsControllerTest>'
Errors Screenshot
I was trying to debug minitest tests and it seems that all related to ActiveRecord methods raising the error: delete_all!, delete, update_all, update! the transaction, etc. (see screenshots)
update! error screenshot
delete_all error screenshot
transaction error screenshot
Have no idea where to move next and how to fix it, any thoughts on how to proceed and where to look are very appreciated.
I run into same exception and what I found was defining scope as
scope :id, (id) -> { where(id: id } I had remove the scope and edit my code so everything was fine

RSpec deprecated behavior 'let'

I am receiving these warnings when running my RSpec tests using Rspec-rails 2.14. I want to upgrade to RSpec 3 to see if there are any performance improvements, but I assume these will all fail due to this warning? I am using Factory girl also.
This is deprecated behavior that will not be supported in RSpec 3.
`let` and `subject` declarations are not intended to be called
in a `before(:all)` hook, as they exist to define state that
is reset between each example, while `before(:all)` exists to
define state that is shared across examples in an example group.
WARNING: let declaration `fa` accessed in a `before(:all)` hook at:
D:/RailsApps/uwb/spec/models/fa_commercial_spec.rb:77:in `block (2 level
s) in <top (required)>'
Here is one example, how can this be changed so that it will be ok in RSpec 3?
require 'spec_helper'
describe 'FaCommercial' do
let(:admin_user) {create(:user_admin_dev)}
let(:template) {create :fa_commercial_template}
let(:fa) {create :fa_commercial, fa_template: template}
let(:stmt_template_bal_sheet) {create :fa_commercial_stmt_template_bal_sheet, fa_template: template}
let(:stmt_template_cash_flow) {create :fa_commercial_stmt_template_cash_flow, fa_template: template}
let(:stmt_template_income_stmt) {create :fa_commercial_stmt_template_income_stmt, fa_template: template}
let(:stmt_template_ratios) {create :fa_commercial_stmt_template_ratios, fa_template: template}
before(:all) do
admin_user
stmt_template_bal_sheet
stmt_template_cash_flow
stmt_template_income_stmt
stmt_template_ratios
..........
The error is self-explanatory.
`let` and `subject` declarations are not intended to be called
in a `before(:all)` hook
You might take a look at the RSpec documentation to understand how things works first, then, you will be able to refactor your scenarios in order to make it work.

Dir.glob with sort issue

As in "Alphabetize results of Dir.glob", I use sort to get file list in alphabetical order:
Dir.glob("#{options[:path]}/**/*.jpg", File::FNM_CASEFOLD).sort { |file|
dir, filename = file.match(/.+\/(.+)\/(.+)/).captures
# ---cut---
}
Without the sort it works good, but with it fails with error:
$ rake slides:import -- --user foo --path /bar/baz
(in /home/user/app_folder)
"baz/ - /bar/baz/DSC_4120.JPG - saved"
rake aborted!
ArgumentError: comparison of String with 0 failed
/home/footoo/footoo/lib/tasks/slides.rake:41:in `>'
/home/footoo/footoo/lib/tasks/slides.rake:41:in `sort'
/home/footoo/footoo/lib/tasks/slides.rake:41:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => slides:import
Any idea what's wrong ?
Full code available on Github.
When sort is given a block it expects it to return -1,0 or 1 in order to know how to sort (a custom <=> function). You need to add each after sort to get back the default sort and the intended behavior.
Dir.glob("#{options[:path]}/**/*.jpg", File::FNM_CASEFOLD).sort.each{|file|
....
}
Read the documentation here: http://ruby-doc.org/core-2.2.0/Array.html#method-i-sort

not_to change.by() is not supported

I upgraded rspec version from 2 to 3. This is one of the issues I faced:
Failures:
1) Slide after .destroy(force: false) visible if .with_deleted
Failure/Error: expect{#slide.destroy(force: false)}.to_not change(Slide.with_deleted, :count).by(1)
NotImplementedError:
`expect { }.not_to change { }.by()` is not supported
# ./spec/models/slide_spec.rb:36:in `block (3 levels) in <top (required)>'
and in the rspec's changelog I can read it was never supported (oink ?!##). At the same time there are still some examples how to use change syntax but without not keyword.
So the question is how to expect no change ?
Fortunately I want to expect no change (any) so I can omit by() part. It works just fine !
expect{#slide.destroy(force: false)}.to_not change(Slide.with_deleted, :count)

cucumber contradictory error messages

Problem Background: "cucumber declarative step definitions using web_steps.rb" Stack Overflow Question
In troubleshooting the problem in question two contradictory error messages are arrived at; with the statement:
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
check(field)
end
added to 'features/step_definitions/movie_steps.rb' execution of 'bundle exec cucumber features/filter_movie_list.feature' results in:
Ambiguous match of "I uncheck "ratings_G"":
features/step_definitions/movie_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/
features/step_definitions/web_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/
However, removal of the step does not result in the step definition from 'web_steps.rb' being utilized; rather, a different error message is displayed:
When I uncheck the following ratings: G, PG-13 # features/step_definitions/movie_steps.rb:44
Undefined step: "When I uncheck "ratings_G"" (Cucumber::Undefined)
./features/step_definitions/movie_steps.rb:52:in `block (2 levels) in <top (required)>'
./features/step_definitions/movie_steps.rb:49:in `each'
./features/step_definitions/movie_steps.rb:49:in `/I (un)?check the following ratings: (.*)/'
features/filter_movie_list.feature:30:in `When I uncheck the following ratings: G, PG-13'
How is it possible for Cucumber to complain that a step is redundant when there are two definitions in two places but then later complain that the very same step is not defined when its duplicate is removed? Is it possible the second error message really means something other than what is stated?
PS: The configuration was arrived at by way of a Cucumber installation with training wheels for CS169.x1 # edX...
It seems that you have one definition called When I uncheck "ratings_G" that is somewhat matched with the call When I uncheck the following ratings: G, P-13 that occurs in the error message. Cucumber is complaining that nothing matches the latter one. Does it exist in your code?
The somewhat matching would possibly explain the ambiguity warning you got initially. The definition matches but not what is found inside the string.

Resources