diff --git a/lib/paco/index.rb b/lib/paco/index.rb index 93555dd..99bde6d 100644 --- a/lib/paco/index.rb +++ b/lib/paco/index.rb @@ -4,7 +4,7 @@ module Paco # @param [Integer] pos def self.calculate(input:, pos:) raise ArgumentError, "`pos` must be a non-negative integer" if pos < 0 - raise ArgumentError, "`pos` is grater then input length" if pos > input.length + raise ArgumentError, "`pos` is greater then input length" if pos > input.length lines = input[0..pos].lines line = lines.empty? ? 1 : lines.length diff --git a/spec/paco/index_spec.rb b/spec/paco/index_spec.rb index 0a07f63..1f0560b 100644 --- a/spec/paco/index_spec.rb +++ b/spec/paco/index_spec.rb @@ -17,10 +17,16 @@ end it "raises an error when pos < 0" do - expect { index.calculate(input: input, pos: -1) }.to raise_error(ArgumentError) + expect { index.calculate(input: input, pos: -1) }.to raise_error( + ArgumentError, + "`pos` must be a non-negative integer" + ) end it "raises an error when pos > input length" do - expect { index.calculate(input: input, pos: 1000) }.to raise_error(ArgumentError) + expect { index.calculate(input: input, pos: 1000) }.to raise_error( + ArgumentError, + "`pos` is greater then input length" + ) end end