From efc0382087bc4315c241f70cd5f0fa7a568dcd52 Mon Sep 17 00:00:00 2001 From: a14m Date: Wed, 2 Dec 2020 23:38:29 +0100 Subject: Add the specs for the input file generator --- .../spec/game_of_life/generators/input_spec.rb | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 CLI/ruby/spec/game_of_life/generators/input_spec.rb (limited to 'CLI/ruby/spec') diff --git a/CLI/ruby/spec/game_of_life/generators/input_spec.rb b/CLI/ruby/spec/game_of_life/generators/input_spec.rb new file mode 100644 index 0000000..cbf3958 --- /dev/null +++ b/CLI/ruby/spec/game_of_life/generators/input_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +RSpec.describe GameOfLife::Generators::Input do + describe ".new" do + let(:file) { instance_double(File) } + + it "returns a GameOfLife::Universe" do + options = { "input" => "something", "width" => 1, "height" => 1 } + allow(URI).to receive(:open).and_return(file) + allow(file).to receive(:read).and_return(options["input"]) + + expect(described_class.new(options)).to be_a GameOfLife::Universe + end + + it "parses alpha-numeric characters as living cells" do + options = { "input" => "Conway's Game of Life", "width" => 21, "height" => 1 } + allow(URI).to receive(:open).and_return(file) + allow(file).to receive(:read).and_return(options["input"]) + + # Conway's Game of Life + expect(described_class.new(options).to_s).to eq "XXXXXX.X.XXXX.XX.XXXX" + end + + it "fills the rest of universe with dead cells" do + options = { "input" => "Conway's Game of Life", "width" => 25, "height" => 2 } + allow(URI).to receive(:open).and_return(file) + allow(file).to receive(:read).and_return(options["input"]) + + # Conway's Game of Life + universe = "XXXXXX.X.XXXX.XX.XXXX....\n" \ + "........................." + + expect(described_class.new(options).to_s).to eq universe + end + + it "truncates the content of the file to match the width" do + options = { "input" => "Conway's Game of Life", "width" => 11, "height" => 3 } + allow(URI).to receive(:open).and_return(file) + allow(file).to receive(:read).and_return(options["input"]) + + # Conway's Ga + universe = "XXXXXX.X.XX\n" \ + "...........\n" \ + "..........." + + expect(described_class.new(options).to_s).to eq universe + end + end +end -- cgit v1.2.3