Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve controller template when no action #2399

Merged
merged 4 commits into from Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/generators/rspec/controller/controller_generator.rb
Expand Up @@ -14,7 +14,6 @@ class ControllerGenerator < Base

def generate_request_spec
return unless options[:request_specs]

ThHareau marked this conversation as resolved.
Show resolved Hide resolved
template 'request_spec.rb',
File.join('spec/requests', class_path, "#{file_name}_spec.rb")
end
Expand Down
9 changes: 8 additions & 1 deletion lib/generators/rspec/controller/templates/request_spec.rb
@@ -1,7 +1,14 @@
require 'rails_helper'

RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
<% namespaced_path = regular_class_path.join('/') %>
<% namespaced_path = regular_class_path.join('/') -%>
<% if actions.empty? -%>
describe "GET /index" do
it "returns http success" do
ThHareau marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specifically related to this pull request.

I'm slightly opposed to adding "returns http success" in request specs. From my point of view, they should test more than just http statuses, and providing this as a reference example in the template is promoting a dubious practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Maybe I can update the template for that as well? Do you have an idea regarding what we can provide?

I'm thinking to exists or is reachable (I have a preference for the second option)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "returns a list of #{class_name.pluralize.downcase}"? At least this is what an "index" originally means.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the template for that as well

That would be very helpful!

pending "add some scenarios (or delete) #{__FILE__}"
ThHareau marked this conversation as resolved.
Show resolved Hide resolved
end
end
<% end -%>
<% for action in actions -%>
describe "GET /<%= action %>" do
it "returns http success" do
Expand Down
Expand Up @@ -17,6 +17,7 @@
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe "Posts", #{type_metatag(:request)}/) }
it { is_expected.to contain('pending') }
end
end

Expand Down