From 0d7b11d7803d7b465f3fbe08187b9339e89fb534 Mon Sep 17 00:00:00 2001 From: Matt Wrock Date: Sun, 17 Apr 2016 23:21:54 -0700 Subject: [PATCH] updating rubocop --- .rubocop.yml | 4 ++ Gemfile | 7 -- lib/winrm/connection_opts.rb | 68 ++++++++++--------- lib/winrm/http/response_handler.rb | 8 +-- lib/winrm/psrp/message.rb | 10 +-- lib/winrm/shells/cmd.rb | 20 +++--- lib/winrm/shells/power_shell.rb | 28 ++++---- lib/winrm/shells/retryable.rb | 9 +-- lib/winrm/shells/shell_factory.rb | 2 +- lib/winrm/version.rb | 2 +- lib/winrm/wsmv/base.rb | 4 +- lib/winrm/wsmv/cleanup_command.rb | 8 +-- lib/winrm/wsmv/close_shell.rb | 2 +- lib/winrm/wsmv/command.rb | 8 +-- lib/winrm/wsmv/command_output.rb | 4 +- lib/winrm/wsmv/command_output_processor.rb | 12 ++-- lib/winrm/wsmv/header.rb | 6 +- lib/winrm/wsmv/powershell_output_processor.rb | 2 +- lib/winrm/wsmv/soap.rb | 26 +++---- lib/winrm/wsmv/wql_query.rb | 6 +- lib/winrm/wsmv/write_stdin.rb | 8 +-- tests/integration/powershell_spec.rb | 3 +- tests/spec/spec_helper.rb | 2 +- winrm.gemspec | 2 +- 24 files changed, 121 insertions(+), 130 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index bffe8b1a..4f54a2cb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ AllCops: Exclude: - 'appveyor.yml' + - 'Vagrantfile' - 'scripts/**/*' - 'lib/winrm/winrm_service.rb' - 'lib/winrm/http/transport.rb' @@ -17,6 +18,9 @@ Metrics/LineLength: Metrics/MethodLength: Max: 20 +ModuleLength: + Max: 250 + ClassLength: Max: 250 diff --git a/Gemfile b/Gemfile index e4fa789c..f5d51710 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,3 @@ # encoding: UTF-8 source 'https://rubygems.org' gemspec - -group :development do - # Use a tighter specification until rubocop issues are fixed. - # Then remove this - gem 'rubocop', '~> 0.28.0' - gem 'pry', '~> 0.10' -end diff --git a/lib/winrm/connection_opts.rb b/lib/winrm/connection_opts.rb index 0b8e8cdc..60856710 100644 --- a/lib/winrm/connection_opts.rb +++ b/lib/winrm/connection_opts.rb @@ -22,16 +22,41 @@ class ConnectionOpts < Hash DEFAULT_OPERATION_TIMEOUT = 60 DEFAULT_RECEIVE_TIMEOUT = DEFAULT_OPERATION_TIMEOUT + 10 DEFAULT_MAX_ENV_SIZE = 153600 - DEFAULT_LOCALE = 'en-US' + DEFAULT_LOCALE = 'en-US'.freeze DEFAULT_RETRY_DELAY = 10 DEFAULT_RETRY_LIMIT = 3 DEFAULT_MAX_COMMANDS = 1480 # TODO: interrogate remote OS version - def self.create_with_defaults(overrides) - config = default.merge(overrides) - config = ensure_receive_timeout_is_greater_than_operation_timeout(config) - config.validate - config + class << self + def create_with_defaults(overrides) + config = default.merge(overrides) + config = ensure_receive_timeout_is_greater_than_operation_timeout(config) + config.validate + config + end + + private + + def ensure_receive_timeout_is_greater_than_operation_timeout(config) + if config[:receive_timeout] < config[:operation_timeout] + config[:receive_timeout] = config[:operation_timeout] + 10 + end + config + end + + def default + config = ConnectionOpts.new + config[:session_id] = SecureRandom.uuid.to_s.upcase + config[:transport] = :negotiate + config[:locale] = DEFAULT_LOCALE + config[:max_envelope_size] = DEFAULT_MAX_ENV_SIZE + config[:max_commands] = DEFAULT_MAX_COMMANDS + config[:operation_timeout] = DEFAULT_OPERATION_TIMEOUT + config[:receive_timeout] = DEFAULT_RECEIVE_TIMEOUT + config[:retry_delay] = DEFAULT_RETRY_DELAY + config[:retry_limit] = DEFAULT_RETRY_LIMIT + config + end end def validate @@ -42,9 +67,9 @@ def validate private def validate_required_fields - fail 'endpoint is a required option' unless self[:endpoint] - fail 'user is a required option' unless self[:user] - fail 'password is a required option' unless self[:password] + raise 'endpoint is a required option' unless self[:endpoint] + raise 'user is a required option' unless self[:user] + raise 'password is a required option' unless self[:password] end def validate_data_types @@ -58,29 +83,8 @@ def validate_data_types def validate_fixnum(key, min = 0) value = self[key] - fail "#{key} must be a Fixnum" unless value && value.is_a?(Fixnum) - fail "#{key} must be greater than #{min}" unless value > min - end - - def self.ensure_receive_timeout_is_greater_than_operation_timeout(config) - if config[:receive_timeout] < config[:operation_timeout] - config[:receive_timeout] = config[:operation_timeout] + 10 - end - config - end - - def self.default - config = ConnectionOpts.new - config[:session_id] = SecureRandom.uuid.to_s.upcase - config[:transport] = :negotiate - config[:locale] = DEFAULT_LOCALE - config[:max_envelope_size] = DEFAULT_MAX_ENV_SIZE - config[:max_commands] = DEFAULT_MAX_COMMANDS - config[:operation_timeout] = DEFAULT_OPERATION_TIMEOUT - config[:receive_timeout] = DEFAULT_RECEIVE_TIMEOUT - config[:retry_delay] = DEFAULT_RETRY_DELAY - config[:retry_limit] = DEFAULT_RETRY_LIMIT - config + raise "#{key} must be a Fixnum" unless value && value.is_a?(Fixnum) + raise "#{key} must be greater than #{min}" unless value > min end end end diff --git a/lib/winrm/http/response_handler.rb b/lib/winrm/http/response_handler.rb index 26378fe5..b330544f 100644 --- a/lib/winrm/http/response_handler.rb +++ b/lib/winrm/http/response_handler.rb @@ -55,7 +55,7 @@ def raise_if_error end def raise_if_auth_error - fail WinRMAuthorizationError if @status_code == 401 + raise WinRMAuthorizationError if @status_code == 401 end def raise_if_wsman_fault @@ -66,7 +66,7 @@ def raise_if_wsman_fault fault = REXML::XPath.first( soap_errors, "//#{WinRM::WSMV::SOAP::NS_WSMAN_FAULT}:WSManFault") - fail WinRMWSManFault.new(fault.to_s, fault.attributes['Code']) unless fault.nil? + raise WinRMWSManFault.new(fault.to_s, fault.attributes['Code']) unless fault.nil? end def raise_if_wmi_error @@ -83,11 +83,11 @@ def raise_if_wmi_error error_code = REXML::XPath.first( error, "//#{WinRM::WSMV::SOAP::NS_WSMAN_MSFT}:error_Code").text - fail WinRMWMIError.new(error.to_s, error_code) + raise WinRMWMIError.new(error.to_s, error_code) end def raise_transport_error - fail WinRMHTTPTransportError.new('Bad HTTP response returned from server', @status_code) + raise WinRMHTTPTransportError.new('Bad HTTP response returned from server', @status_code) end end end diff --git a/lib/winrm/psrp/message.rb b/lib/winrm/psrp/message.rb index c92f4852..eb3db3bb 100644 --- a/lib/winrm/psrp/message.rb +++ b/lib/winrm/psrp/message.rb @@ -71,7 +71,7 @@ class Message information_record: 0x00041011, pipeline_host_call: 0x00041100, pipeline_host_response: 0x00041101 - } + }.freeze # Creates a new PSRP message instance # @param message_parts [Hash] @@ -88,11 +88,11 @@ class Message def initialize(message_parts) message_parts.merge!(default_parts) { |_key, v1, _v2| v1 } - fail 'runspace_pool_id cannot be nil' unless message_parts[:runspace_pool_id] + raise 'runspace_pool_id cannot be nil' unless message_parts[:runspace_pool_id] unless MESSAGE_TYPES.values.include?(message_parts[:message_type]) - fail 'invalid message type' + raise 'invalid message type' end - fail 'data cannot be nil' unless message_parts[:data] + raise 'data cannot be nil' unless message_parts[:data] @data = message_parts[:data] @destination = message_parts[:destination] @@ -113,7 +113,7 @@ def initialize(message_parts) # @return [Array] Unencoded raw byte array of the PSRP message. def bytes if data_bytes.length > BLOB_MAX_LEN - fail "data cannot be greater than #{BLOB_MAX_LEN} bytes" + raise "data cannot be greater than #{BLOB_MAX_LEN} bytes" end [ diff --git a/lib/winrm/shells/cmd.rb b/lib/winrm/shells/cmd.rb index 36585202..752d2059 100644 --- a/lib/winrm/shells/cmd.rb +++ b/lib/winrm/shells/cmd.rb @@ -30,6 +30,17 @@ module Shells class Cmd include Retryable + class << self + def finalize(connection_opts, transport, shell_id) + proc { Cmd.close_shell(connection_opts, transport, shell_id) } + end + + def close_shell(connection_opts, transport, shell_id) + msg = WinRM::WSMV::CloseShell.new(connection_opts, shell_id: shell_id) + transport.send_request(msg.build) + end + end + # Create a new Cmd shell # @param connection_opts [ConnectionOpts] The WinRM connection options # @param transport [HttpTransport] The WinRM SOAP transport @@ -110,15 +121,6 @@ def add_finalizer def remove_finalizer ObjectSpace.undefine_finalizer(self) end - - def self.close_shell(connection_opts, transport, shell_id) - msg = WinRM::WSMV::CloseShell.new(connection_opts, shell_id: shell_id) - transport.send_request(msg.build) - end - - def self.finalize(connection_opts, transport, shell_id) - proc { Cmd.close_shell(connection_opts, transport, shell_id) } - end end end end diff --git a/lib/winrm/shells/power_shell.rb b/lib/winrm/shells/power_shell.rb index dbb09aef..189d6eae 100644 --- a/lib/winrm/shells/power_shell.rb +++ b/lib/winrm/shells/power_shell.rb @@ -34,6 +34,21 @@ module Shells class PowerShell include Retryable + class << self + def finalize(connection_opts, transport, shell_id) + proc { PowerShell.close_shell(connection_opts, transport, shell_id) } + end + + def close_shell(connection_opts, transport, shell_id) + msg = WinRM::WSMV::CloseShell.new( + connection_opts, + shell_id: shell_id, + shell_uri: WinRM::WSMV::Header::RESOURCE_URI_POWERSHELL + ) + transport.send_request(msg.build) + end + end + # Create a new PowerShell shell # @param connection_opts [ConnectionOpts] The WinRM connection options # @param transport [HttpTransport] The WinRM SOAP transport @@ -93,15 +108,6 @@ def cleanup_command(command_id) @transport.send_request(cleanup_msg.build) end - def self.close_shell(connection_opts, transport, shell_id) - msg = WinRM::WSMV::CloseShell.new( - connection_opts, - shell_id: shell_id, - shell_uri: WinRM::WSMV::Header::RESOURCE_URI_POWERSHELL - ) - transport.send_request(msg.build) - end - def open close retryable(@connection_opts[:retry_limit], @connection_opts[:retry_delay]) do @@ -124,10 +130,6 @@ def add_finalizer def remove_finalizer ObjectSpace.undefine_finalizer(self) end - - def self.finalize(connection_opts, transport, shell_id) - proc { PowerShell.close_shell(connection_opts, transport, shell_id) } - end end end end diff --git a/lib/winrm/shells/retryable.rb b/lib/winrm/shells/retryable.rb index bedd1e1d..a6150364 100644 --- a/lib/winrm/shells/retryable.rb +++ b/lib/winrm/shells/retryable.rb @@ -34,12 +34,9 @@ module Retryable def retryable(retries, delay) yield rescue *RETRYABLE_EXCEPTIONS.call - if (retries -= 1) > 0 - sleep(delay) - retry - else - raise - end + raise unless (retries -= 1) > 0 + sleep(delay) + retry end end end diff --git a/lib/winrm/shells/shell_factory.rb b/lib/winrm/shells/shell_factory.rb index 95752100..560f5f75 100644 --- a/lib/winrm/shells/shell_factory.rb +++ b/lib/winrm/shells/shell_factory.rb @@ -41,7 +41,7 @@ def create_shell(shell_type) when :powershell return WinRM::Shells::PowerShell.new(@connection_opts, @transport, @logger) else - fail "#{shell_type} is not a valid WinRM shell type. " \ + raise "#{shell_type} is not a valid WinRM shell type. " \ 'Expected either :cmd or :powershell.' end end diff --git a/lib/winrm/version.rb b/lib/winrm/version.rb index 423e1a19..d3d224db 100644 --- a/lib/winrm/version.rb +++ b/lib/winrm/version.rb @@ -3,5 +3,5 @@ # WinRM module module WinRM # The version of the WinRM library - VERSION = '2.0.0.dev' + VERSION = '2.0.0.dev'.freeze end diff --git a/lib/winrm/wsmv/base.rb b/lib/winrm/wsmv/base.rb index 4ce4fae6..d31b056b 100644 --- a/lib/winrm/wsmv/base.rb +++ b/lib/winrm/wsmv/base.rb @@ -44,11 +44,11 @@ def build protected def create_header - fail 'create_header must be implemented' + raise 'create_header must be implemented' end def create_body - fail 'create_body must be implemented' + raise 'create_body must be implemented' end def encode_bytes(bytes) diff --git a/lib/winrm/wsmv/cleanup_command.rb b/lib/winrm/wsmv/cleanup_command.rb index a7edce73..faa1e03a 100644 --- a/lib/winrm/wsmv/cleanup_command.rb +++ b/lib/winrm/wsmv/cleanup_command.rb @@ -21,8 +21,8 @@ module WSMV # WSMV message to execute a command inside a remote shell class CleanupCommand < Base def initialize(session_opts, opts) - fail 'opts[:shell_id] is required' unless opts[:shell_id] - fail 'opts[:command_id] is required' unless opts[:command_id] + raise 'opts[:shell_id] is required' unless opts[:shell_id] + raise 'opts[:command_id] is required' unless opts[:command_id] @session_opts = session_opts @shell_id = opts[:shell_id] @command_id = opts[:command_id] @@ -36,8 +36,8 @@ def create_header(header) end def create_body(body) - body.tag!("#{NS_WIN_SHELL}:Signal", 'CommandId' => @command_id) do - |cl| cl << Gyoku.xml(cleanup_body) + body.tag!("#{NS_WIN_SHELL}:Signal", 'CommandId' => @command_id) do |cl| + cl << Gyoku.xml(cleanup_body) end end diff --git a/lib/winrm/wsmv/close_shell.rb b/lib/winrm/wsmv/close_shell.rb index 195e9d6c..8ec3db75 100644 --- a/lib/winrm/wsmv/close_shell.rb +++ b/lib/winrm/wsmv/close_shell.rb @@ -21,7 +21,7 @@ module WSMV # WSMV message to close a remote shell class CloseShell < Base def initialize(session_opts, shell_opts) - fail 'shell_opts[:shell_id] is required' unless shell_opts[:shell_id] + raise 'shell_opts[:shell_id] is required' unless shell_opts[:shell_id] @session_opts = session_opts @shell_id = shell_opts[:shell_id] @shell_uri = shell_opts[:shell_uri] || RESOURCE_URI_CMD diff --git a/lib/winrm/wsmv/command.rb b/lib/winrm/wsmv/command.rb index 9bede84d..ef41ca60 100644 --- a/lib/winrm/wsmv/command.rb +++ b/lib/winrm/wsmv/command.rb @@ -58,13 +58,13 @@ def init_ops(session_opts, cmd_opts) end def validate_opts(session_opts, cmd_opts) - fail 'session_opts is required' unless session_opts - fail 'cmd_opts[:shell_id] is required' unless cmd_opts[:shell_id] - fail 'cmd_opts[:command] is required' unless cmd_opts[:command] + raise 'session_opts is required' unless session_opts + raise 'cmd_opts[:shell_id] is required' unless cmd_opts[:shell_id] + raise 'cmd_opts[:command] is required' unless cmd_opts[:command] end def issue69_unescape_single_quotes(xml) - escaped_cmd = /<#{NS_WIN_SHELL}:Command>(.+)<\/#{NS_WIN_SHELL}:Command>/m.match(xml)[1] + escaped_cmd = %r{<#{NS_WIN_SHELL}:Command>(.+)<\/#{NS_WIN_SHELL}:Command>}m.match(xml)[1] xml[escaped_cmd] = escaped_cmd.gsub(/'/, "'") xml end diff --git a/lib/winrm/wsmv/command_output.rb b/lib/winrm/wsmv/command_output.rb index 51fba1b0..f8858d99 100644 --- a/lib/winrm/wsmv/command_output.rb +++ b/lib/winrm/wsmv/command_output.rb @@ -21,8 +21,8 @@ module WSMV # WSMV message to get output from a remote shell class CommandOutput < Base def initialize(session_opts, command_out_opts) - fail 'command_out_opts[:shell_id] is required' unless command_out_opts[:shell_id] - fail 'command_out_opts[:command_id] is required' unless command_out_opts[:command_id] + raise 'command_out_opts[:shell_id] is required' unless command_out_opts[:shell_id] + raise 'command_out_opts[:command_id] is required' unless command_out_opts[:command_id] @session_opts = session_opts @shell_id = command_out_opts[:shell_id] @command_id = command_out_opts[:command_id] diff --git a/lib/winrm/wsmv/command_output_processor.rb b/lib/winrm/wsmv/command_output_processor.rb index 6b9dd0ba..6ddc962b 100644 --- a/lib/winrm/wsmv/command_output_processor.rb +++ b/lib/winrm/wsmv/command_output_processor.rb @@ -57,7 +57,7 @@ def command_output(shell_id, command_id, &block) stream = { n.attributes['Name'].to_sym => decoded_text } output[:data] << stream - block.call stream[:stdout], stream[:stderr] if block + yield stream[:stdout], stream[:stderr] if block end end output[:exitcode] = exit_code(resp_doc) @@ -82,12 +82,10 @@ def send_get_output_message(message) # 2150858793. When the client receives this fault, it SHOULD issue # another Receive request. # http://msdn.microsoft.com/en-us/library/cc251676.aspx - if e.fault_code == '2150858793' - logger.debug('[WinRM] retrying receive request after timeout') - retry - else - raise - end + raise unless e.fault_code == '2150858793' + + logger.debug('[WinRM] retrying receive request after timeout') + retry end def exit_code(resp_doc) diff --git a/lib/winrm/wsmv/header.rb b/lib/winrm/wsmv/header.rb index 44255d22..b51839ee 100644 --- a/lib/winrm/wsmv/header.rb +++ b/lib/winrm/wsmv/header.rb @@ -24,10 +24,10 @@ module WSMV # SOAP header utility mixin module Header # WSMan URI of the regular Windows cmd shell - RESOURCE_URI_CMD = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd' + RESOURCE_URI_CMD = 'http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd'.freeze # WSMan URI for PowerShell - RESOURCE_URI_POWERSHELL = 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell' + RESOURCE_URI_POWERSHELL = 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell'.freeze # Merge the various header hashes and make sure we carry all of the attributes # through instead of overwriting them. @@ -43,7 +43,7 @@ def merge_headers(*headers) def shared_headers(session_opts) { - "#{SOAP::NS_ADDRESSING}:To" => "#{session_opts[:endpoint]}", + "#{SOAP::NS_ADDRESSING}:To" => session_opts[:endpoint], "#{SOAP::NS_ADDRESSING}:ReplyTo" => { "#{SOAP::NS_ADDRESSING}:Address" => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous', diff --git a/lib/winrm/wsmv/powershell_output_processor.rb b/lib/winrm/wsmv/powershell_output_processor.rb index ac9037c7..861885be 100644 --- a/lib/winrm/wsmv/powershell_output_processor.rb +++ b/lib/winrm/wsmv/powershell_output_processor.rb @@ -46,7 +46,7 @@ def command_output(shell_id, command_id, &block) stream = { stream_type(message) => decoded_text } output[:data] << stream - block.call stream[:stdout], stream[:stderr] if block + yield stream[:stdout], stream[:stderr] if block end end output[:exitcode] = exit_code(resp_doc) diff --git a/lib/winrm/wsmv/soap.rb b/lib/winrm/wsmv/soap.rb index 087cf4a3..7e92f194 100644 --- a/lib/winrm/wsmv/soap.rb +++ b/lib/winrm/wsmv/soap.rb @@ -15,23 +15,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -# rubocop:disable Metrics/MethodLength - module WinRM module WSMV # WSMV SOAP namespaces mixin module SOAP - NS_SOAP_ENV = 's' # http://www.w3.org/2003/05/soap-envelope - NS_ADDRESSING = 'a' # http://schemas.xmlsoap.org/ws/2004/08/addressing - NS_CIMBINDING = 'b' # http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd - NS_ENUM = 'n' # http://schemas.xmlsoap.org/ws/2004/09/enumeration - NS_TRANSFER = 'x' # http://schemas.xmlsoap.org/ws/2004/09/transfer - NS_WSMAN_DMTF = 'w' # http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd - NS_WSMAN_MSFT = 'p' # http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd - NS_SCHEMA_INST = 'xsi' # http://www.w3.org/2001/XMLSchema-instance - NS_WIN_SHELL = 'rsp' # http://schemas.microsoft.com/wbem/wsman/1/windows/shell - NS_WSMAN_FAULT = 'f' # http://schemas.microsoft.com/wbem/wsman/1/wsmanfault - NS_WSMAN_CONF = 'cfg' # http://schemas.microsoft.com/wbem/wsman/1/config + NS_SOAP_ENV = 's'.freeze # http://www.w3.org/2003/05/soap-envelope + NS_ADDRESSING = 'a'.freeze # http://schemas.xmlsoap.org/ws/2004/08/addressing + NS_CIMBINDING = 'b'.freeze # http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd + NS_ENUM = 'n'.freeze # http://schemas.xmlsoap.org/ws/2004/09/enumeration + NS_TRANSFER = 'x'.freeze # http://schemas.xmlsoap.org/ws/2004/09/transfer + NS_WSMAN_DMTF = 'w'.freeze # http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd + NS_WSMAN_MSFT = 'p'.freeze # http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd + NS_SCHEMA_INST = 'xsi'.freeze # http://www.w3.org/2001/XMLSchema-instance + NS_WIN_SHELL = 'rsp'.freeze # http://schemas.microsoft.com/wbem/wsman/1/windows/shell + NS_WSMAN_FAULT = 'f'.freeze # http://schemas.microsoft.com/wbem/wsman/1/wsmanfault + NS_WSMAN_CONF = 'cfg'.freeze # http://schemas.microsoft.com/wbem/wsman/1/config def namespaces @namespaces ||= { @@ -51,5 +49,3 @@ def namespaces end end end - -# rubocop:enable Metrics/MethodLength diff --git a/lib/winrm/wsmv/wql_query.rb b/lib/winrm/wsmv/wql_query.rb index 27b59b42..952de6d9 100644 --- a/lib/winrm/wsmv/wql_query.rb +++ b/lib/winrm/wsmv/wql_query.rb @@ -39,11 +39,7 @@ def process_response(response) items = {} if hresp[:enumerate_response][:items] hresp[:enumerate_response][:items].each_pair do |k, v| - if v.is_a?(Array) - items[k] = v - else - items[k] = [v] - end + items[k] = v.is_a?(Array) ? v : [v] end end items diff --git a/lib/winrm/wsmv/write_stdin.rb b/lib/winrm/wsmv/write_stdin.rb index 98276993..67870934 100644 --- a/lib/winrm/wsmv/write_stdin.rb +++ b/lib/winrm/wsmv/write_stdin.rb @@ -47,10 +47,10 @@ def init_ops(session_opts, stdin_opts) end def validate_opts(session_opts, stdin_opts) - fail 'session_opts is required' unless session_opts - fail 'stdin_opts[:shell_id] is required' unless stdin_opts[:shell_id] - fail 'stdin_opts[:command_id] is required' unless stdin_opts[:command_id] - fail 'stdin_opts[:stdin] is required' unless stdin_opts[:stdin] + raise 'session_opts is required' unless session_opts + raise 'stdin_opts[:shell_id] is required' unless stdin_opts[:shell_id] + raise 'stdin_opts[:command_id] is required' unless stdin_opts[:command_id] + raise 'stdin_opts[:stdin] is required' unless stdin_opts[:stdin] end def stdin_headers diff --git a/tests/integration/powershell_spec.rb b/tests/integration/powershell_spec.rb index 5eaf48bd..2f60a112 100644 --- a/tests/integration/powershell_spec.rb +++ b/tests/integration/powershell_spec.rb @@ -28,12 +28,11 @@ describe 'Math area calculation' do subject(:output) do - @powershell.run(<<-EOH + @powershell.run <<-EOH $diameter = 4.5 $area = [Math]::pow([Math]::PI * ($diameter/2), 2) Write-Host $area EOH - ) end it { should have_exit_code 0 } it { should have_stdout_match(/49.9648722805149/) } diff --git a/tests/spec/spec_helper.rb b/tests/spec/spec_helper.rb index 8d416471..8f5da6c3 100644 --- a/tests/spec/spec_helper.rb +++ b/tests/spec/spec_helper.rb @@ -30,7 +30,7 @@ def default_connection_opts # and remove newlines. class String def unindent - gsub(/^#{self[/\A[ \t]*/]}/, '').gsub("\n", '') + gsub(/^#{self[/\A[ \t]*/]}/, '').delete("\n") end def to_byte_string diff --git a/winrm.gemspec b/winrm.gemspec index 4bf64bb8..ba60c4a6 100644 --- a/winrm.gemspec +++ b/winrm.gemspec @@ -36,6 +36,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'erubis', '~> 2.7' s.add_development_dependency 'rspec', '~> 3.2' s.add_development_dependency 'rake', '~> 10.3' - s.add_development_dependency 'rubocop', '~> 0.28' + s.add_development_dependency 'rubocop', '~> 0.39.0' s.add_development_dependency 'pry' end