Skip to content

Commit dca0930

Browse files
akanshmurthyrachelmyers
authored andcommitted
Testing curriculum fixes (railsbridge#625)
* update curriculum based on event feedback * Add example with receive and not times * Make matchers description more conversational
1 parent 2a5c52f commit dca0930

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

sites/en/testing-rails-applications/additional_concepts.step

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ message <<-MARKDOWN
1919
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!
2020

2121
### Spies
22-
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.
22+
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 a certain number of times.
2323
For instance (assume you already have the orange double from above):
2424

2525
```ruby
2626
orange = spy('orange')
2727
orange.name
28-
expect(orange).to have_received(:name)
28+
expect(orange).to receive(:name)
29+
orange.name
30+
expect(orange).to receive(:name).exactly(2).times
2931
```
3032

3133
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!

sites/en/testing-rails-applications/testing_frameworks.step

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,7 @@ rails generate rspec:install
3939
</pre>
4040
</div>
4141

42-
This adds the following files which are used for configuration:
43-
44-
<div class="console"><pre>
45-
.rspec
46-
spec/spec_helper.rb
47-
spec/rails_helper.rb
48-
</pre>
49-
</div>
42+
This command will add the spec helper, rails helper, and .rspec configuration files.
5043

5144
Use the rspec command to run your specs:
5245

@@ -92,7 +85,7 @@ expected: #< Tree @age=1 >
9285
</div>
9386

9487
## Matchers
95-
Remember in our example on line 5? 'to eq' is a matcher. RSpec has many built-in matchers. Matchers evaluates our expectations. In our example, we are saying that we expect orange_tree's age to equal an integer of 1.
88+
Remember our example in the RSpec Basics section above? The 'to eq' is a matcher! RSpec has many built-in matchers. You can think of them as ways to equate or check certain values or expressions to what you think or expect they would "match" to. In our example, we are saying that we expect orange_tree's age to equal an integer of 1.
9689

9790
Check out the other built-in matchers!
9891
https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers

sites/en/testing-rails-applications/types_of_tests.step

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ steps do
2727
source_code :ruby, <<-RUBY
2828
RSpec.describe Orange, :type => :model do
2929
context 'ActiveRecord associations' do
30-
it 'Orange belongs to tree' do
30+
it 'belongs to tree' do
3131
expect(Orange.reflect_on_association(:tree).macro).to be (:belongs_to)
3232
end
3333
end
@@ -47,7 +47,7 @@ steps do
4747

4848
step do
4949

50-
message "Now let's write a has_many association test for the relationship between the Tree model and the Orange model! (hint: this doesn't exist yet so you'll have to create the model and migrate!)"
50+
message "Now let's write a has_many association test for the relationship between the Tree model and the Orange model! (<strong>hint: this doesn't exist yet so you'll have to create the model and migrate!</strong>)"
5151

5252
message "On to controller tests! Just like the Orange model, you will create the OrangesController, which will also create spec files in the /spec/controllers folder of your app."
5353
end
@@ -71,7 +71,7 @@ steps do
7171
get :index
7272
expect(response).to render_template("index")
7373
end
74-
74+
7575
it "renders html" do
7676
process :index, method: :get
7777
expect(response.content_type).to eq "text/html"
@@ -80,13 +80,13 @@ steps do
8080
end
8181
RUBY
8282

83-
message "You should see two failing tests. You'll need to add a route, index action, and a view. Not sure where to start? Read the errors in your failing tests for a hint. Run 'bundle exec rspec' after each change until both tests pass."
83+
message "You should see two failing tests. <strong>Hint: You'll need to add a route, index action, and a view.</strong> Not sure where to start? Read the errors in your failing tests for a hint. Run 'bundle exec rspec' after each change until both tests pass."
8484

8585
message "Note: as you write the controller tests, you may be prompted to install a missing gem called 'rails-controller-testing' to use the assert_template method. If prompted, please add it to your Gemfile and do a bundle install!"
8686
end
8787

8888
step do
89-
message "Now, write another controller test for the new action (hint: you might need to look up what a mock is)."
89+
message "Now, write another controller test for the new action (<strong>hint: you might need to look up what a mock is</strong>)."
9090
end
9191

9292
step do
@@ -109,14 +109,15 @@ steps do
109109

110110
message "First, create a views folder in the spec folder. Then, create an oranges folder in the views folder. Lastly, create an oranges view spec file in the oranges folder. Type these commands in the terminal:"
111111

112-
console_without_message "mkdir app/spec/views"
113-
console_without_message "mkdir app/spec/views/oranges"
114-
console_without_message "cd app/spec/views/oranges"
112+
console_without_message "mkdir spec/views"
113+
console_without_message "mkdir spec/views/oranges"
114+
console_without_message "cd spec/views/oranges"
115115
console_without_message "touch show.html.erb_spec.rb"
116116
end
117117
step do
118-
message "Then, run rspec."
118+
message "Change directory back to the root directory of your app. Then, run rspec."
119119

120+
console_without_message "cd ../../.."
120121
console_without_message "bundle exec rspec"
121122

122123
message "You should see a report with some passing tests but those are just the model and controller tests you wrote. So, let's add some view tests!"

0 commit comments

Comments
 (0)