Skip to content

Testing Ruby with RSpec: Split apart Ruby's Connect Four assignment into 3 separate files #29665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ruby/testing_ruby_with_rspec/practice_rspec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Introduction

Before getting into any big projects, you should have some practice with writing tests in RSpec. Learning is best done through doing after all! There are a lot of tests to go through and you have to refer to multiple files, but make sure to not feel too overwhelmed. We're all in this together!

For this section, you're first going to complete a lot of exercises involving test-writing, and then finally implementing tests into an old you've written.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
For this section, you're first going to complete a lot of exercises involving test-writing, and then finally implementing tests into an old you've written.
For this section, you're first going to complete a lot of exercises involving test-writing, and then finally implementing tests into an old project you've written.

Missing word here.


### Assignment

Check failure on line 7 in ruby/testing_ruby_with_rspec/practice_rspec.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Required heading structure

ruby/testing_ruby_with_rspec/practice_rspec.md:7 TOP004/lesson-headings Required heading structure [Expected: ### Lesson overview; Actual: ### Assignment] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP004.md

<div class="lesson-content__panel" markdown="1">

1. Clone our [ruby testing repo](https://github.com/TheOdinProject/ruby_testing) and complete the lessons in the spec folder.
1. Go back to the [Caesar Cipher Project](/lessons/ruby-caesar-cipher) and write tests for your code. It shouldn't take more than a half-dozen tests to cover all the possible cases. As always, use the git workflow you learned in [Revisiting Rock Paper Scissors](https://www.theodinproject.com/lessons/foundations-revisiting-rock-paper-scissors) to work on a new feature so you can work on your new code without fear.

</div>

### Additional resources

This section contains helpful links to related content. It isn't required, so consider it supplemental.

- Stack Overflow has an [RSpec Mock Object example](http://stackoverflow.com/questions/3622604/rspec-mock-object-example).
- Youtube has a [helpful video by Sandi Metz about Ruby testing](https://www.youtube.com/watch?v=URSWYvyc42M).
- Tutorials Point has an article about [RSpec Writing Specs](https://www.tutorialspoint.com/rspec/rspec_writing_specs.htm).
19 changes: 2 additions & 17 deletions ruby/testing_ruby_with_rspec/project_connect_four.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
### Introduction

A good way to get familiar with and begin contributing to a new project is to write tests for it. It's also the best way to become familiar with a new code base, something you'll have to do when you start working. It's pretty common for test code to ultimately take up twice as many lines of code as the actual project code!

You still may feel shaky on RSpec at this point (which is totally normal), so let's go back in time and write tests for some of the code you've already done to build up a bit of muscle memory. If you've written a good batch, submit them below and we'll include them as part of the original project description to help future students!

### Assignment

<div class="lesson-content__panel" markdown="1">

1. Clone our [ruby testing repo](https://github.com/TheOdinProject/ruby_testing) and complete the lessons in the spec folder.
1. Go back to the [Caesar Cipher Project](/lessons/ruby-caesar-cipher) and write tests for your code. It shouldn't take more than a half-dozen tests to cover all the possible cases. As always, use the git workflow you learned in [Revisiting Rock Paper Scissors](https://www.theodinproject.com/lessons/foundations-revisiting-rock-paper-scissors) to work on a new feature so you can work on your new code without fear.
1. Write tests for your [Tic Tac Toe project](/lessons/ruby-tic-tac-toe). In this situation, it's not quite as straightforward as just coming up with inputs and making sure the method returns the correct thing. You'll need to make sure the tests that determine victory or loss conditions are correctly assessed.
1. Start by writing tests to make sure players win when they should, e.g. when the board reads X X X across the top row, your `#game_over` method (or its equivalent) should trigger.
1. Test each of your critical methods to make sure they function properly and handle edge cases.
1. Use mocks/doubles to isolate methods to make sure that they're sending back the right outputs.

</div>
At this point, you've written tests for older projects of yours, and have completed a plethora of other test-writign assignments to familiarize yourself with RSpec. You're now ready to create a new project with TDD in mind!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
At this point, you've written tests for older projects of yours, and have completed a plethora of other test-writign assignments to familiarize yourself with RSpec. You're now ready to create a new project with TDD in mind!
At this point, you've written tests for older projects of yours, and have completed a plethora of other test-writing assignments to familiarize yourself with RSpec. You're now ready to create a new project with TDD in mind!


### Project: TDD Connect Four

Expand All @@ -27,7 +12,7 @@ The major difference here is that you'll be doing this TDD-style. So figure out

Only write exactly enough code to make your test pass. Oftentimes, you'll end up having to write two tests in order to make a method do anything useful. That's okay here. It may feel a bit like overkill, but that's the point of the exercise. Your thoughts will probably be something like "Okay, I need to make this thing happen. How do I test it? Okay, wrote the test, how do I code it into Ruby? Okay, wrote the Ruby, how can I make this better?" You'll find yourself spending a fair bit of time Googling and trying to figure out exactly how to test a particular bit of functionality. That's also okay... You're really learning RSpec here, not Ruby, and it takes some getting used to.

### Assignment continued
### Assignment

<div class="lesson-content__panel" markdown="1">

Expand Down
23 changes: 23 additions & 0 deletions ruby/testing_ruby_with_rspec/revisiting_tictactoe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Introduction

Check failure on line 1 in ruby/testing_ruby_with_rspec/revisiting_tictactoe.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Headings should be surrounded by blank lines

ruby/testing_ruby_with_rspec/revisiting_tictactoe.md:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Introduction"] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md022.md
Now you have some experience with writing tests. Congratulations! Practice makes perfect, so here's another assignment.

This time, you're going to go back to your Tic Tac Toe assignment and write tests for it.

### Assignment

Check failure on line 6 in ruby/testing_ruby_with_rspec/revisiting_tictactoe.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Required heading structure

ruby/testing_ruby_with_rspec/revisiting_tictactoe.md:6 TOP004/lesson-headings Required heading structure [Expected: ### Lesson overview; Actual: ### Assignment] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP004.md

<div class="lesson-content__panel" markdown="1">

1. Write tests for your [Tic Tac Toe project](/lessons/ruby-tic-tac-toe). In this situation, it's not quite as straightforward as just coming up with inputs and making sure the method returns the correct thing. You'll need to make sure the tests that determine victory or loss conditions are correctly assessed.
1. Start by writing tests to make sure players win when they should, e.g. when the board reads X X X across the top row, your `#game_over` method (or its equivalent) should trigger.
1. Test each of your critical methods to make sure they function properly and handle edge cases.
1. Use mocks/doubles to isolate methods to make sure that they're sending back the right outputs.

</div>

### Additional resources

This section contains helpful links to related content. It isn't required, so consider it supplemental.

- Stack Overflow has an [RSpec Mock Object example](http://stackoverflow.com/questions/3622604/rspec-mock-object-example).
- Youtube has a [helpful video by Sandi Metz about Ruby testing](https://www.youtube.com/watch?v=URSWYvyc42M).
- Tutorials Point has an article about [RSpec Writing Specs](https://www.tutorialspoint.com/rspec/rspec_writing_specs.htm).
Loading