From 33272643ecdc3fb869975fc9d571fb1ac08d4538 Mon Sep 17 00:00:00 2001 From: Caroline Evans Date: Sun, 21 May 2023 22:20:18 +0100 Subject: [PATCH 1/5] first draft of app, still needs refactoring --- .rspec | 1 + Gemfile | 7 +++ Gemfile.lock | 26 +++++++++ app.rb | 113 +++++++++++++++++++++++++++++++++++ spec/app_spec.rb | 139 ++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 98 +++++++++++++++++++++++++++++++ 6 files changed, 384 insertions(+) create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 app.rb create mode 100644 spec/app_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..c99d2e73 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..41df210d --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" + +gem "rspec", "~> 3.12" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..135b57b2 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,26 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.5.0) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + +PLATFORMS + x86_64-darwin-20 + +DEPENDENCIES + rspec (~> 3.12) + +BUNDLED WITH + 2.4.13 diff --git a/app.rb b/app.rb new file mode 100644 index 00000000..ffb74f6e --- /dev/null +++ b/app.rb @@ -0,0 +1,113 @@ +class Application + def initialize(io) + @io = io + @score_table = [] + @total_frames = 10 + @max_rolls = 2 + @last_roll = { + frame: 0, + roll: 0, + pins: 0, + frame_score: 0, + notes: '' + } + @second_last_roll = @last_roll + + end + + def run + run_game + print_result + end + + def run_game + frame = 1 + while frame <= @total_frames do + play_frame(frame) + frame +=1 + end + return @score_table.sum {|roll| roll[:frame_score] } + end + + private + + def play_frame(frame) + roll = 1 + while roll <= @max_rolls do + if @last_roll[:roll] == 1 && @last_roll[:notes] == 'strike' + pins = 0 + else + @io.puts "Frame #{frame}, roll #{roll}: Enter number of knocked down pins:" + pins = @io.gets.chomp.to_i + end + add_score(frame,roll,pins) + if frame == 10 && @last_roll[:notes] == 'spare' + @max_rolls = 3 + elsif frame == 10 && @last_roll[:notes] == 'strike' + @max_rolls = 4 + end + roll += 1 + end + end + + def add_score(frame,roll,pins) + if roll == 1 && pins == 10 + note = 'strike' + elsif roll == 2 && @last_roll[:pins] == 10 + note = 'strike' + elsif roll == 2 && (pins + @last_roll[:pins] == 10) + note = 'spare' + end + + if roll == 2 + frame_score = pins + @last_roll[:pins] + else + frame_score = 0 + end + + if @score_table.length > 1 + if @score_table[-2][:notes] == 'strike' && @score_table[-2][:frame_score] >= 10 + @score_table[-2][:frame_score] += pins + end + + if @score_table.length > 3 + if @score_table[-1][:notes] == 'strike' && @score_table[-1][:frame_score] >= 10 && @score_table[-3][:notes] == 'strike' + @score_table[-3][:frame_score] += pins + end + end + + end + + if @score_table.length > 0 + if (@score_table[-1][:notes] == 'strike' || @score_table[-1][:notes] == 'spare') && @score_table[-1][:frame_score] >= 10 + @score_table[-1][:frame_score] += pins + end + end + + + @last_roll = { + frame: frame, + roll: roll, + pins: pins, + frame_score: frame_score, + notes: note + } + + @score_table << @last_roll + end + + def print_result + @score_table.each{ |entry| + @io.puts entry + } + end + +end + + +if __FILE__ == $0 + app = Application.new( + Kernel + ) + app.run +end \ No newline at end of file diff --git a/spec/app_spec.rb b/spec/app_spec.rb new file mode 100644 index 00000000..55a73aeb --- /dev/null +++ b/spec/app_spec.rb @@ -0,0 +1,139 @@ +require_relative '../app.rb' + +RSpec.describe Application do + it 'will ask for roll input 20 times if no strikes' do + io = double :io + expect(io).to receive(:puts).exactly(20).times + expect(io).to receive(:gets).exactly(20).times.and_return("1") + + app = Application.new(io) + app.run_game + end + + it 'calculates the running score of a game with no strikes or spares' do + io = double :io + expect(io).to receive(:puts).exactly(20).times + expect(io).to receive(:gets).exactly(20).times.and_return("2") + + app = Application.new(io) + + expect(app.run_game).to eq 40 + + end + + it 'will ask for roll input 19 times if one strike' do + io = double :io + expect(io).to receive(:puts).exactly(19).times + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(18).times.and_return("1") + + + app = Application.new(io) + app.run_game + + end + + it 'calculates the running score of a game with 1 strike (not in the 10th frame) and no spares' do + io = double :io + expect(io).to receive(:puts).exactly(19).times + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(18).times.and_return("1") + + app = Application.new(io) + + expect(app.run_game).to eq 30 + + end + + it 'calculates the running score of a game with 1 spare (not in the 10th frame) and no strikes' do + io = double :io + expect(io).to receive(:puts).exactly(20).times + expect(io).to receive(:gets).exactly(1).times.and_return("2") + expect(io).to receive(:gets).exactly(1).times.and_return("8") + expect(io).to receive(:gets).exactly(18).times.and_return("1") + + app = Application.new(io) + + expect(app.run_game).to eq 29 + + end + + it 'calculates the running score of a game with 1 spare in the 10th frame and no strikes' do + io = double :io + expect(io).to receive(:puts).exactly(21).times + expect(io).to receive(:gets).exactly(18).times.and_return("1") + expect(io).to receive(:gets).exactly(1).times.and_return("2") + expect(io).to receive(:gets).exactly(1).times.and_return("8") + expect(io).to receive(:gets).exactly(1).times.and_return("1") + + + app = Application.new(io) + + expect(app.run_game).to eq 29 + + end + + it 'calculates the running score of a game with 1 strike in the 10th frame and no spares' do + io = double :io + expect(io).to receive(:puts).exactly(21).times + expect(io).to receive(:gets).exactly(18).times.and_return("1") + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(1).times.and_return("1") + expect(io).to receive(:gets).exactly(1).times.and_return("1") + + + app = Application.new(io) + + expect(app.run_game).to eq 30 + + end + + it 'calculates the running score of a game with all strikes' do + io = double :io + expect(io).to receive(:puts).exactly(12).times + expect(io).to receive(:gets).exactly(12).times.and_return("10") + + app = Application.new(io) + + expect(app.run_game).to eq 300 + + end + + it 'calculates the running score of a game with all spares' do + io = double :io + expect(io).to receive(:puts).exactly(21).times + expect(io).to receive(:gets).exactly(21).times.and_return("5") + + app = Application.new(io) + + expect(app.run_game).to eq 150 + + end + + it 'calculates the running score of a game with a mix of spares and strikes' do + io = double :io + expect(io).to receive(:puts).exactly(17).times + expect(io).to receive(:gets).exactly(2).times.and_return("5") + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(2).times.and_return("5") + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(2).times.and_return("5") + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(2).times.and_return("5") + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(2).times.and_return("5") + expect(io).to receive(:gets).exactly(1).times.and_return("10") + expect(io).to receive(:gets).exactly(2).times.and_return("5") + + + app = Application.new(io) + + expect(app.run_game).to eq 200 + + end + + + + + +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..c80d44b9 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,98 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From b3ec2a1d89bcb2d37db8d81352d700513515a7a8 Mon Sep 17 00:00:00 2001 From: Caroline Evans Date: Mon, 22 May 2023 13:09:04 +0100 Subject: [PATCH 2/5] re-did code in a new app to make use of a bowling_score_sheet object and frame object, will likely delete old code --- app.rb | 76 ++++++++++++---- lib/bowling_score_sheet.rb | 63 +++++++++++++ lib/frame.rb | 11 +++ spec/app_spec.rb | 31 ++++++- spec/bowling_score_sheet_spec.rb | 151 +++++++++++++++++++++++++++++++ 5 files changed, 314 insertions(+), 18 deletions(-) create mode 100644 lib/bowling_score_sheet.rb create mode 100644 lib/frame.rb create mode 100644 spec/bowling_score_sheet_spec.rb diff --git a/app.rb b/app.rb index ffb74f6e..44ad834f 100644 --- a/app.rb +++ b/app.rb @@ -1,3 +1,43 @@ +require_relative './lib/bowling_score_sheet' + +class BowlingApp + def initialize(io, score_sheet) + @io = io + @score_sheet = score_sheet + end + + def run + self.roll('1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,2') + p self.score + p @score_sheet.all_frames + end + + def roll(string_of_pins) + rolls = string_of_pins.split(',').map { |s| s.to_i } + i = 0 + while i < rolls.length do + @score_sheet.add_roll(rolls[i]) + i += 1 + end + end + + def score + @score_sheet.all_frames.sum do |frame| + frame.round <= 10 ? frame.total_score : 0 + end + end + +end + + +if __FILE__ == $0 + app = BowlingApp.new( + Kernel, + BowlingScoreSheet.new + ) + app.run +end + class Application def initialize(io) @io = io @@ -16,7 +56,7 @@ def initialize(io) end def run - run_game + p run_game print_result end @@ -50,14 +90,8 @@ def play_frame(frame) end end - def add_score(frame,roll,pins) - if roll == 1 && pins == 10 - note = 'strike' - elsif roll == 2 && @last_roll[:pins] == 10 - note = 'strike' - elsif roll == 2 && (pins + @last_roll[:pins] == 10) - note = 'spare' - end + def add_score(frame,roll,pins) + note = get_note(roll,pins) if roll == 2 frame_score = pins + @last_roll[:pins] @@ -84,7 +118,6 @@ def add_score(frame,roll,pins) end end - @last_roll = { frame: frame, roll: roll, @@ -102,12 +135,21 @@ def print_result } end -end + def get_note(roll, pins) + if roll == 1 && pins == 10 + note = 'strike' + elsif roll == 2 && @last_roll[:pins] == 10 + note = 'strike' + elsif roll == 2 && (pins + @last_roll[:pins] == 10) + note = 'spare' + end + end +end -if __FILE__ == $0 - app = Application.new( - Kernel - ) - app.run -end \ No newline at end of file +# if __FILE__ == $0 +# app = Application.new( +# Kernel +# ) +# app.run +# end \ No newline at end of file diff --git a/lib/bowling_score_sheet.rb b/lib/bowling_score_sheet.rb new file mode 100644 index 00000000..17f765a3 --- /dev/null +++ b/lib/bowling_score_sheet.rb @@ -0,0 +1,63 @@ +require_relative 'frame' + +class BowlingScoreSheet + def initialize + @frames = [Frame.new] + end + + def add_roll(pins) + add_bonus_to_previous_frames(pins) + add_score_to_current_frame(pins) + end + + def add_bonus_to_previous_frames(pins) + @frames.each {|frame| + if frame.bonuses > 0 && frame.complete + frame.total_score += pins + frame.bonuses -= 1 + end + } + end + + def add_score_to_current_frame(pins) + current_frame = @frames.last + if current_frame.complete + new_frame = Frame.new + new_frame.round = current_frame.round + 1 + new_frame.score = [pins] + new_frame.total_score = pins + new_frame.complete = false if pins != 10 + set_frame_status(new_frame) + @frames << new_frame + else + current_frame.score << pins + current_frame.total_score += pins + set_frame_status(current_frame) + current_frame.complete = true + end + end + + def all_frames + @frames + end + + private + + def set_frame_status(frame) + if frame.total_score == 10 + if frame.score[0] == 10 + frame.status = 'strike' + frame.bonuses = 2 + else + frame.status = 'spare' + frame.bonuses = 1 + end + end + + end + + + + + +end \ No newline at end of file diff --git a/lib/frame.rb b/lib/frame.rb new file mode 100644 index 00000000..10ca4c77 --- /dev/null +++ b/lib/frame.rb @@ -0,0 +1,11 @@ +class Frame + attr_accessor :round, :score, :total_score, :status, :complete, :bonuses + + def initialize + @complete = true + @round = 0 + @score = 0 + @total_score = 0 + @bonuses = 0 + end +end \ No newline at end of file diff --git a/spec/app_spec.rb b/spec/app_spec.rb index 55a73aeb..81593911 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -1,4 +1,34 @@ require_relative '../app.rb' +require_relative'../lib/bowling_score_sheet.rb' + +RSpec.describe BowlingApp do + it 'calculates the running score of a game with no strikes or spares' do + io = double :io + game = BowlingApp.new(io,BowlingScoreSheet.new) + game.roll('1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1') + expect(game.score).to eq 20 + + game = BowlingApp.new(io,BowlingScoreSheet.new) + game.roll('2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2') + expect(game.score).to eq 40 + + game = BowlingApp.new(io,BowlingScoreSheet.new) + game.roll('2,2,2,2,2,2,2,2,2,2') + game.roll('2,2,2,2,2,2,2,2,2,2') + expect(game.score).to eq 40 + end + + it 'calculates the running score of a game with one spare (not in final frame)' do + io = double :io + game = BowlingApp.new(io,BowlingScoreSheet.new) + game.roll('1,1,2,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1') + expect(game.score).to eq 29 + + end + + +end + RSpec.describe Application do it 'will ask for roll input 20 times if no strikes' do @@ -132,7 +162,6 @@ end - diff --git a/spec/bowling_score_sheet_spec.rb b/spec/bowling_score_sheet_spec.rb new file mode 100644 index 00000000..1dd5652a --- /dev/null +++ b/spec/bowling_score_sheet_spec.rb @@ -0,0 +1,151 @@ +require 'bowling_score_sheet' + +RSpec.describe BowlingScoreSheet do + it 'calculates the running score of a game with no strikes or spares' do + io = double :io + score_sheet = BowlingScoreSheet.new + 20.times do + score_sheet.add_roll(1) + end + + total_score = score_sheet.all_frames.sum do |frame| + frame.total_score + end + expect(total_score).to eq 20 + end + + it 'calculates the running score of a game with a spare (not in final frame) and no strikes' do + io = double :io + score_sheet = BowlingScoreSheet.new + + score_sheet.add_roll(2) + score_sheet.add_roll(8) + + 18.times do + score_sheet.add_roll(1) + end + + total_score = score_sheet.all_frames.sum do |frame| + frame.total_score + end + expect(total_score).to eq 29 + end + + + it 'calculates the running score of a game with a strike (not in final frame) and no spares' do + io = double :io + score_sheet = BowlingScoreSheet.new + + score_sheet.add_roll(10) + score_sheet.add_roll(2) + score_sheet.add_roll(3) + 16.times do + score_sheet.add_roll(1) + end + + total_score = score_sheet.all_frames.sum do |frame| + frame.total_score + end + expect(total_score).to eq 36 + end + + it 'calculates the running score of a game with multiple strikes (not in final frame) and no spares' do + io = double :io + score_sheet = BowlingScoreSheet.new + + score_sheet.add_roll(10) + score_sheet.add_roll(10) + score_sheet.add_roll(2) + score_sheet.add_roll(3) + + 14.times do + score_sheet.add_roll(1) + end + + total_score = score_sheet.all_frames.sum do |frame| + frame.total_score + end + expect(total_score).to eq 56 + end + + it 'calculates the running score of a game with multiple strikes and spares (not in final frame)' do + io = double :io + score_sheet = BowlingScoreSheet.new + + score_sheet.add_roll(10) + score_sheet.add_roll(10) + score_sheet.add_roll(2) + score_sheet.add_roll(8) + score_sheet.add_roll(8) + score_sheet.add_roll(2) + score_sheet.add_roll(10) + + 10.times do + score_sheet.add_roll(1) + end + + total_score = score_sheet.all_frames.sum do |frame| + frame.total_score + end + expect(total_score).to eq 102 + end + + it 'calculates the running score of a game with a strike in final frame' do + io = double :io + score_sheet = BowlingScoreSheet.new + + 18.times do + score_sheet.add_roll(1) + end + score_sheet.add_roll(10) + score_sheet.add_roll(2) + score_sheet.add_roll(3) + + total_score = score_sheet.all_frames.sum do |frame| + frame.round <= 10 ? frame.total_score : 0 + end + expect(total_score).to eq 33 + end + + it 'calculates the running score of a game with a spare in final frame' do + io = double :io + score_sheet = BowlingScoreSheet.new + + 19.times do + score_sheet.add_roll(1) + end + score_sheet.add_roll(9) + score_sheet.add_roll(2) + + total_score = score_sheet.all_frames.sum do |frame| + frame.round <= 10 ? frame.total_score : 0 + end + expect(total_score).to eq 30 + end + + it 'calculates the running score of a game with a mix of spares and stikes' do + io = double :io + score_sheet = BowlingScoreSheet.new + + 10.times do + score_sheet.add_roll(1) + end + + score_sheet.add_roll(10) + score_sheet.add_roll(10) + score_sheet.add_roll(2) + score_sheet.add_roll(8) + score_sheet.add_roll(8) + score_sheet.add_roll(2) + score_sheet.add_roll(10) + score_sheet.add_roll(4) + score_sheet.add_roll(5) + + + total_score = score_sheet.all_frames.sum do |frame| + frame.round <= 10 ? frame.total_score : 0 + end + expect(total_score).to eq 109 + end + +end \ No newline at end of file From 8c81269db59c2f918882fc327d7f2f8d804ff883 Mon Sep 17 00:00:00 2001 From: Caroline Evans Date: Mon, 22 May 2023 13:41:09 +0100 Subject: [PATCH 3/5] refactored code and deleted old app code and logic. --- app.rb | 117 ------------------------------ lib/bowling_score_sheet.rb | 16 ++--- spec/app_spec.rb | 143 ++----------------------------------- 3 files changed, 13 insertions(+), 263 deletions(-) diff --git a/app.rb b/app.rb index 44ad834f..d7b3a28d 100644 --- a/app.rb +++ b/app.rb @@ -9,7 +9,6 @@ def initialize(io, score_sheet) def run self.roll('1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,2') p self.score - p @score_sheet.all_frames end def roll(string_of_pins) @@ -37,119 +36,3 @@ def score ) app.run end - -class Application - def initialize(io) - @io = io - @score_table = [] - @total_frames = 10 - @max_rolls = 2 - @last_roll = { - frame: 0, - roll: 0, - pins: 0, - frame_score: 0, - notes: '' - } - @second_last_roll = @last_roll - - end - - def run - p run_game - print_result - end - - def run_game - frame = 1 - while frame <= @total_frames do - play_frame(frame) - frame +=1 - end - return @score_table.sum {|roll| roll[:frame_score] } - end - - private - - def play_frame(frame) - roll = 1 - while roll <= @max_rolls do - if @last_roll[:roll] == 1 && @last_roll[:notes] == 'strike' - pins = 0 - else - @io.puts "Frame #{frame}, roll #{roll}: Enter number of knocked down pins:" - pins = @io.gets.chomp.to_i - end - add_score(frame,roll,pins) - if frame == 10 && @last_roll[:notes] == 'spare' - @max_rolls = 3 - elsif frame == 10 && @last_roll[:notes] == 'strike' - @max_rolls = 4 - end - roll += 1 - end - end - - def add_score(frame,roll,pins) - note = get_note(roll,pins) - - if roll == 2 - frame_score = pins + @last_roll[:pins] - else - frame_score = 0 - end - - if @score_table.length > 1 - if @score_table[-2][:notes] == 'strike' && @score_table[-2][:frame_score] >= 10 - @score_table[-2][:frame_score] += pins - end - - if @score_table.length > 3 - if @score_table[-1][:notes] == 'strike' && @score_table[-1][:frame_score] >= 10 && @score_table[-3][:notes] == 'strike' - @score_table[-3][:frame_score] += pins - end - end - - end - - if @score_table.length > 0 - if (@score_table[-1][:notes] == 'strike' || @score_table[-1][:notes] == 'spare') && @score_table[-1][:frame_score] >= 10 - @score_table[-1][:frame_score] += pins - end - end - - @last_roll = { - frame: frame, - roll: roll, - pins: pins, - frame_score: frame_score, - notes: note - } - - @score_table << @last_roll - end - - def print_result - @score_table.each{ |entry| - @io.puts entry - } - end - - def get_note(roll, pins) - if roll == 1 && pins == 10 - note = 'strike' - elsif roll == 2 && @last_roll[:pins] == 10 - note = 'strike' - elsif roll == 2 && (pins + @last_roll[:pins] == 10) - note = 'spare' - end - end - -end - -# if __FILE__ == $0 -# app = Application.new( -# Kernel -# ) -# app.run -# end \ No newline at end of file diff --git a/lib/bowling_score_sheet.rb b/lib/bowling_score_sheet.rb index 17f765a3..4e97086e 100644 --- a/lib/bowling_score_sheet.rb +++ b/lib/bowling_score_sheet.rb @@ -10,6 +10,12 @@ def add_roll(pins) add_score_to_current_frame(pins) end + def all_frames + @frames + end + + private + def add_bonus_to_previous_frames(pins) @frames.each {|frame| if frame.bonuses > 0 && frame.complete @@ -37,12 +43,6 @@ def add_score_to_current_frame(pins) end end - def all_frames - @frames - end - - private - def set_frame_status(frame) if frame.total_score == 10 if frame.score[0] == 10 @@ -56,8 +56,4 @@ def set_frame_status(frame) end - - - - end \ No newline at end of file diff --git a/spec/app_spec.rb b/spec/app_spec.rb index 81593911..b4b83435 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -26,143 +26,14 @@ end - -end - - -RSpec.describe Application do - it 'will ask for roll input 20 times if no strikes' do - io = double :io - expect(io).to receive(:puts).exactly(20).times - expect(io).to receive(:gets).exactly(20).times.and_return("1") - - app = Application.new(io) - app.run_game - end - - it 'calculates the running score of a game with no strikes or spares' do - io = double :io - expect(io).to receive(:puts).exactly(20).times - expect(io).to receive(:gets).exactly(20).times.and_return("2") - - app = Application.new(io) - - expect(app.run_game).to eq 40 - - end - - it 'will ask for roll input 19 times if one strike' do - io = double :io - expect(io).to receive(:puts).exactly(19).times - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(18).times.and_return("1") - - - app = Application.new(io) - app.run_game - - end - - it 'calculates the running score of a game with 1 strike (not in the 10th frame) and no spares' do - io = double :io - expect(io).to receive(:puts).exactly(19).times - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(18).times.and_return("1") - - app = Application.new(io) - - expect(app.run_game).to eq 30 - - end - - it 'calculates the running score of a game with 1 spare (not in the 10th frame) and no strikes' do - io = double :io - expect(io).to receive(:puts).exactly(20).times - expect(io).to receive(:gets).exactly(1).times.and_return("2") - expect(io).to receive(:gets).exactly(1).times.and_return("8") - expect(io).to receive(:gets).exactly(18).times.and_return("1") - - app = Application.new(io) - - expect(app.run_game).to eq 29 - - end - - it 'calculates the running score of a game with 1 spare in the 10th frame and no strikes' do - io = double :io - expect(io).to receive(:puts).exactly(21).times - expect(io).to receive(:gets).exactly(18).times.and_return("1") - expect(io).to receive(:gets).exactly(1).times.and_return("2") - expect(io).to receive(:gets).exactly(1).times.and_return("8") - expect(io).to receive(:gets).exactly(1).times.and_return("1") - - - app = Application.new(io) - - expect(app.run_game).to eq 29 - - end - - it 'calculates the running score of a game with 1 strike in the 10th frame and no spares' do + it 'calculates the running score of a game with a mix of spares and stikes' do io = double :io - expect(io).to receive(:puts).exactly(21).times - expect(io).to receive(:gets).exactly(18).times.and_return("1") - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(1).times.and_return("1") - expect(io).to receive(:gets).exactly(1).times.and_return("1") - - - app = Application.new(io) - - expect(app.run_game).to eq 30 - - end - - it 'calculates the running score of a game with all strikes' do - io = double :io - expect(io).to receive(:puts).exactly(12).times - expect(io).to receive(:gets).exactly(12).times.and_return("10") - - app = Application.new(io) - - expect(app.run_game).to eq 300 - - end - - it 'calculates the running score of a game with all spares' do - io = double :io - expect(io).to receive(:puts).exactly(21).times - expect(io).to receive(:gets).exactly(21).times.and_return("5") - - app = Application.new(io) - - expect(app.run_game).to eq 150 - - end - - it 'calculates the running score of a game with a mix of spares and strikes' do - io = double :io - expect(io).to receive(:puts).exactly(17).times - expect(io).to receive(:gets).exactly(2).times.and_return("5") - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(2).times.and_return("5") - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(2).times.and_return("5") - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(2).times.and_return("5") - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(2).times.and_return("5") - expect(io).to receive(:gets).exactly(1).times.and_return("10") - expect(io).to receive(:gets).exactly(2).times.and_return("5") - - - app = Application.new(io) - - expect(app.run_game).to eq 200 + score_sheet = BowlingScoreSheet.new + game = BowlingApp.new(io,BowlingScoreSheet.new) + game.roll('1,1,1,1,1,1,1,1,1,1,10,10,2,8,8,2,10,4,5') + expect(game.score).to eq 109 + end +end - - - -end \ No newline at end of file From 1ea7c56de5816aaaa549ff4e55d0bdddd0a02a4a Mon Sep 17 00:00:00 2001 From: Caroline Evans Date: Mon, 22 May 2023 16:43:17 +0100 Subject: [PATCH 4/5] added user interface to show current results table and to prompt user to keep adding rolls if game is not complete --- app.rb | 18 ++++++++++++++++-- lib/bowling_score_sheet.rb | 12 ++++++++++++ spec/app_spec.rb | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app.rb b/app.rb index d7b3a28d..ede32b5f 100644 --- a/app.rb +++ b/app.rb @@ -7,8 +7,14 @@ def initialize(io, score_sheet) end def run - self.roll('1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,2') - p self.score + while @score_sheet.complete == false + @io.puts "Enter number of knocked down pins separated by commas (eg 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1):" + user_input = @io.gets.chomp + self.roll(user_input) + print_score_sheet + @io.puts "Total: #{self.score}" + end + end def roll(string_of_pins) @@ -26,6 +32,14 @@ def score end end + def print_score_sheet + @score_sheet.all_frames.each do |frame| + if frame.round > 0 && frame.round <= 10 + @io.puts "Frame: #{frame.round}, scores: #{frame.score}, total score: #{frame.total_score}, notes: #{frame.status}" + end + end + end + end diff --git a/lib/bowling_score_sheet.rb b/lib/bowling_score_sheet.rb index 4e97086e..6d55e2ce 100644 --- a/lib/bowling_score_sheet.rb +++ b/lib/bowling_score_sheet.rb @@ -14,6 +14,18 @@ def all_frames @frames end + def complete + frame_10 = @frames.filter { |frame| frame.round == 10} + if frame_10 == [] + false + elsif frame_10[0].complete == true && frame_10[0].bonuses == 0 + true + else + false + end + end + + private def add_bonus_to_previous_frames(pins) diff --git a/spec/app_spec.rb b/spec/app_spec.rb index b4b83435..e8754bbd 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -35,5 +35,7 @@ expect(game.score).to eq 109 end + + end From 2a07ff6c282dd145564990624e55c7ee39a811b6 Mon Sep 17 00:00:00 2001 From: Caroline Evans Date: Mon, 22 May 2023 16:59:08 +0100 Subject: [PATCH 5/5] refactored code --- Gemfile | 6 +- Gemfile.lock | 23 +++++++ app.rb | 19 +++--- lib/bowling_score_sheet.rb | 69 +++++++++++---------- lib/frame.rb | 4 +- spec/app_spec.rb | 23 +++---- spec/bowling_score_sheet_spec.rb | 57 +++++++---------- spec/spec_helper.rb | 102 +++++++++++++++---------------- 8 files changed, 160 insertions(+), 143 deletions(-) diff --git a/Gemfile b/Gemfile index 41df210d..e9dfc3e6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,9 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' # gem "rails" -gem "rspec", "~> 3.12" +gem 'rspec', '~> 3.12' + +gem 'rubocop', '~> 1.51' diff --git a/Gemfile.lock b/Gemfile.lock index 135b57b2..b8760bf9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,15 @@ GEM remote: https://rubygems.org/ specs: + ast (2.4.2) diff-lcs (1.5.0) + json (2.6.3) + parallel (1.23.0) + parser (3.2.2.1) + ast (~> 2.4.1) + rainbow (3.1.1) + regexp_parser (2.8.0) + rexml (3.2.5) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) @@ -15,12 +23,27 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) + rubocop (1.51.0) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.2.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.28.1) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) + unicode-display_width (2.4.2) PLATFORMS x86_64-darwin-20 DEPENDENCIES rspec (~> 3.12) + rubocop (~> 1.51) BUNDLED WITH 2.4.13 diff --git a/app.rb b/app.rb index ede32b5f..a7c909a4 100644 --- a/app.rb +++ b/app.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative './lib/bowling_score_sheet' class BowlingApp @@ -8,19 +10,18 @@ def initialize(io, score_sheet) def run while @score_sheet.complete == false - @io.puts "Enter number of knocked down pins separated by commas (eg 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1):" + @io.puts 'Enter number of knocked down pins separated by commas (eg 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1):' user_input = @io.gets.chomp - self.roll(user_input) + roll(user_input) print_score_sheet - @io.puts "Total: #{self.score}" + @io.puts "Total: #{score}" end - end def roll(string_of_pins) - rolls = string_of_pins.split(',').map { |s| s.to_i } + rolls = string_of_pins.split(',').map(&:to_i) i = 0 - while i < rolls.length do + while i < rolls.length @score_sheet.add_roll(rolls[i]) i += 1 end @@ -34,16 +35,14 @@ def score def print_score_sheet @score_sheet.all_frames.each do |frame| - if frame.round > 0 && frame.round <= 10 + if frame.round.positive? && frame.round <= 10 @io.puts "Frame: #{frame.round}, scores: #{frame.score}, total score: #{frame.total_score}, notes: #{frame.status}" end end end - end - -if __FILE__ == $0 +if __FILE__ == $PROGRAM_NAME app = BowlingApp.new( Kernel, BowlingScoreSheet.new diff --git a/lib/bowling_score_sheet.rb b/lib/bowling_score_sheet.rb index 6d55e2ce..8dce9b2b 100644 --- a/lib/bowling_score_sheet.rb +++ b/lib/bowling_score_sheet.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'frame' class BowlingScoreSheet @@ -15,57 +17,60 @@ def all_frames end def complete - frame_10 = @frames.filter { |frame| frame.round == 10} + frame_10 = @frames.filter { |frame| frame.round == 10 } if frame_10 == [] false - elsif frame_10[0].complete == true && frame_10[0].bonuses == 0 + elsif frame_10[0].complete == true && frame_10[0].bonuses.zero? true - else + else false end end - private def add_bonus_to_previous_frames(pins) - @frames.each {|frame| - if frame.bonuses > 0 && frame.complete + @frames.each do |frame| + if frame.bonuses.positive? && frame.complete frame.total_score += pins frame.bonuses -= 1 end - } + end end def add_score_to_current_frame(pins) current_frame = @frames.last - if current_frame.complete - new_frame = Frame.new - new_frame.round = current_frame.round + 1 - new_frame.score = [pins] - new_frame.total_score = pins - new_frame.complete = false if pins != 10 - set_frame_status(new_frame) - @frames << new_frame - else - current_frame.score << pins - current_frame.total_score += pins - set_frame_status(current_frame) - current_frame.complete = true - end + if current_frame.complete + new_frame = create_new_frame(current_frame, pins) + @frames << new_frame + else + current_frame.score << pins + current_frame.total_score += pins + set_frame_status(current_frame) + current_frame.complete = true + end end - def set_frame_status(frame) - if frame.total_score == 10 - if frame.score[0] == 10 - frame.status = 'strike' - frame.bonuses = 2 - else - frame.status = 'spare' - frame.bonuses = 1 - end - end + def create_new_frame(current_frame, pins) + new_frame = Frame.new + new_frame.round = current_frame.round + 1 + new_frame.score = [pins] + new_frame.total_score = pins + new_frame.complete = false if pins != 10 + set_frame_status(new_frame) + new_frame end -end \ No newline at end of file + def set_frame_status(frame) + return unless frame.total_score == 10 + + if frame.score[0] == 10 + frame.status = 'strike' + frame.bonuses = 2 + else + frame.status = 'spare' + frame.bonuses = 1 + end + end +end diff --git a/lib/frame.rb b/lib/frame.rb index 10ca4c77..bc6ba15f 100644 --- a/lib/frame.rb +++ b/lib/frame.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Frame attr_accessor :round, :score, :total_score, :status, :complete, :bonuses @@ -8,4 +10,4 @@ def initialize @total_score = 0 @bonuses = 0 end -end \ No newline at end of file +end diff --git a/spec/app_spec.rb b/spec/app_spec.rb index e8754bbd..c3eabc43 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -1,18 +1,20 @@ -require_relative '../app.rb' -require_relative'../lib/bowling_score_sheet.rb' +# frozen_string_literal: true + +require_relative '../app' +require_relative '../lib/bowling_score_sheet' RSpec.describe BowlingApp do it 'calculates the running score of a game with no strikes or spares' do io = double :io - game = BowlingApp.new(io,BowlingScoreSheet.new) + game = BowlingApp.new(io, BowlingScoreSheet.new) game.roll('1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1') expect(game.score).to eq 20 - game = BowlingApp.new(io,BowlingScoreSheet.new) + game = BowlingApp.new(io, BowlingScoreSheet.new) game.roll('2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2') expect(game.score).to eq 40 - game = BowlingApp.new(io,BowlingScoreSheet.new) + game = BowlingApp.new(io, BowlingScoreSheet.new) game.roll('2,2,2,2,2,2,2,2,2,2') game.roll('2,2,2,2,2,2,2,2,2,2') expect(game.score).to eq 40 @@ -20,22 +22,17 @@ it 'calculates the running score of a game with one spare (not in final frame)' do io = double :io - game = BowlingApp.new(io,BowlingScoreSheet.new) + game = BowlingApp.new(io, BowlingScoreSheet.new) game.roll('1,1,2,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1') expect(game.score).to eq 29 - end it 'calculates the running score of a game with a mix of spares and stikes' do io = double :io - score_sheet = BowlingScoreSheet.new + BowlingScoreSheet.new - game = BowlingApp.new(io,BowlingScoreSheet.new) + game = BowlingApp.new(io, BowlingScoreSheet.new) game.roll('1,1,1,1,1,1,1,1,1,1,10,10,2,8,8,2,10,4,5') expect(game.score).to eq 109 - end - - end - diff --git a/spec/bowling_score_sheet_spec.rb b/spec/bowling_score_sheet_spec.rb index 1dd5652a..4bae18ac 100644 --- a/spec/bowling_score_sheet_spec.rb +++ b/spec/bowling_score_sheet_spec.rb @@ -1,23 +1,23 @@ +# frozen_string_literal: true + require 'bowling_score_sheet' RSpec.describe BowlingScoreSheet do it 'calculates the running score of a game with no strikes or spares' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new 20.times do score_sheet.add_roll(1) end - total_score = score_sheet.all_frames.sum do |frame| - frame.total_score - end + total_score = score_sheet.all_frames.sum(&:total_score) expect(total_score).to eq 20 end it 'calculates the running score of a game with a spare (not in final frame) and no strikes' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new - + score_sheet.add_roll(2) score_sheet.add_roll(8) @@ -25,17 +25,14 @@ score_sheet.add_roll(1) end - total_score = score_sheet.all_frames.sum do |frame| - frame.total_score - end + total_score = score_sheet.all_frames.sum(&:total_score) expect(total_score).to eq 29 end - it 'calculates the running score of a game with a strike (not in final frame) and no spares' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new - + score_sheet.add_roll(10) score_sheet.add_roll(2) score_sheet.add_roll(3) @@ -43,16 +40,14 @@ score_sheet.add_roll(1) end - total_score = score_sheet.all_frames.sum do |frame| - frame.total_score - end + total_score = score_sheet.all_frames.sum(&:total_score) expect(total_score).to eq 36 end it 'calculates the running score of a game with multiple strikes (not in final frame) and no spares' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new - + score_sheet.add_roll(10) score_sheet.add_roll(10) score_sheet.add_roll(2) @@ -62,16 +57,14 @@ score_sheet.add_roll(1) end - total_score = score_sheet.all_frames.sum do |frame| - frame.total_score - end + total_score = score_sheet.all_frames.sum(&:total_score) expect(total_score).to eq 56 end it 'calculates the running score of a game with multiple strikes and spares (not in final frame)' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new - + score_sheet.add_roll(10) score_sheet.add_roll(10) score_sheet.add_roll(2) @@ -84,16 +77,14 @@ score_sheet.add_roll(1) end - total_score = score_sheet.all_frames.sum do |frame| - frame.total_score - end + total_score = score_sheet.all_frames.sum(&:total_score) expect(total_score).to eq 102 end it 'calculates the running score of a game with a strike in final frame' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new - + 18.times do score_sheet.add_roll(1) end @@ -108,9 +99,9 @@ end it 'calculates the running score of a game with a spare in final frame' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new - + 19.times do score_sheet.add_roll(1) end @@ -124,9 +115,9 @@ end it 'calculates the running score of a game with a mix of spares and stikes' do - io = double :io + double :io score_sheet = BowlingScoreSheet.new - + 10.times do score_sheet.add_roll(1) end @@ -141,11 +132,9 @@ score_sheet.add_roll(4) score_sheet.add_roll(5) - total_score = score_sheet.all_frames.sum do |frame| frame.round <= 10 ? frame.total_score : 0 end expect(total_score).to eq 109 end - -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c80d44b9..4f8c8d91 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause @@ -44,55 +46,53 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ - config.disable_monkey_patching! - - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + # config.disable_monkey_patching! + # + # # This setting enables warnings. It's recommended, but in some cases may + # # be too noisy due to issues in dependencies. + # config.warnings = true + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end