summaryrefslogtreecommitdiffstats
path: root/CLI/ruby/spec/game_of_life/generators/input_spec.rb
diff options
context:
space:
mode:
authora14m <[email protected]>2020-12-06 16:16:35 +0100
committera14m <[email protected]>2020-12-06 16:16:35 +0100
commitc7a80df29dac0cb5a7b5bd78a750c15fd6146908 (patch)
treef17b19ee2917bddd4d2a1104632c644d98c70ab6 /CLI/ruby/spec/game_of_life/generators/input_spec.rb
parent90eb66f7e34cf6f5a0468e21d3542b20cc668e78 (diff)
Add the error handling for missing/invalid file/URL input
Diffstat (limited to 'CLI/ruby/spec/game_of_life/generators/input_spec.rb')
-rw-r--r--CLI/ruby/spec/game_of_life/generators/input_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/CLI/ruby/spec/game_of_life/generators/input_spec.rb b/CLI/ruby/spec/game_of_life/generators/input_spec.rb
index e05dbfb..6986787 100644
--- a/CLI/ruby/spec/game_of_life/generators/input_spec.rb
+++ b/CLI/ruby/spec/game_of_life/generators/input_spec.rb
@@ -51,5 +51,29 @@ RSpec.describe GameOfLife::Generators::Input do
expect(described_class.new(options).to_s).to eq universe
end
+
+ it "rescues Errno::ENOENT and raises GameOfLife::Error" do
+ options = { "input" => "not-existing-file.txt", "width" => 25, "height" => 2 }
+ expect { described_class.new(options) }.to raise_error(
+ GameOfLife::Error,
+ "File isn't avaialable, please check it again and make sure the path to the input file is correct",
+ )
+ end
+
+ it "rescues SocketError and raises GameOfLife::Error" do
+ options = { "input" => "https://not-existing-url.com", "width" => 25, "height" => 2 }
+ expect { described_class.new(options) }.to raise_error(
+ GameOfLife::Error,
+ "URL isn't avaialable, please check it again and make sure the URL is correct",
+ )
+ end
+
+ it "rescues OpenURI::HTTPError and raises GameOfLife::Error" do
+ options = { "input" => "https://example.com/non-existing", "width" => 25, "height" => 2 }
+ expect { described_class.new(options) }.to raise_error(
+ GameOfLife::Error,
+ "URL isn't avaialable, please check it again and make sure the URL is correct",
+ )
+ end
end
end