summaryrefslogtreecommitdiffstats
path: root/CLI/ruby/spec
diff options
context:
space:
mode:
Diffstat (limited to 'CLI/ruby/spec')
-rw-r--r--CLI/ruby/spec/game_of_life/generators/input_spec.rb49
1 files changed, 49 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
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