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: sites/en/testing-rails-applications/additional_concepts.step
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -19,13 +19,15 @@ message <<-MARKDOWN
19
19
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!
20
20
21
21
### 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.
23
23
For instance (assume you already have the orange double from above):
24
24
25
25
```ruby
26
26
orange = spy('orange')
27
27
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
29
31
```
30
32
31
33
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!
Copy file name to clipboardExpand all lines: sites/en/testing-rails-applications/testing_frameworks.step
+2-9Lines changed: 2 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -39,14 +39,7 @@ rails generate rspec:install
39
39
</pre>
40
40
</div>
41
41
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.
50
43
51
44
Use the rspec command to run your specs:
52
45
@@ -92,7 +85,7 @@ expected: #< Tree @age=1 >
92
85
</div>
93
86
94
87
## 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.
Copy file name to clipboardExpand all lines: sites/en/testing-rails-applications/types_of_tests.step
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ steps do
27
27
source_code :ruby, <<-RUBY
28
28
RSpec.describe Orange, :type => :model do
29
29
context 'ActiveRecord associations' do
30
-
it 'Orange belongs to tree' do
30
+
it 'belongs to tree' do
31
31
expect(Orange.reflect_on_association(:tree).macro).to be (:belongs_to)
32
32
end
33
33
end
@@ -47,7 +47,7 @@ steps do
47
47
48
48
step do
49
49
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>)"
51
51
52
52
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."
53
53
end
@@ -71,7 +71,7 @@ steps do
71
71
get :index
72
72
expect(response).to render_template("index")
73
73
end
74
-
74
+
75
75
it "renders html" do
76
76
process :index, method: :get
77
77
expect(response.content_type).to eq "text/html"
@@ -80,13 +80,13 @@ steps do
80
80
end
81
81
RUBY
82
82
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."
84
84
85
85
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!"
86
86
end
87
87
88
88
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>)."
90
90
end
91
91
92
92
step do
@@ -109,14 +109,15 @@ steps do
109
109
110
110
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:"
0 commit comments