Skip to content

Commit

Permalink
Complete 15a assignment method TheOdinProject#1, partial 2
Browse files Browse the repository at this point in the history
  • Loading branch information
lohikaarme committed Dec 9, 2023
1 parent c8529f8 commit a9b4076
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions spec/15a_binary_game_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,38 +130,60 @@

context 'when user inputs an incorrect value once, then a valid input' do
before do
invalid_input = 'q'
valid_input = '4'
allow(game_input).to receive(:gets).and_return(invalid_input, valid_input)
end

xit 'completes loop and displays error message once' do
it 'completes loop and displays error message once' do
min = game_input.instance_variable_get(:@minimum)
max = game_input.instance_variable_get(:@maximum)
error_message = "Input error! Please enter a number between #{min} or #{max}."
expect(game_input).to receive(:puts).with(error_message).once
game_input.player_input(min, max)
end
end

context 'when user inputs two incorrect values, then a valid input' do
before do
invalid_input = 'q'
valid_input = '4'
allow(game_input).to receive(:gets).and_return(invalid_input, invalid_input, valid_input)
end

xit 'completes loop and displays error message twice' do
it 'completes loop and displays error message twice' do
min = game_input.instance_variable_get(:@minimum)
max = game_input.instance_variable_get(:@maximum)
error_message = "Input error! Please enter a number between #{min} or #{max}."
expect(game_input).to receive(:puts).with(error_message).twice
game_input.player_input(min, max)
end
end
end

# ASSIGNMENT #2

# Create a new instance of BinaryGame and write a test for the following two
# context blocks.
describe '#verify_input' do
subject(:verify_game) { described_class.new(1, 10) }
# Located inside #player_input (Looping Script Method)
# Query Method -> Test the return value

# Note: #verify_input will only return a number if it is between?(min, max)

context 'when given a valid input as argument' do
xit 'returns valid input' do
it 'returns valid input' do
min = verify_game.instance_variable_get(:@minimum)
max = verify_game.instance_variable_get(:@maximum)
expect(verify_game.verify_input(min, max, 4)).to eq(4)
end
end

context 'when given invalid input as argument' do
xit 'returns nil' do
it 'returns nil' do
min = verify_game.instance_variable_get(:@minimum)
max = verify_game.instance_variable_get(:@maximum)
expect(verify_game.verify_input(min, max, 99)).to be_nil
end
end
end
Expand Down

0 comments on commit a9b4076

Please sign in to comment.