diff options
| author | a14m <[email protected]> | 2020-12-03 13:15:00 +0100 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-12-03 13:15:00 +0100 |
| commit | 05730269d4d2d690d871548ae3930d3ce20cdcad (patch) | |
| tree | 91017414194247100352b76d2288fb5da2aeece4 /CLI/ruby/spec | |
| parent | 187b189044b19482879eac3ed63772f3d8d2e000 (diff) | |
Randomize the order and stub constants used
Diffstat (limited to 'CLI/ruby/spec')
| -rw-r--r-- | CLI/ruby/spec/game_of_life/cell_spec.rb | 7 | ||||
| -rw-r--r-- | CLI/ruby/spec/game_of_life/generators/input_spec.rb | 6 | ||||
| -rw-r--r-- | CLI/ruby/spec/spec_helper.rb | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/CLI/ruby/spec/game_of_life/cell_spec.rb b/CLI/ruby/spec/game_of_life/cell_spec.rb index 063fd06..00f55b3 100644 --- a/CLI/ruby/spec/game_of_life/cell_spec.rb +++ b/CLI/ruby/spec/game_of_life/cell_spec.rb @@ -5,19 +5,16 @@ RSpec.describe GameOfLife::Cell do subject(:dead_cell) { described_class.new(x: nil, y: nil, alive: false) } describe "#to_s" do - before(:all) do - described_class.const_set(:LIVE_CELL, "X") - described_class.const_set(:DEAD_CELL, ".") - end - context "when alive" do it "returns LIVE_CELL representation" do + stub_const("LIVE_CELL", "X") expect(living_cell.to_s).to eq "X" end end context "when dead" do it "returns DEAD_CELL representation" do + stub_const("DEAD_CELL", ".") expect(dead_cell.to_s).to eq "." end end 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 cbf3958..e05dbfb 100644 --- a/CLI/ruby/spec/game_of_life/generators/input_spec.rb +++ b/CLI/ruby/spec/game_of_life/generators/input_spec.rb @@ -16,6 +16,8 @@ RSpec.describe GameOfLife::Generators::Input 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"]) + stub_const("GameOfLife::Cell::LIVE_CELL", "X") + stub_const("GameOfLife::Cell::DEAD_CELL", ".") # Conway's Game of Life expect(described_class.new(options).to_s).to eq "XXXXXX.X.XXXX.XX.XXXX" @@ -25,6 +27,8 @@ RSpec.describe GameOfLife::Generators::Input 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"]) + stub_const("GameOfLife::Cell::LIVE_CELL", "X") + stub_const("GameOfLife::Cell::DEAD_CELL", ".") # Conway's Game of Life universe = "XXXXXX.X.XXXX.XX.XXXX....\n" \ @@ -37,6 +41,8 @@ RSpec.describe GameOfLife::Generators::Input 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"]) + stub_const("GameOfLife::Cell::LIVE_CELL", "X") + stub_const("GameOfLife::Cell::DEAD_CELL", ".") # Conway's Ga universe = "XXXXXX.X.XX\n" \ diff --git a/CLI/ruby/spec/spec_helper.rb b/CLI/ruby/spec/spec_helper.rb index b65df8e..890ca34 100644 --- a/CLI/ruby/spec/spec_helper.rb +++ b/CLI/ruby/spec/spec_helper.rb @@ -10,6 +10,8 @@ RSpec.configure do |config| # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! + config.order = :random + config.expect_with :rspec do |c| c.syntax = :expect end |
