lib/rails/auth/rspec/helper_methods.rb in rails-auth-2.1.4 vs lib/rails/auth/rspec/helper_methods.rb in rails-auth-2.2.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Rails module Auth module RSpec # RSpec helper methods module HelperMethods @@ -10,10 +12,11 @@ # Perform a test with the given credentials # NOTE: Credentials will be *cleared* after the block. Nesting is not allowed. def with_credentials(credentials = {}) raise TypeError, "expected Hash of credentials, got #{credentials.class}" unless credentials.is_a?(Hash) + test_credentials.clear credentials.each do |type, value| test_credentials[type.to_s] = value end @@ -22,12 +25,12 @@ end # Creates an Rails::Auth::X509::Certificate instance double def x509_certificate(cn: nil, ou: nil) subject = "" - subject << "CN=#{cn}" if cn - subject << "OU=#{ou}" if ou + subject += "CN=#{cn}" if cn + subject += "OU=#{ou}" if ou instance_double(Rails::Auth::X509::Certificate, subject, cn: cn, ou: ou).tap do |certificate| allow(certificate).to receive(:[]) do |key| { "CN" => cn, @@ -45,12 +48,10 @@ Rails::Auth::ACL::Resource::HTTP_METHODS.each do |method| define_method("#{method.downcase}_request") do |credentials: {}| path = self.class.description # Warn if methods are improperly used - unless path.chars[0] == "/" - raise ArgumentError, "expected #{path} to start with '/'" - end + raise ArgumentError, "expected #{path} to start with '/'" unless path.chars[0] == "/" env = { "REQUEST_METHOD" => method, "PATH_INFO" => self.class.description }