byebug
I am wondering is there anyway to step through code in minitest? if I put byebug or debugger in my code and run the test that hits it, the tests run right through and dont stop. Is there anyway to stop the code and step through the way you do in development?
Source: (StackOverflow)
I have a rails (4.2.1) app that uses postgresql in development and test. I use byebug to debug and step through the tests.
When running in development, everything works fine, and I can see the rows in the database. When running in test, with a byebug breakpoint within a particular test, I check the database (from PG Commander) and see that the schema is there, but there are no records.
Am I missing some configuration?
Source: (StackOverflow)
Has anyone seen a similar issue? . I have Windows 8. Every time I do any 'generate scaffold` I get the error below.
I'm getting this error in most of my projects, often at various steps but always with byebug.
C:\Ruby200-x64\rail_projects\bookmarks>rails generate scaffold
DL is deprecated, please use Fiddle
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/byebug-3.5.1/lib/byebug/core.rb:1:in `re
quire': cannot load such file -- byebug/byebug (LoadError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/byebug-3.5.1/lib/byebug/cor
e.rb:1:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/byebug-3.5.1/lib/byebug.rb:
1:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/byebug-3.5.1/lib/byebug.rb:
1:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.5/lib/bundler/r
untime.rb:76:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.5/lib/bundler/r
untime.rb:76:in `block (2 levels) in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.5/lib/bundler/r
untime.rb:72:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.5/lib/bundler/r
untime.rb:72:in `block in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.5/lib/bundler/r
untime.rb:61:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.5/lib/bundler/r
untime.rb:61:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.7.5/lib/bundler.r
b:133:in `require'
from C:/Ruby200-x64/rail_projects/bookmarks/config/application.rb:15:in
`<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta4/lib/ra
ils/commands/commands_tasks.rb:141:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta4/lib/ra
ils/commands/commands_tasks.rb:141:in `require_application_and_environment!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta4/lib/ra
ils/commands/commands_tasks.rb:128:in `generate_or_destroy'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta4/lib/ra
ils/commands/commands_tasks.rb:50:in `generate'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta4/lib/ra
ils/commands/commands_tasks.rb:39:in `run_command!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.2.0.beta4/lib/ra
ils/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Gemifile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0.beta4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.0.beta1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jQuery as the JavaScript library
gem 'jquery-rails', '~> 4.0.0.beta2'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0.0.beta4'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Source: (StackOverflow)
I have the follwing error:
NameError (undefined local variable or method `byebug'
Code is
def test
t = ""
byebug
end
--
RAILS_ENV=development gem list | grep bye
byebug (3.5.1)
then I run :
RAILS_ENV=development rails s
but it shows:
NameError (undefined local variable or method `byebug'
Do you have any idea why?
Thanks!
Source: (StackOverflow)
I'm having the problem that byebug class are ignored after the first one. It's very strange.
I start the server. Whenever there is a byebug statement, if it is the first one since the server has started, it will work. If not, it will say this message: *** Byebug already started. Ignoring
byebugcall.
and the only way for the debugger to work would be to restart the server (and it will only work once).
Any help would be really appreciated.
BTW, this happens with every project.
Thanks.
Source: (StackOverflow)
When I'm debugging with Byebug sometimes I evaluate some variables in the terminal which causes the displayed line context to 'go up'. Then I would like to print it again to screen. How can I do that?
I thought maybe 'display' will do that but apparently it does something else.
Source: (StackOverflow)
I try to debug my user_mailer.rb within my test environment. But I dont know why the debugger doesnst stop where it suppose to.
So, the code I roughly have is:
user_mailer_spec.rb
describe UserMailer do
describe '#send_notification_letters' do
# bunch of code omitted here ...
it 'should record itself to the database'
expect { UserMailer.send_notification_letters(user) }.to change{SentMail.count}.by(1)
end
end
end
In user_mailer.rb
class UserMailer < ActionMailer::Base
def send_notification_letters(user)
byebug # should break here but doesnt,
# also tried binding.pry here, also doesnt work
# buggy code ...
# buggy code ...
# buggy code ...
SentMail.create(...) # never reached
mail(to:..., from:...)
end
end
The question is, why is byebug/pry not stopping in the user_mail.rb
when i run the test rspec spec/mailer/user_mailer_spec.rb
?
And why?
How to make it stop at that break point?
Is there a bug in the debugger?
Source: (StackOverflow)
I have a function that looks like this:
def search_street_addresses(query, limit: 100)
if query.is_a? String
query = @address_parser.parse(query)
fail ArgumentError, "Invalid address string" if query.nil?
end
# ...
And it's called like this:
begin
results = @ndi.search_street_addresses(query)
rescue ArgumentError
raise CommandError, "Failed to parse address"
end
It works perfectly on my machine. I have stepped through the code with a debugger, and everything works as expected. The problem is that on the machine of a co-worker (with the exact same code as I and the exact same Ruby version) a seemingly impossible thing happens. Between the call @ndi.search_street_addresses(query)
and the first line of the function, an ArgumentError
is raised. I have inserted a breakpoint like this:
begin
require "byebug"; byebug
results = @ndi.search_street_addresses(query)
# ...
And attempted to step into the function, but the ArgumentError
is raised after the first step
I take, without me ever entering the function. I have also set a breakpoint in the function:
def search_street_addresses(query, limit: 100)
require "byebug"; byebug
if query.is_a? String
# ...
But the ArgumentError
is raised without the breakpoint triggering. This only happens on his machine, everything works perfectly on mine. I don't have the slightest clue how to debug this since the ArgumentError
is seemingly raised somewhere in the Ruby ether outside the reach of Byebug.
So; how do I debug this?
Source: (StackOverflow)
I launch unicorn through foreman, so the debugger prompt is swallowed. I've had luck with the debugger
gem in the past connecting as a remote debugger.
We're about to upgrade to Ruby 2.1.2 which, as I understand it, is not compatible with debugger
.
I've changed the remote debugger code to use byebug
:
require 'byebug'
def find_available_port
server = TCPServer.new(nil, 0)
server.addr[1]
ensure
server.close if server
end
port = find_available_port
puts "Remote debugger on port #{port}"
Byebug.start_server('localhost', port)
Once unicorn is started, I can connect to byebug:
$ byebug -R localhost:54623
Connecting to byebug server localhost:54623
Connected.
But my code is littered with byebug
calls, and they never trigger a breakpoint in the remote debugger. Pages that block on load when the debugger is not remote load normally when connected remotely.
The unicorn file specifies only one worker, so I'm reasonably sure that's not it:
require File.dirname(__FILE__)+'/application'
if Rails.env.development?
worker_processes 1
timeout_override = ENV['WEBSERVER_TIMEOUT_OVERRIDE']
timeout Integer(timeout_override || 3600)
if timeout_override
puts "Development: Using WEBSERVER_TIMEOUT_OVERRIDE of #{timeout_override} seconds"
end
else
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout 25
end
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
Any ideas would be greatly appreciated.
Source: (StackOverflow)
What is the best way to debug in JRuby 9000? Pry and Byebug are both MRI-dependent. All the JRuby info that I have found seem to be only for pre-9k, and are not working for my JRuby 9k setup.
Source: (StackOverflow)
When I set a breakpoint with Byebug in rails I sometime want it to finish executing, but the guide on github says to use 'exit' which also exits pry. Also hitting 'continue' a bunch of times can be annoying if the breakpoint is dropped in a loop. Is there anyway to stop byebug without exiting the rails console?
Source: (StackOverflow)
I've got a collision between the step
'pseudo function' provided by the byebug debugger (specifically, I'm using pry-byebug), and the step
function provided by cucumber for running arbitrary cucumber steps.
I've tried to do my step function call with byebug's eval
function, but this requires quotes to be nested three layers deep, and I haven't found a way to properly escape everything. For example, this doesn't work:
eval "step(\"I click on the \"Save order\" form button\")"
Source: (StackOverflow)
I'm currently getting an error that looks like this:
NoMethodError: undefined method `debug' for nil:NilClass
/mnt/hgfs/Dropbox/Company/Project/lib/project/misc.rb:23:in `debug'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:49:in `block in compare_addresses'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `each'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `compare_addresses'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:32:in `valid?'
/mnt/hgfs/Dropbox/Company/Project/specs/project/validation/google_geocoding_validation_engine_spec.rb:56:in `block (2 levels) in <module:Validation>'
/home/tomas/ruby2/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
I figured I'd try using byebug to figure out why the object is nil
since it's never supposed to be nil
. I placed byebug
just above the erroneous line:
def debug(&block)
if @logger.nil?
byebug
end
@logger.debug(@logger_name, &block)
end
And ran the tests. I was dropped to the byebug debugging interface and could confirm that the object was indeed nil
. The problem is that I can't climb up the stack:
(byebug) up
*** Adjusting would put us beyond the oldest (initial) frame.
(byebug) down
*** Adjusting would put us beyond the newest (innermost) frame.
(byebug) backtrace
--> #0 AddressKit::Misc::Logging.debug(block#Proc) at /mnt/hgfs/Dropbox/Kvantel/Address Kit/lib/addresskit/misc.rb:25
Warning: saved frames may be incomplete; compare with caller(0)
Why can't I go up the stack? Is this an issue with byebug or perhaps an incompatibility with MiniTest?
Source: (StackOverflow)
I am making a rather simple Rails app with Rails 4.1.6. Initially, I used Ruby version 1.9.3 (which is what I used for another project, and this Ruby version was set as default), but half way through the app I decided to change the Ruby version to the most recent 2.1.3 (rvm use 2.1.3
). After the change of the Ruby version, I re-bundled.
For debugging purposes, I added pry, because debugger doesn't work with recent versions of Ruby:
Gemfile:
group :development, :test do
gem 'pry-rails'
gem 'pry-byebug'
end
Now every time I try to enter the rails console (rails c
), I get the following error:
Could not find byebug-3.5.1 in any of the sources
Which is strange, because the list of gems printed out in the console after bundling contains the following:
Using byebug 3.5.1
<...>
Using pry 0.10.1
Using pry-byebug 2.0.0
Using pry-rails 0.3.2
and the command bundle show byebug
returns:
/home/<my home directory>/.rvm/gems/ruby-2.1.3/gems/byebug-3.5.1
I tried to bundle update
and to delete the Gemfile.lock and re-bundle, but the error remains. Could you suggest how to solve it?
Source: (StackOverflow)