You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,7 @@ The next line:
115
115
116
116
is the RSpec language and can basically be ignored for now beyond the actual semantics and meaning. We are simply saying, via valid Ruby, that this test describes the `current_age_for_birth_year` method.
117
117
118
-
The only things that are required in this line of code are the `describe` RSpec method and the Ruby `do` keyword, the rest of this line is entirely arbitrary and of our own design. After all `current_age_for_birth_year method`, is a String of data and could not possibly matter to Ruby because it is not interpreted, it's just data.
118
+
The only things that are required in this line of code are the `describe` RSpec method and the Ruby `do` keyword, the rest of this line is entirely arbitrary and of our own design. After all,`current_age_for_birth_year method` is a String of data and could not possibly matter to Ruby because it is not interpreted, it's just data.
119
119
120
120
When we write tests we use the `describe` RSpec method and strings to describe what we are testing. This code is entirely for you, the programmer, and has very little meaning to RSpec or Ruby.
121
121
@@ -165,7 +165,7 @@ end
165
165
166
166
**A test is always going to be about setting up a state with a known result and comparing that known result or expectation to the behavior of your program, thus ensuring that your program behaves as you expected.**
167
167
168
-
There are many kind of tests, and test-driven development and RSpec are very complex topics. Just focus on the semantics and meaning of the `*_spec.rb` files for now. It's a tremendously valuable skill to be introduced to this early.
168
+
There are many kinds of tests, and test-driven development and RSpec are very complex topics. Just focus on the semantics and meaning of the `*_spec.rb` files for now. It's a tremendously valuable skill to be introduced to this early.
returns the age of a person based on the year of birth (FAILED - 1)
211
211
```
212
212
213
-
Those lines are summaries of what we are testing and what failed. They correspond directly to the strings provided to `describe` and `it` and are simply there to provide context.
213
+
Those lines are summaries of what we are testing and what failed. They correspond directly to the strings provided to `describe` and `it`, and they are simply there to provide context.
214
214
215
215
```bash
216
216
1) current_age_for_birth_year method returns the age of a person based on the year of birth
@@ -242,7 +242,7 @@ The above line raises the line of code in our test suite that created the failur
242
242
# ./spec/current_age_for_birth_year_spec.rb:5:in `block (2 levels) in <top (required)>'
243
243
```
244
244
245
-
Before writing any code, our test suite is failing because a line of code within it:
245
+
Before writing any code, our test suite is failing because of a line of code within it:
@@ -254,13 +254,13 @@ It's totally cool to have errors—a big part of programming is simply getting p
254
254
255
255
### Reading Errors And Making Our Tests Pass
256
256
257
-
So, we conceptually understand what we're trying to build, a method called `current_age_for_birth_year`, that when given an argument of a year of birth, `current_age_for_birth_year(1984)`, returns the age of a person, `31`. Our test suite actually tries to execute this code and compares the result of it to the desired outcome, failing until the expectation and the outcome are equal.
257
+
So, we conceptually understand what we're trying to build: a method called `current_age_for_birth_year`, that when given an argument of a year of birth, `current_age_for_birth_year(1984)`, returns the age of a person, `31`. Our test suite actually tries to execute this code and compares the result of it to the desired outcome, failing until the expectation and the outcome are equal.
258
258
259
-
The first error thrown by the test suite is that our code, defined in `current_age_for_birth_year.rb`, should have defined a method called `current_age_for_birth_year`, but did not resulting in a `NoMethodError`.
259
+
The first error thrown by the test suite is that our code, defined in `current_age_for_birth_year.rb`, should have defined a method called `current_age_for_birth_year`, but did not, resulting in a `NoMethodError`.
260
260
261
261
Let's fix this error by defining a method in`current_age_for_birth_year.rb` called `current_age_for_birth_year`.
262
262
263
-
Add the following to the file:`current_age_for_birth_year.rb`
263
+
Add the following to the file,`current_age_for_birth_year.rb`:
264
264
265
265
```ruby
266
266
def current_age_for_birth_year
@@ -280,7 +280,7 @@ Save the file and go back to your terminal and run the `learn` command. You'll s
280
280
281
281
#### `ArgumentError:`
282
282
283
-
Our tests are still failing, but for a new reason. Previously we lacked the method definition. Now we have the method defined, however, our tests are complaining that the line of code `age_of_person = current_age_for_birth_year(1984)` invoked the method `current_age_for_birth_year` incorrectly because it called that method with an argument but the method *we* defined does not accept an argument.
283
+
Our tests are still failing, but for a new reason. Previously we lacked the method definition. Now we have the method defined; however, our tests are complaining that the line of code,`age_of_person = current_age_for_birth_year(1984)`, invoked the method `current_age_for_birth_year` incorrectly because it called that method with an argument but the method *we* defined does not accept an argument.
284
284
285
285
This results in an `ArgumentError`.
286
286
@@ -361,9 +361,9 @@ Run this program with `ruby how_old_are_you.rb`. There shouldn't be any errors i
361
361
362
362
What this program does is load the code in our original program `current_age_for_birth_year.rb`. It then prints the string `"What year were you born?"`. It prompts the user for input via the `gets` method and converts the input to an integer with `to_i`.
363
363
364
-
The program then invokes (or calls) the method `current_age_for_birth_year`. The cool part is that this method is not defined within this file, rather, it was defined in a singular, simple file, and just loaded and used in this more complex program. That's the heart of abstraction and encapsulation; `how_old_are_you.rb` doesn't need to know how `current_age_for_birth_year.rb` works, it just gets to load the code and rely that it behaves as expected and defined in the tests for that library.
364
+
The program then invokes (or calls) the method `current_age_for_birth_year`. The cool part is that this method is not defined within this file, rather, it was defined in a singular, simple file, and just loaded and used in this more complex program. That's the heart of abstraction and encapsulation: `how_old_are_you.rb` doesn't need to know how `current_age_for_birth_year.rb` works, it just gets to load the code and trusts that it behaves as expected, as it was defined in the tests for that library.
365
365
366
-
This is the architecture of real applications. Each file is a singular, simple, component or "unit of work". The files are loaded together by an execution file and the discrete units execute together to make complex and amazing applications.
366
+
This is the architecture of real applications. Each file is a singular, simple component or "unit of work". The files are loaded together by an execution file and the discrete units execute together to make complex and amazing applications.
367
367
368
368
#### Our Tests Are Only Temporarily Correct
369
369
@@ -400,7 +400,7 @@ That would be a better implementation of `current_age_for_birth_year` as it is m
400
400
401
401
## Conclusion
402
402
403
-
Remember, for now you are not being asked to write your own tests. The important take away here is how to *read* tests and understand error messages that get outputted as a result of running them. You can refer back to earlier lessons (see below) to review those skills.
403
+
Remember, for now, you are not being asked to write your own tests. The important take away here is how to *read* tests and understand error messages that get outputted as a result of running them. You can refer back to earlier lessons (see below) to review those skills.
0 commit comments