Skip to content

Commit 349719a

Browse files
committed
Generate request specs for the provided actions
1 parent 764de75 commit 349719a

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
require 'rails_helper'
22

33
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
4-
describe "GET /<%= name.underscore.pluralize %>" do
5-
it "works! (now write some real specs)" do
4+
<% namespaced_path = regular_class_path.join('/') %>
5+
<% for action in actions -%>
6+
describe "GET /<%= action %>" do
7+
it "returns http success" do
8+
get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>"
9+
expect(response).to have_http_status(:success)
610
end
711
end
12+
13+
<% end -%>
814
end

spec/generators/rspec/controller/controller_generator_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@
2626
end
2727
it { is_expected.not_to exist }
2828
end
29+
30+
31+
describe 'with actions' do
32+
before do
33+
run_generator %w[posts index custom_action]
34+
end
35+
36+
it { is_expected.to exist }
37+
it { is_expected.to contain('get "/posts/index"') }
38+
it { is_expected.to contain('get "/posts/custom_action"') }
39+
end
40+
41+
describe 'with namespace and actions' do
42+
subject { file('spec/requests/admin/external/users_request_spec.rb') }
43+
44+
before do
45+
run_generator %w[admin::external::users index custom_action]
46+
end
47+
48+
it { is_expected.to exist }
49+
it { is_expected.to contain(/^RSpec.describe "Admin::External::Users", #{type_metatag(:request)}/) }
50+
it { is_expected.to contain('get "/admin/external/users/index"') }
51+
it { is_expected.to contain('get "/admin/external/users/custom_action"') }
52+
end
2953
end
3054

3155
describe 'view specs' do

0 commit comments

Comments
 (0)