Full backtrace for Omniauth error in testing enviroment - ruby-on-rails

When running an automated test with a omniauth mock, I get:
Run options: -b --seed 58490
# Running:
D, [2023-02-14T18:24:28.454047 #7345] DEBUG -- omniauth: (github) Setup endpoint detected, running now.
E, [2023-02-14T18:24:28.457195 #7345] ERROR -- omniauth: (github) Authentication failure! undefined method `settings_object' for nil:NilClass: NoMethodError, undefined method `settings_object' for nil:NilClass
F
Failure:
Sessions::OmniauthControllerTes#test_should_create_a_github_session [/opt/web/test/controllers/sessions/omniauth_controller_test.rb:13]:
"Session.count" didn't change by 1.
Expected: 1
Actual: 0
rails test test/controllers/sessions/omniauth_controller_test.rb:10
Finished in 2.899824s, 0.3448 runs/s, 0.3448 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
Even with -b, I don't get a backtrace for "Authentication failure!". I'm assuming this is either because:
Omniauth is catching the error
The testing environment is simulating a second http connection and this error is happening in that second connection
I've looked in log/test.log. I don't see any clues where this error is happening.
How to I get a backtrace for the "Authentication failure!" error so I know where to put a debugger call and further inspect?

I was able to find the location where to put the debugger call by running in the container:
$ grep 'Authentication failure!' -rin `find / -iname 'gem*' -type d `
But if there's a way for minitest to bring the backgrace into the forefront, I'd like to know it.

Related

Resque not failing an obviously buggy job

I have the following problem with Resque and Rails 6 (ruby 2.7.2). I am new to this gem and wanted to do some simple testing to see how things are handled, so I created a simple failing job:
class TestJob < ApplicationJob
#queue = :default
def self.perform(*args)
0/0
end
end
Obviously, when I go to the console and run it, I get the error:
irb(main):001:0> TestJob.perform
Traceback (most recent call last):
3: from (irb):1
2: from app/jobs/test_job.rb:5:in `perform'
1: from app/jobs/test_job.rb:5:in `/'
ZeroDivisionError (divided by 0)
But when I run my worker with the command:
QUEUE=* VVERBOSE=true rake resque:work
And then enqueue my job in rails console, the output I get is:
irb(main):002:0> Resque.enqueue(TestJob)
=> true
And in the resque logs:
** [21:32:57 2020-12-09] 15198: resque-2.0.0: Waiting for default
** [21:33:02 2020-12-09] 15198: Checking default
** [21:33:02 2020-12-09] 15198: Found job on default
** [21:33:02 2020-12-09] 15198: resque-2.0.0: Processing default since 1607545982 [TestJob]
** [21:33:02 2020-12-09] 15198: got: (Job{default} | TestJob | [])
** [21:33:02 2020-12-09] 15198: resque-2.0.0: Forked 15765 at 1607545982
** [21:33:02 2020-12-09] 15765: done: (Job{default} | TestJob | [])
Additionally, in the resque web UI it counts this process as successful. The number of failed jobs stays 0. Furthermore, any puts and raise I put into the perform method are not showing in resque/rails console logs.
I have done a basic resque setup on a fresh rails app following the README on the resque's github page. I did not do anything custom. Obviously I restarted my console and worker after I made changes to the test_job.rb file, so this is not a problem of loading (maybe?). I also tried changing self.perform to perform.
I don't know why, but this is the solution. Rather than running:
Resque.enqueue(TestJob)
one should run:
TestJob.perform_later
The thing is, the first way is from the Resque README, and the second one is from the Rails docs. I guess I was fixated on doing this the first way, but it looks like going with the rails conventions is always best.

Agile Web Development Rails 5 test failures

I just finished creating the Depot app from the Agile Web Development with Rails 5 textbook. For some reason, I am getting errors & failures when I run 'rails test'. Can someone explain why this is happening?
My Github repository is here: https://github.com/christopheragnus/Agile_Web_Development_with_Rails_5
Christophers-MacBook-Pro-3:depot Agnus$ rails test
Running via Spring preloader in process 45997
Run options: --seed 52040
# Running:
..............F
Failure:
LineItemsControllerTest#test_should_create_line_item [/Users/Agnus/Dropbox/CA/AgileWebDevelopment/depot/test/controllers/line_items_controller_test.rb:25]:
<Your Cart> expected but was
<>..
Expected 0 to be >= 1.
bin/rails test test/controllers/line_items_controller_test.rb:18
..E
Error:
OrderMailerTest#test_shipped:
NameError: undefined local variable or method `login_url' for #<OrderMailerTest:0x007ff7b60cc410>
Did you mean? login_as
test/test_helper.rb:12:in `login_as'
test/test_helper.rb:20:in `setup'
bin/rails test test/mailers/order_mailer_test.rb:12
E
Error:
OrderMailerTest#test_received:
NameError: undefined local variable or method `login_url' for #<OrderMailerTest:0x007ff7b6058880>
Did you mean? login_as
test/test_helper.rb:12:in `login_as'
test/test_helper.rb:20:in `setup'
bin/rails test test/mailers/order_mailer_test.rb:4
E
Error:
AdminControllerTest#test_should_get_index:
NameError: undefined local variable or method `admin_index_url' for #<AdminControllerTest:0x007ff7b4ca8880>
test/controllers/admin_controller_test.rb:5:in `block in <class:AdminControllerTest>'
bin/rails test test/controllers/admin_controller_test.rb:4
...........................
Finished in 5.740751s, 8.1871 runs/s, 14.4580 assertions/s.
47 runs, 83 assertions, 1 failures, 3 errors, 0 skips
The undefined errors mean just that: you are calling "login_url" but rails cannot find it anywhere. If you simply copy pasted code from the book you should go to the section where they create this helper file and see where they defined the login_url.
The test failure, opposed to the error, is that it is expecting an h2 element to exist with the name "Your Cart" but it cannot find it. To debug this, you could either go through the code and make sure all the routing/rerouting is correct and that the views are correctly structured and there's no typos- or run the app and go through what the test is doing and see if the results you are seeing is what is expected. Then- we can go from there.
As a rule of thumb, it is good to get into the habit of googling errors which can help give you an idea of where to troubleshoot the issues in your project.

Capybara::Webkit::InvalidResponseError: Unable to load URL: file:///

So I get this error when trying to run a Integration test in TestUnit using Capybara.
It's trying to load the URL at file:///
Any ideas?
# Running:
E
Finished in 1.072113s, 0.9327 runs/s, 0.0000 assertions/s.
1) Error:
SignInTest#test_user_signs_in_successfully:
Capybara::Webkit::InvalidResponseError: Unable to load URL: file:/// because of error loading file:///: Unknown error
test/integration/sign_in_test.rb:12:in `block in <class:SignInTest>'
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
[Finished in 6.2s with exit code 1]
[cmd: ["/usr/local/bin/rbenv exec ruby -Itest test/integration/sign_in_test.rb -n 'test_user_signs_in_successfully'"]]
[dir: /Users/user/code/project]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
Ensure this is in test_helper.rb
require "capybara/rails"

Ruby on Rails rspec runs tests succesfully, but Guard + Spork doesn't find methods for Devise

I tried to add a few tests to my Ruby on Rails -application. When I run them on command line using command rspec, it runs fine:
Finished in 0.87603 seconds 3 examples, 0 failures
When starting guard, it runs them fine for the first time as well. It gives this kind of message even though I'm not using minitest:
/.rvm/gems/ruby-2.0.0-p353/gems/minitest-4.7.5/lib/minitest/unit.rb:1037:in `block in process_args': invalid option: --drb (OptionParser::InvalidOption)
I haven't configured to use MiniTest, so I guess there might be something wrong with my configuration files?
However, when I make changes to my user_pages_spec.rb and save, which triggers Guard to run the tests, it gives this kind of error:
Running tests with args ["--drb", "-f", "progress", "-r", "/home/.rvm/gems/ruby-2.0.0-p353/gems/guard-rspec-2.5.0/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/requests/user_pages_spec.rb"]...
Failures:
1)
User pages signup page
Failure/Error: before { visit new_user_registration_path }
ActionView::Template::Error:
undefined method `devise_error_messages!' for #<#<Class:0x00000006b18248>:0x00000006b226f8>
2)
User pages signup page
Failure/Error: before { visit new_user_registration_path }
ActionView::Template::Error:
undefined method `devise_error_messages!' for #<#<Class:0x00000006b18248>:0x000000066de560>
Basicly not finding those methods running the same tests the second time. Tests I run for another page which contains only static content works fine.
Here are some files:
Gemfile: http://pastebin.com/bHgxXYZ3
Guardfile: http://pastebin.com/Rnhz2tsJ
spec_helper: http://pastebin.com/Jpvu3k2Q
.rspec: http://pastebin.com/B0bzmE0n
If something's missing, just give me a note. Thanks for helping :)
Do you also have these errors when starting spork and then running your specs (without Guard)?
For the MiniTest error message, be sure that you don't have a test/ folder in your project.

delayed_jobs error, undefined method `email' for nil:NilClass

the gem delayed_jobs works perfectly in development enviroment. But in production, it doesnot work. It throws the following error in the logs
Am using this delayed_job to send emails to users
I, [2013-11-20T13:55:28.418252 #31220] INFO -- : 2013-11-20T13:55:28+0000:
[Worker(delayed_job host:li483-234 pid:31220)] 1 jobs processed at 77.3979 j/s, 1 failed
I, [2013-11-20T14:05:48.680718 #31220] INFO -- : 2013-11-20T14:05:48+0000: [Worker(delayed_job host:li483-234 pid:31220)] Job Class#receive_msg (id=1) RUNNING
E, [2013-11-20T14:05:48.683409 #31220] ERROR -- : 2013-11-20T14:05:48+0000: [Worker(delayed_job host:li483-234 pid:31220)] Job Class#receive_msg (id=1) FAILED (5 prior attempts) with NoMethodError: undefined method `email' for nil:NilClass
any clues?
I found the answer
in config/application.rb place this on top
require 'yaml'
YAML::ENGINE.yamler = 'psych'
restart server and RAILS_ENV=production bin/delayed_job start

Resources