-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
render_views.feature
132 lines (112 loc) · 3.48 KB
/
render_views.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
Feature: render_views
You can tell a controller example group to render views with the
`render_views` declaration.
Scenario: expect template that exists and is rendered by controller (passes)
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""
require "spec_helper"
describe WidgetsController do
render_views
describe "index" do
it "renders the index template" do
get :index
response.should contain("Listing widgets")
end
it "renders the widgets/index template" do
get :index
response.should contain("Listing widgets")
end
end
end
"""
When I run "rspec spec"
Then the output should contain "2 examples, 0 failures"
Scenario: expect template that does not exist and is rendered by controller (fails)
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""
require "spec_helper"
describe WidgetsController do
render_views
before do
def controller.index
render :template => "other"
end
end
describe "index" do
it "renders the other template" do
get :index
end
end
end
"""
When I run "rspec spec"
Then the output should contain "1 example, 1 failure"
And the output should contain "Missing template"
Scenario: render_views on and off in diff contexts
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""
require "spec_helper"
describe WidgetsController do
context "with render_views" do
render_views
describe "index" do
it "renders the actual template" do
get :index
response.body.should =~ /Listing widgets/m
end
end
end
context "without render_views" do
describe "index" do
it "renders the RSpec generated template" do
get :index
response.body.should == ""
end
end
end
context "with render_views again" do
render_views
describe "index" do
it "renders the actual template" do
get :index
response.body.should =~ /Listing widgets/m
end
end
end
context "without render_views again" do
describe "index" do
it "renders the RSpec generated template" do
get :index
response.body.should == ""
end
end
end
end
"""
When I run "rspec spec"
Then the output should contain "4 examples, 0 failures"
Scenario: render_views globally
Given a file named "spec/support/render_views.rb" with:
"""
RSpec.configure do |config|
config.render_views
end
"""
And a file named "spec/controllers/widgets_controller_spec.rb" with:
"""
require "spec_helper"
describe WidgetsController do
describe "index" do
it "renders the index template" do
get :index
response.should contain("Listing widgets")
end
it "renders the widgets/index template" do
get :index
response.should contain("Listing widgets")
end
end
end
"""
When I run "rspec spec"
Then the output should contain "2 examples, 0 failures"