jeremyevans/roda

When running tests for a simple app: "warning: instance variable @status not initialized"

Closed this issue · 3 comments

Maybe I'm doing something silly, but I don't like that warning. My Ruby version is MRI, 2.6.5

Test code

require_relative 'test_helper'

describe 'API V1' do
  include Rack::Test::Methods

  it 'shows a root page' do
    get '/'
    assert last_response.ok?
  end

  def app
    App
  end
end

and the output:

$ rake
Run options: --seed 38523

# Running:

/home/megatux/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/roda-3.26.0/lib/roda.rb:1331: warning: instance variable @status not initialized
.

Finished in 0.014973s, 66.7850 runs/s, 66.7850 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

Thanks!

Instance variables in performance-sensitive parts of Roda are frequently not pre-initialized. If you want to know why, I believe Jeremy discussed it in his RubyKaigi 2019 keynote.

If this concerns, you, either drop the warning flag from your test configuration or look at using the ruby-warning library (also from Jeremy).

# Ignore all warnings in Gem dependencies
Gem.path.each do |path|
  Warning.ignore(//, path)
end

These warnings don't show up by default, you must have verbose warnings enabled (-w ruby option). As @adam12 stated, this is for performance and by design. You can ignore these specific warnings while still emitting other warnings:

require 'warning'
require 'roda'
Gem.loaded_specs['roda'].full_require_paths.each do |path|
  Warning.ignore(:missing_ivar, path)
end

Thanks a lot. Nice gem, BTW <3 !, I'm using rerun gem to run/reload code. It must be using the -w flag.