Capybara::Webkit::InvalidResponseError: Unable to load URL: file:/// - ruby-on-rails

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"

Related

Full backtrace for Omniauth error in testing enviroment

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.

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.

Can't use guard-minitest in Rails

I start using MiniTest in my Rails project.
When I run spring rake test, the test works fine.
But I can't run the test by guard-minitest.
bundle exec guard
05:03:24 - INFO - Guard::Minitest 2.4.6 is running, with Minitest::Unit 5.9.0!
05:03:24 - INFO - Running: all tests
Run options: -n spec/apis/user_spec.rb --seed 22566
# Running:
Finished in 0.004998s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
05:03:25 - INFO - Guard is now watching at '/Users/ironsand/dev/my_project'
Guardfile
guard :minitest, spring: 'spring rake test' do
watch(%r{^test/models/company_test.rb$})
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }
end
I wrote the test file name directory to avoid regular expression failer.
The test file is in test/models/company_test.rb.
Where and how can I configure properly to watch the test files by guard?
I guess that the problem here is in watch blocks
Could you try to set the block like that:
guard 'minitest', cmd: 'spring rake test' do
watch('company.rb') { 'company_test.rb' }
watch('company_test.rb')
enŠ²

Is it possible to enhance the rake test task and merge test results together?

I am writing tests for my sidekiq workers and I want them to run when I type "rake" in the terminal. I have that working - I added the following to my Rakefile:
namespace :test do
Rake::TestTask.new(:workers) do |t|
t.libs << "test"
t.pattern = 'test/workers/**/*_test.rb'
end
end
Rake::Task[:test].enhance ["test:workers"]
When I run rake I get something like this as my output:
Run options: --seed 51172
# Running tests:
SS
Finished tests in 0.005594s, 357.5259 tests/s, 0.0000 assertions/s.
2 tests, 0 assertions, 0 failures, 0 errors, 2 skips
Run options: --seed 17561
# Running tests:
S............................................SSSS..SSSSS......
Finished tests in 2.037526s, 30.4291 tests/s, 45.6436 assertions/s.
62 tests, 93 assertions, 0 failures, 0 errors, 10 skips
The S characters are skips - I haven't finished all of my tests yet. So my question is basically - is there a way to merge the two sets of tests after enhancing? Should I be doing something different than an enhance?
If I'm doing anything blatantly wrong please let me know, and thanks for reading this. And just in case it is needed: Rails 4 w/ Ruby 2.0
Try this, change the following:
Rake::TestTask.new(:workers) do |t|
to this:
Rails::TestTask.new(:workers) do |t|
It's a small change, but fixes the problem for me. It means your entire test suite will run with merged output.
there is a simple workaround for this:
bundle exec rake test:all
if you want to see how rails tasks are created look here

Running tests for ruby on rails

I use RubyMine, Windows
I wrote test:
class PostTest < ActiveSupport::TestCase
# Replace this with your real tests.
fixtures :posts
test "the truth" do
#first_posts = posts(:first_posts)
assert #first_posts.title == "Ruby on rails"
end
end
But when I run test with rubyMine ( with bottom button I select "test" and run it)
i get this
C:\Ruby187\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\Ruby187\bin/rake test
Testing started at 1:44 PM ...
(in D:/Projects/TestProject)
Empty test suite.
0 tests, 0 assertions, 0 failures, 0 errors
Test suite finished: 0.031002 seconds
Errors running test:units!
Empty test suite.
Process finished with exit code 1
E.g my test suite is empty, but test suite has one test: "the truth"
When i run tests from console (ruby post_test.rb), I have
D:\Projects\TestProject\test>ruby unit/post_test.rb
Loaded suite unit/post_test
Started
Ruby on rails
.
Finished in 1.7471 seconds.
1 tests, 1 assertions, 0 failures, 0 errorsWhat's wrong?
This bug RubyMine (build 98.47) http://youtrack.jetbrains.net/issue/RUBY-6158

Resources