Skip to content

Basic RPS program - JM - #257

Open
jormark wants to merge 1 commit into
makersacademy:mainfrom
jormark:main
Open

Basic RPS program - JM#257
jormark wants to merge 1 commit into
makersacademy:mainfrom
jormark:main

Conversation

@jormark

@jormark jormark commented Jul 11, 2022

Copy link
Copy Markdown

Basic Rock, Paper, Scissors program - quite limited testing, but it works properly!

@HanzAkor HanzAkor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful application. Works really well. Just add more tests to cover every possible scenario.

Comment thread app.rb
erb(:result)
end

def pick_winner(player, opponent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested if statement could be optimised better. Maybe use a hash.
Also, put this in a class file and instantiate in the app file to keep it more tidy.

scenario "When I select 'Rock', I will lose if the machine selects 'Paper'" do
allow_any_instance_of(@opponent_choice).to receive(:sample).and_return(:paper)
visit '/'
fill_in('name', with: 'Jordan')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a web_helpers page where you can create a separate method and call it here, to keep the test more tidy and avoid repeating too many lines.

Comment thread views/result.erb

<h2>You picked <%= @user_choice %>, and your opponent picked <%= @opponent_choice %></h2>

<form action="/" method="get">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirect to the game and keep the user's name so that they don't need to keep entering it again.
Enabling sessions will help with this:
https://github.com/makersacademy/course/blob/main/apprenticeships_intro_to_the_web/walkthroughs/post_redirect_get_pattern.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants