Skip to content

Commit ea816ab

Browse files
akanshmurthytjgrathwell
authored andcommitted
correct grammar and integrate all pages to one story
1 parent 66938c3 commit ea816ab

File tree

5 files changed

+67
-55
lines changed

5 files changed

+67
-55
lines changed

sites/en/testing/additional_concepts.step

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ message <<-MARKDOWN
44
### Doubles and stubs
55
Doubles are simpler objects that represent objects from your application.
66
<div class="console"><pre>
7-
post = double(:post)
7+
orange = double(:orange)
88
</pre>
99
</div>
10-
If you instantiate that double in your test file, you have access to post in your tests to test with. This is instead of creating an entire Post model in ActiveRecord. If you need to create many different test objects with different properties, FactoryGirl is a great gem for that purpose and will allow persistence or in-memory object creation, depending on your testing situation.
10+
If you instantiate that double in your test file, you have access to orange in your tests to test with. This is instead of creating an entire Orange model in ActiveRecord. If you need to create many different test objects with different properties, FactoryGirl is a great gem for that purpose and will allow persistence or in-memory object creation, depending on your testing situation.
1111

1212
Stubs can be used to dictate what is returned when a method is called on a double.
1313
<div class="console"><pre>
14-
post.stub(:title).and_return("Jelly")
14+
orange.stub(:name).and_return("Florida Orange")
1515
</pre>
1616
</div>
17-
So, when you write a test that calls the title attribute of the post double, you'll always get back the string Jelly. Got it? Good!
17+
So, when you write a test that calls the title attribute of the orange double, you'll always get back the string Florida Orange. Got it? Good!
1818

1919
### Spies
2020
With spies, we are not talking about espionage... at least, not in relation to testing :) Spies can be used to verify whether a method was called on an object.
21-
For instance (assume you already have the post double from above):
21+
For instance (assume you already have the orange double from above):
2222
<div class="console"><pre>
23-
post = spy('post')
24-
post.content
25-
expect(post).to have_received(:content)
23+
orange = spy('orange')
24+
orange.name
25+
expect(orange).to have_received(:name)
2626
</pre>
2727
</div>
28-
Obviously, this is a simplified case. Instead of post.content, you might have a complicated method that executes many functions internally and that's where spies can come in handy; they can check easily whether one specific method was called. Capiche? Ok, let's keep on trucking!
28+
Obviously, this is a simplified case. Instead of orange.name, you might have a complicated method that executes many functions internally and that's where spies can come in handy; they can check easily whether one specific method was called. Capiche? Ok, let's keep on trucking!
2929

3030
### Webmock
3131
What if your app relies on third-party services or applications, known amongst friends as application programming interfaces or APIs? Well, it seems like APIs should also be tested but should our test suite really be dependent on someone else? NOPE! What if the API goes down? Or is slow? Welcome to the stage: Webmock!
@@ -37,7 +37,7 @@ WebMock.disable_net_connect!(allow_localhost: true)
3737
RUBY
3838

3939
message <<-MARKDOWN
40-
Then, you can start stubbing out API requests in your spec helper file. Let's write an example for Bitly, a service that shortens long URLs.
40+
Then, you can start stubbing out API requests in your spec helper file. Let's write an example for Bitly, a service that shortens long URLs. This may come in handy when you want to provide external links to info pages about the different types of oranges in your orange tree but the links are too long to display on a line.
4141
MARKDOWN
4242

4343
console_without_message <<-RUBY
@@ -53,5 +53,7 @@ RUBY
5353
message <<-MARKDOWN
5454
So, if you write any tests in your test files that call the Bitly API, then the response will be whatever you defined above. The test will prevent the actual API request from being made. Pretty cool, huh?
5555

56-
Awesome, you are now equipped with a license to TEST! Go forth and create doubles, stubs, and spies in your app (at least one of each and have a TA verify).
56+
Awesome, you are now equipped with a license to TEST! Go forth and create doubles, stubs, and spies in your app (at least one of each and have a TA verify). And, if you have time for a final challenge (optional), click below...
5757
MARKDOWN
58+
59+
next_step "final_challenge"

sites/en/testing/final_challenge.step

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
message <<-MARKDOWN
2+
3+
Congratulations! Take a second and give yourself a pat on your back. You've come far, my young padawan. This is the final test (no pun intended haha!) :)
4+
5+
# The final challenge
6+
Essentially, you will clone a repo (link is below) that has broken tests and fix all the broken tests. The broken tests will consist of a variety of different types of tests, incorporating everything you have learned thus far. Good luck, keep calm, and test on!
7+
8+
MARKDOWN

sites/en/testing/testing_frameworks.step

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
message <<-MARKDOWN
22
# What's a testing framework?
3-
A testing framework is an execution environment for automated tests. Think of it as the set of assumptions that reminds you when you veer away from those assumptions. In short Test frameworks helps teams organize their test suites and in turn
4-
help improve the efficiency of testing.
3+
A testing framework is an execution environment for automated tests. Testing frameworks help teams organize their test suites and in turn
4+
help improve the efficiency of testing.
55

66
# Types of testing frameworks
7-
There are many testing frameworks that work great. Mini Test is the default testing framework in Rails 5. However, we will be using the RSpec testing framework instead.
7+
There are many testing frameworks that work great. Mini Test is the default testing framework in Rails 5. However, we will be using the RSpec testing framework instead.
88

99

1010
# RSpec
1111
## How to set up RSpec in Rails
1212

13-
Add rspec-rails to both the :development and :test groups in the Gemfile:
13+
First, create a new Rails app. Then, add rspec-rails to both the :development and :test groups in the Gemfile:
1414

1515
<div class="console"><pre>
1616
group :development, :test do
@@ -48,7 +48,7 @@ bundle exec rspec
4848
</pre>
4949
</div>
5050

51-
By default the above will run all spec files in the spec directory.
51+
By default, the above code will run all spec files in the spec directory.
5252

5353
To run only a subset of these specs use the following command:
5454

@@ -67,8 +67,8 @@ bundle exec rspec spec/controllers/post_controller_spec.rb
6767
1 describe Tree do
6868
2 it "is able to age by 1 year increments" do
6969
3 orange_tree = Tree.new
70-
4 orange_tree.age
71-
5 expect(orange_tree.age).to eq(1)
70+
4 orange_tree.age
71+
5 expect(orange_tree.age).to eq(1)
7272
6 end
7373
7 end
7474
</pre>
@@ -92,7 +92,7 @@ Check out the other built-in matchers!
9292
https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
9393

9494
# Mini Test
95-
In case you were curious to see how tests are written in Mini Test. Mini Test also allows you to write tests in 'expectation style' which is very similar to how RSpec tests are written.
95+
In case you were curious to see how tests are written in Mini Test. Mini Test also allows you to write tests in 'expectation style' which is very similar to how RSpec tests are written.
9696

9797
<div class="console">
9898
<pre>

sites/en/testing/types_of_tests.step

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,64 @@ message <<-MARKDOWN
33

44
In your Rails app, you have models, views, and controllers -> is MVC ringing a bell? :) Well, it should be no surprise that tests can be written for models, views, and controllers.
55

6-
Take a look at the following Post model in your app:
6+
Create the Orange and Tree models in your app so that the model files are something like this:
77

88
<div class="console"><pre>
9-
class Post < ActiveRecord::Base
10-
belongs_to :user
11-
has_many :replies
12-
validates :title, :user_id, :content, presence: true
9+
class Orange < ActiveRecord::Base
10+
belongs_to :tree
11+
validates :name, :tree_id, presence: true
12+
end
13+
14+
class Tree < ActiveRecord::Base
15+
has_many :oranges
16+
validates :name, presence: true
1317
end
1418
</pre>
1519
</div>
1620

17-
As you learned in the previous section, tests are used to verify that your code is working as expected. So, a couple things we can test right off the bat are that a post should have certain associations and validations. Let's start by writing some model tests also known as unit tests!
21+
As you learned in the previous section, tests are used to verify that your code is working as expected. So, a couple things we can test right off the bat are that a tree should have certain associations and validations. Let's start by writing some model tests also known as unit tests!
1822
MARKDOWN
1923

2024
steps do
2125
step do
22-
message "First, create a post model spec file in the models folder of the spec folder. Type this in the terminal:"
26+
message "First, create a orange model spec file in the models folder of the spec folder. Type this in the terminal:"
2327

2428
console_without_message "cd app/spec/models"
25-
console_without_message "touch post_spec.rb"
29+
console_without_message "touch orange_spec.rb"
2630
end
2731
step do
2832
message "Then, run rspec."
2933

3034
console_without_message "bundle exec rpsec"
3135

32-
message "You should see some report but no tests exist yet. So, let's add one! Copy the below test, paste it into the post model spec file and then run 'bundle exec rspec' on the terminal again."
36+
message "You should see some report but no tests exist yet. So, let's add one! Copy the below test, paste it into the orange model spec file and then run 'bundle exec rspec' on the terminal again."
3337

3438
console_without_message <<-RUBY
3539
describe 'ActiveRecord associations' do
36-
it 'Post belongs to users' do
37-
expect(Post.reflect_on_association(:user).macro).to be (:belongs_to)
40+
it 'Orange belongs to tree' do
41+
expect(Orange.reflect_on_association(:tree).macro).to be (:belongs_to)
3842
end
3943
end
4044
RUBY
4145

42-
message "Great, now you should see one passing test! That's an example of an association test. Let's modify that test to fail. Then, run 'bundle exec rspec' and see what happens. Cool! Let's revert back to the passing test. And, write another association test for the relationship between the Post model and the Reply model!"
46+
message "Great, now you should see one passing test! That's an example of an association test. Let's modify that test to fail. Then, run 'bundle exec rspec' and see what happens. Cool! Let's revert back to the passing test. And, write a has many association test for the relationship between the Tree model and the Orange model!"
4347

4448
end
4549
end
4650

4751

4852
message <<-MARKDOWN
49-
On to controller tests! Just like the Post model, assume we have the following controller in our app (the other methods are omitted for brevity):
53+
On to controller tests! Just like the Orange model, create the following controller in your app (the other methods are omitted for brevity):
5054

5155
<div class="console"><pre>
52-
class PostsController < ApplicationController
53-
include PostsHelper
54-
56+
class OrangesController < ApplicationController
5557
def index
56-
@posts = Post.all
58+
@oranges = Orange.all
5759
render :index
5860
end
5961

6062
def new
61-
@post = Post.new
63+
@orange = Orange.new
6264
render :new
6365
end
6466
end
@@ -68,17 +70,17 @@ MARKDOWN
6870

6971
steps do
7072
step do
71-
message "First, create a posts controller spec file in the controllers folder of the spec folder. Type this in the terminal:"
73+
message "First, create an orange controller spec file in the controllers folder of the spec folder. Type this in the terminal:"
7274

7375
console_without_message "cd app/spec/controllers"
74-
console_without_message "touch posts_controller_spec.rb"
76+
console_without_message "touch oranges_controller_spec.rb"
7577
end
7678
step do
7779
message "Then, run rspec."
7880

7981
console_without_message "bundle exec rpsec"
8082

81-
message "You should see a report with some passing tests but those are just the model tests you wrote. So, let's add some controller tests! Copy the below test, paste it into the posts controller spec file and then run 'bundle exec rspec' on the terminal again."
83+
message "You should see a report with some passing tests but those are just the model tests you wrote. So, let's add some controller tests! Copy the below test, paste it into the oranges controller spec file and then run 'bundle exec rspec' on the terminal again."
8284

8385
console_without_message <<-RUBY
8486
describe '#index' do
@@ -100,26 +102,26 @@ steps do
100102
end
101103

102104
message <<-MARKDOWN
103-
Last but not least: view tests! Below is an short snippet of the Post show HTML page in your app:
105+
Last but not least: view tests! Below is an short snippet of a possible Orange show HTML page you can create in your app:
104106
MARKDOWN
105107
console_without_message <<-HTML
106108
<br>
107-
Post title: <%= @post.title %>
109+
Orange title: <%= @orange.name %>
108110
<br>
109111
<br>
110-
Post content: <%= @post.content %>
112+
Orange tree id: <%= @orange.tree_id %>
111113
<br>
112114
HTML
113115

114116
message <<-MARKDOWN
115-
So, based on the post you create, the show page should render HTML with the post's title and content. Let's verify that with a few tests.
117+
So, based on the orange you create, the show page should render HTML with the orange's name and tree id. Let's verify that with a few tests.
116118
MARKDOWN
117119

118120
steps do
119121
step do
120-
message "First, create a posts view spec file in the views folder of the spec folder. Type this in the terminal:"
122+
message "First, create an oranges view spec file in the views folder of the spec folder. Type this in the terminal:"
121123

122-
console_without_message "cd app/spec/views/posts"
124+
console_without_message "cd app/spec/views/oranges"
123125
console_without_message "touch show.html.erb_spec.rb"
124126
end
125127
step do

sites/en/testing/what_are_tests.step

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
message <<-MARKDOWN
2-
Tests are ways of testing our code to see if they are performing the way we have intended it behave.
2+
3+
Tests are not exams like the ones you have to take in school. Rather, tests are ways of testing code to see if it is performing the way we expect it to behave. Pretty easy, right?
34

45
# Example
5-
For example, lets say we wanted to create a program that models an orange tree. Well, what defines an orange tree to us? Is it safe to say that we need at least two objects, an orange object and a tree object? Can our tree mature and bear more fruit at a certain age? Could our oranges ripen and fall from the tree? Sounds like the list can become lengthy right? Lets stop here for a few minutes and see what we need to fulfill these user stories.
6+
For example, let's say we wanted to create a program that models an orange tree because nature is awesome. Well, what defines an orange tree to us? Is it safe to say that we need at least two objects, an orange object and a tree object? Can our tree mature and bear more fruit at a certain age? Could our oranges ripen and fall from the tree? Sounds like the list can become lengthy, right? Let's stop here for a few minutes and see what we need to fulfill these user stories.
67

78
# What We Need To Test?
8-
Remember that we need to model an orange and a tree, so we know that there are two objects that needs to be created.
9+
Remember that we need to model an orange and a tree. So, we know that there are two objects that need to be created.
910

10-
We could say that the tree will not bear fruit until it matures at one year of age and then it well bare an X amount of oranges. We would need a test to test if the tree ages and a test to see if the tree has created an X amount of oranges once it has matured.
11-
12-
How do we determine if an orange is ripe? Well, we can have oranges age and if it is at least 30 days old, then it will fall from the tree. We would need to write a test to check for ripeness and a test to check if it falls at ripeness.
11+
We could say that the tree will not bear fruit until it matures at one year of age and then it will bear X number of oranges. We would need a test to test if the tree ages and a test to see if the tree has created X number of oranges once it has matured.
1312

14-
# Now That We Have Tests
15-
You could think of tests as a requirement list. Every time a change is made we want to test to see if our code still meets those requirements. For example, as our program becomes increasingly complex and we want to have our tree to have a certain lifespan, would it make sense for our tree to continue to create oranges after exceeding that lifespan?
13+
How do we determine if an orange is ripe? Well, we can have an orange age and if it is at least 30 days old, then it will fall from the tree. We would need to write a test to check for ripeness and a test to check if it falls at ripeness.
1614

1715
# Why Is It Important That We Test?
18-
For situations like our tree's lifespan is a prime example of why tests are important. As our program becomes more complex over time the tests tells us that a basic requirement is not fulfilled and needs to be addressed. Can you imagine looking at pages and pages of code that was written by someone else or many years ago without a way to trace exactly where the bug is? Tests can help!
16+
You could think of tests as a requirement list. Every time a change is made we want to test to see if our code still meets those requirements. For example, as our program becomes increasingly complex and we want to have our tree to have a certain lifespan, would it make sense for our tree to continue to create oranges after exceeding that lifespan?
17+
18+
A situation like our tree's lifespan is a prime example of why tests are important. As our program becomes more complex over time with new code added, the tests tell us that the new code negatively affected prior expectations of the behavior of the code. Tests can help keep the original behavior of the code and prevent new bugs from appearing.
1919

2020
# Test Driven Development
2121
Test-driven development (TDD) is a development technique where you must first write a test that fails before you write new functional code. TDD is a great way to develop your program! Add a test, run all tests, write code, run tests, and then refactor code!

0 commit comments

Comments
 (0)