Skip to content

Commit

Permalink
Generate request specs for the provided actions
Browse files Browse the repository at this point in the history
  • Loading branch information
klyonrad committed Dec 15, 2019
1 parent 764de75 commit 349719a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/generators/rspec/controller/templates/request_spec.rb
@@ -1,8 +1,14 @@
require 'rails_helper'

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

<% end -%>
end
24 changes: 24 additions & 0 deletions spec/generators/rspec/controller/controller_generator_spec.rb
Expand Up @@ -26,6 +26,30 @@
end
it { is_expected.not_to exist }
end


describe 'with actions' do
before do
run_generator %w[posts index custom_action]
end

it { is_expected.to exist }
it { is_expected.to contain('get "/posts/index"') }
it { is_expected.to contain('get "/posts/custom_action"') }
end

describe 'with namespace and actions' do
subject { file('spec/requests/admin/external/users_request_spec.rb') }

before do
run_generator %w[admin::external::users index custom_action]
end

it { is_expected.to exist }
it { is_expected.to contain(/^RSpec.describe "Admin::External::Users", #{type_metatag(:request)}/) }
it { is_expected.to contain('get "/admin/external/users/index"') }
it { is_expected.to contain('get "/admin/external/users/custom_action"') }
end
end

describe 'view specs' do
Expand Down

0 comments on commit 349719a

Please sign in to comment.