Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'uninitialized @digest_username' warning. #116

Closed
wants to merge 1 commit into from

Conversation

tgxworld
Copy link

@tgxworld tgxworld commented Oct 6, 2014

Related Tests: https://travis-ci.org/rails/rails/jobs/36882244

When a test returns a status of 401, the following methods will be called:

# test.rb

def retry_with_digest_auth?(env)
  last_response.status == 401 &&
  digest_auth_configured? &&
  !env["rack-test.digest_auth_retry"]
end

def digest_auth_configured?
  @digest_username
end

However, if digest_authorize is not called by the tests, we will get this warning warning: instance variable @digest_username not initialized

# Set the username and password for HTTP Digest authorization, to be
# included in subsequent requests in the HTTP_AUTHORIZATION header.
#
# Example:
#   digest_authorize "bryan", "secret"
def digest_authorize(username, password)
  @digest_username = username
  @digest_password = password
end

@tgxworld
Copy link
Author

tgxworld commented Oct 6, 2014

@brynary Could you have a look at this? Thanks in advance!

@whatyouhide
Copy link

👍 This should be merged IMO!

@cpetschnig
Copy link

Adding this would really be helpful, especially since RSpec 3.5 has warnings turned on by default:

# This setting enables warnings. It's recommended, but in some cases may
# be too noisy due to issues in dependencies.
config.warnings = true

rack-test is far too popular to have such mentioned issues ;-)

@dentarg
Copy link

dentarg commented Jan 10, 2017

Using the following in my specs for now, but would love to see this merged and released.

spec_help/warning_filter.rb:

# frozen_string_literal: true

# Inspired by https://github.com/rkh/tool
require "delegate"
class WarningFilter < DelegateClass(IO)
  def write(line)
    super unless silence?(line)
  end

  private

  VARIABLES_TO_IGNORE_PER_GEM = {
    # can be removed if https://github.com/brynary/rack-test/pull/116 is merged
    "rack-test" => %w[
      digest_username
    ],
    "rack-timeout" => %w[
      logger
      runner
      cancelled
    ],
  }

  VARIABLES_TO_IGNORE = VARIABLES_TO_IGNORE_PER_GEM
    .flat_map { |_gem_name, variables_to_ignore| variables_to_ignore }
    .join("|")

  def silence?(line)
    [
      /warning: instance variable @(#{VARIABLES_TO_IGNORE}) not initialized/,
      /assigned but unused variable - offset/,
    ].any? { |r| r =~ line }
  end
end

spec_helper.rb:

require_relative "spec_help/warning_filter"

# Replace stderr with our filtered class
$stderr = WarningFilter.new($stderr)

perlun pushed a commit that referenced this pull request Apr 21, 2017
Adds intialization of digest_username and digest_password.

Implements PR #116 and PR #124 .
@dennissivia
Copy link

Implemented by PR #141

@junaruga
Copy link
Contributor

@tgxworld thank your for your pull-request.
It was merged as 2178498 .

@junaruga junaruga closed this Apr 26, 2017
alex-damian-negru pushed a commit to alex-damian-negru/rack-test that referenced this pull request Apr 5, 2021
Adds intialization of digest_username and digest_password.

Implements PR rack#116 and PR rack#124 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants