Skip to content

Commit 2dc9829

Browse files
rlueJonRowe
authored andcommitted
Make README more accessible to novices (#2042)
* Make README more accessible to novices * Amend per @JonRowe's review * Apply second round of fixes per @JonRowe's review * Amend per @benoittgt's code review * Remove trailing whitespace * Apply more fixes per @JonRowe's review * Change semicolon to full colon in intro * Fix punctuation in intro * Apply changes per @samphippen's review * Fix description of spec type assignment, per @JonRowe's suggestion * Rephrase introduction per @mikegee's review
1 parent 49ddef1 commit 2dc9829

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

features/matchers/have_http_status_matcher.feature

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
Feature: `have_http_status` matcher
22

33
The `have_http_status` matcher is used to specify that a response returns a
4-
desired status code.
4+
desired status code. It accepts one argument in any of the following formats:
5+
6+
* numeric code
7+
* status name as defined in `Rack::Utils::SYMBOL_TO_STATUS_CODE`
8+
* generic status type (`:success`, `:missing`, `:redirect`, or `:error`)
59

610
The matcher works on any `response` object. It is available for use in
711
[controller specs](../controller-specs), [request specs](../request-specs), and [feature specs](../feature-specs).
812

9-
Scenario: Checking a numeric response code
13+
Scenario: Checking a numeric status code
1014
Given a file named "spec/controllers/application_controller_spec.rb" with:
1115
"""ruby
1216
require "rails_helper"
@@ -31,7 +35,7 @@ Feature: `have_http_status` matcher
3135
When I run `rspec spec`
3236
Then the examples should all pass
3337

34-
Scenario: Checking a symbolic response code
38+
Scenario: Checking a symbolic status name
3539
Given a file named "spec/controllers/application_controller_spec.rb" with:
3640
"""ruby
3741
require "rails_helper"
@@ -56,7 +60,7 @@ Feature: `have_http_status` matcher
5660
When I run `rspec spec`
5761
Then the examples should all pass
5862

59-
Scenario: Checking a general response code
63+
Scenario: Checking a symbolic generic status type
6064
Given a file named "spec/controllers/application_controller_spec.rb" with:
6165
"""ruby
6266
require "rails_helper"

features/view_specs/view_spec.feature

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
Feature: view spec
22

3-
View specs live in spec/views and render view templates in isolation.
3+
View specs are marked by `:type => :view`
4+
or if you have set `config.infer_spec_type_from_file_location!`
5+
by placing them in `spec/views`.
6+
7+
Use them to test the content of view templates
8+
without invoking a specific controller.
9+
They generally follow three steps:
10+
11+
```ruby
12+
assign(:widget, Widget.new) # sets @widget = Widget.new in the view template
13+
14+
render
15+
16+
expect(rendered).to match(/text/)
17+
```
18+
19+
1. Use the `assign` method to set instance variables in the view.
20+
21+
2. Use the `render` method to render the view.
22+
23+
3. Set expectations against the resulting rendered template.
424

525
Scenario: View specs render the described view file
626
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
@@ -73,6 +93,34 @@ Feature: view spec
7393
When I run `rspec spec/views`
7494
Then the examples should all pass
7595

96+
Scenario: View specs can render templates in layouts
97+
Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
98+
"""ruby
99+
require "rails_helper"
100+
101+
RSpec.describe "rendering the widget template" do
102+
context "with the inventory layout" do
103+
it "displays the widget" do
104+
assign(:widget, Widget.create!(:name => "slicer"))
105+
106+
render :template => "widgets/widget.html.erb", :layout => "layouts/inventory"
107+
108+
expect(rendered).to match /slicer/
109+
end
110+
end
111+
end
112+
"""
113+
And a file named "app/views/widgets/widget.html.erb" with:
114+
"""
115+
<h2><%= @widget.name %></h2>
116+
"""
117+
And a file named "app/views/layouts/inventory.html.erb" with:
118+
"""
119+
<%= yield %>
120+
"""
121+
When I run `rspec spec/views`
122+
Then the examples should all pass
123+
76124
Scenario: View specs can have description that includes the format and handler
77125
Given a file named "spec/views/widgets/widget.xml.erb_spec.rb" with:
78126
"""ruby

0 commit comments

Comments
 (0)