forked from rspec/rspec-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller_spec.feature
104 lines (90 loc) · 3.41 KB
/
controller_spec.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
Feature: controller spec
Scenario: simple passing example
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe WidgetsController, :type => :controller do
describe "GET index" do
it "has a 200 status code" do
get :index
expect(response.status).to eq(200)
end
end
end
"""
When I run `rspec spec`
Then the example should pass
Scenario: controller is exposed to global before hooks
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.configure {|c| c.before { expect(controller).not_to be_nil }}
RSpec.describe WidgetsController, :type => :controller do
describe "GET index" do
it "doesn't matter" do
end
end
end
"""
When I run `rspec spec`
Then the example should pass
@rails_pre_6
Scenario: setting a different content type for example json (request type)
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe WidgetsController, :type => :controller do
describe "responds to" do
it "responds to html by default" do
post :create, :params => { :widget => { :name => "Any Name" } }
expect(response.content_type).to eq "text/html"
end
it "responds to custom formats when provided in the params" do
post :create, :params => { :widget => { :name => "Any Name" }, :format => :json }
expect(response.content_type).to eq "application/json"
end
end
end
"""
When I run `rspec spec`
Then the example should pass
@rails_post_6
Scenario: setting a different content type for example json (request type)
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe WidgetsController, :type => :controller do
describe "responds to" do
it "responds to html by default" do
post :create, :params => { :widget => { :name => "Any Name" } }
expect(response.content_type).to eq "text/html; charset=utf-8"
end
it "responds to custom formats when provided in the params" do
post :create, :params => { :widget => { :name => "Any Name" }, :format => :json }
expect(response.content_type).to eq "application/json; charset=utf-8"
end
end
end
"""
When I run `rspec spec`
Then the example should pass
@rails_post_6
Scenario: setting a different media type for example json (request type)
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe WidgetsController, :type => :controller do
describe "responds to" do
it "responds to html by default" do
post :create, :params => { :widget => { :name => "Any Name" } }
expect(response.media_type).to eq "text/html"
end
it "responds to custom formats when provided in the params" do
post :create, :params => { :widget => { :name => "Any Name" }, :format => :json }
expect(response.media_type).to eq "application/json"
end
end
end
"""
When I run `rspec spec`
Then the example should pass