-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
Typo and details #29156
base: main
Are you sure you want to change the base?
Typo and details #29156
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ leapyears | |
leapYears | ||
falsy | ||
warmup | ||
procs | ||
enumerables | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
We will once again be working from the `odin_rspec` project we set up in the previous lesson. To get the most out this lesson, please follow along with all the examples. | ||
|
||
### Learning Outcomes | ||
Check failure on line 7 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesRequired heading structure
|
||
|
||
- What is a before hook and what phase of a test should you use it for? | ||
- What is an after hook and phase of a test should you use it for? | ||
|
@@ -21,7 +21,7 @@ | |
|
||
To see this in action, create a new file in the lib directory of your `odin_rspec` project named `user.rb` and paste the following code into it: | ||
|
||
~~~ruby | ||
Check failure on line 24 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
# lib/user.rb | ||
|
||
class User | ||
|
@@ -37,11 +37,11 @@ | |
age >= 65 | ||
end | ||
end | ||
~~~ | ||
Check failure on line 40 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
|
||
Next, create a test file for the user class in the spec directory named `user_spec.rb` and write the following tests for the `User` class to exercise the name, email and age attributes: | ||
|
||
~~~ruby | ||
~~~~ruby | ||
Check failure on line 44 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code fences need to be wrapped with 3 tildes, not 4. This seems like an incorrect change. |
||
# spec/user_spec.rb | ||
|
||
require "spec_helper" | ||
|
@@ -74,7 +74,7 @@ | |
end | ||
|
||
end | ||
~~~ | ||
Check failure on line 77 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
|
||
Run the tests to make sure everything is wired together correctly. We can run just the tests for this user class by passing the test file name to the `rspec` command: `$rspec spec/user_spec.rb` . | ||
|
||
|
@@ -84,7 +84,7 @@ | |
|
||
In our case, we can include a before hook that will create a new `User` instance and assign that instance to a `@user` instance variable that we can use in each of our tests: | ||
|
||
~~~ruby | ||
Check failure on line 87 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
# spec/user_spec.rb | ||
|
||
require "spec_helper" | ||
|
@@ -115,18 +115,18 @@ | |
end | ||
|
||
end | ||
~~~ | ||
Check failure on line 118 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
|
||
By default, before hooks run *before* each test in the same example group. We can see this a bit more clearly by including a puts statement in our before hook: | ||
|
||
~~~ruby | ||
Check failure on line 122 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
# spec/user_spec.rb | ||
|
||
before do | ||
puts "running the before hook" | ||
@user = User.new("David", "[email protected]", 30) | ||
end | ||
~~~ | ||
Check failure on line 129 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
|
||
Now, when we run our tests again we should see "running the before hook" printed to the screen three times, once for each of our tests. | ||
|
||
|
@@ -134,7 +134,7 @@ | |
|
||
Change the before hook to the following and run the tests. The puts statement will only print once in the terminal, proving the before block was only executed once. | ||
|
||
~~~ruby | ||
Check failure on line 137 in ruby/automated_testing/rspec_part_two_code_sharing.md GitHub Actions / Lint lesson filesFenced code blocks should use backticks instead of tildes
|
||
# spec/user_spec.rb | ||
|
||
before(:all) do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
So far you’ve been learning how to test code that you’ve written, but there’s a popular development process that flips that concept on its head. Rather than writing code, manually testing it until you get it working, then writing a test to make sure it stays working; you can write the test **before** the code, so that you don’t have to waste *any* time manually testing. Test Driven Development is the name of this inverted development process. | ||
|
||
### Learning Outcomes | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. |
||
Look through these now and use them to guide your learning. By the end of this lesson, expect to: | ||
|
||
- Learn what Test Driven Development is | ||
|
@@ -30,6 +31,7 @@ This development cycle is known as red-green-refactor, and it’s at the heart o | |
One key aspect of the red-green-refactor cycle that *isn’t* in the name, is that the code you write to go from `red` to `green` should be the **minimum** amount required to pass the test. If you find that the functionality you’re adding actually does *more* than is being tested, that is a sign that your method is likely doing too much, or possibly that your tests aren’t testing all of the right functionality. | ||
|
||
#### TDD Examples | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. |
||
Let’s walk through a TDD approach to a basic class. | ||
|
||
Given the general problem: | ||
|
@@ -210,6 +212,7 @@ TODO: Exercise: TDD a value object | |
TODO: Exercise: TDD a class that has a collaborator which doesn't exist yet using mocks | ||
|
||
### Additional Resources | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. |
||
This section contains helpful links to other content. It isn't required, so consider it supplemental. | ||
|
||
Read ["TDD is Dead. Long Live Testing"](http://david.heinemeierhansson.com/2014/tdd-is-dead-long-live-testing.html) by DHH for an anti-TDD viewpoint | ||
|
@@ -218,7 +221,7 @@ Read ["TDD is Dead. Long Live Testing"](http://david.heinemeierhansson.com/2014/ | |
|
||
This section contains questions for you to check your understanding of this lesson. If you’re having trouble answering the questions below on your own, review the material above to find the answer. | ||
|
||
- What does it mean for code to be test **driven**? | ||
- List four different advantages of TDD. | ||
- What is the 3 part development cycle used for TDD? | ||
- How much code should be written when going from the `red` state to the `green` state of the red-green-refactor cycle? | ||
- [What does it mean for code to be test **driven**?](#what-is-tdd-and-why-do-it) | ||
- [List four different advantages of TDD](#what-is-tdd-and-why-do-it) | ||
- [What is the 3 part development cycle used for TDD?](#what-is-tdd-and-why-do-it) | ||
- [How much code should be written when going from the `red` state to the `green` state of the red-green-refactor cycle?](#what-is-tdd-and-why-do-it) | ||
Comment on lines
+224
to
+227
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having link backs in the Knowledge Check section is good, but if they all point to the same section, then they might cause confusion when they all end up at the same place. Additionally, you've missed a period at the end of the second check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Because and This PR sections of the PR don't explain what this change is doing. Can you elaborate on this?