diff options
| author | a14m <[email protected]> | 2020-12-02 23:38:29 +0100 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-12-02 23:38:29 +0100 |
| commit | efc0382087bc4315c241f70cd5f0fa7a568dcd52 (patch) | |
| tree | 7e333ab0c3217b557331a664ae51fe36473c6180 /CLI/ruby | |
| parent | 8ba691b78f136b13d9efa58d8e70f4e06c07c2e0 (diff) | |
Add the specs for the input file generator
Diffstat (limited to 'CLI/ruby')
| -rw-r--r-- | CLI/ruby/spec/game_of_life/generators/input_spec.rb | 49 |
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 |
