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

Create controller generator for routing specs #1806

Closed
wants to merge 1 commit into from
Closed

Create controller generator for routing specs #1806

wants to merge 1 commit into from

Conversation

00dav00
Copy link

@00dav00 00dav00 commented Apr 21, 2017

This PR covers #1160

This creates routing specs for controller generator

/cc @rspec/rspec

@fables-tales
Copy link
Member

@00dav00 Thanks for this PR! This looks fine to me and I like most of the PR implementation, I do have a few notes. Before we go ahead with this I need to think about whether or not this is a feature we want to support going forward.

I rarely if ever use a routing spec. Do you personally find a lot of value from them?

@seuros
Copy link
Member

seuros commented Apr 24, 2017

@samphippen I use routing specs for API endpoints since they should follow the specification and not change.

class_option :view_specs, :type => :boolean, :default => true
class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could have default : false ?

@00dav00
Copy link
Author

00dav00 commented Apr 25, 2017

@samphippen I agree with @seuros, this specs can be useful when the routes does not follow rest conventions.

@JonRowe
Copy link
Member

JonRowe commented Apr 26, 2017

@seuros @00dav00 sure they can be useful, but that doesn't mean they should be recommended by default, generated specs have a habit of becoming the default, personally I'd welcome adding a seperate generator, for those that so desire, but not adding them as the default for a controller.

@seuros
Copy link
Member

seuros commented Apr 26, 2017

@JonRowe what about having the option routing_specs default to false ?

@00dav00
Copy link
Author

00dav00 commented Apr 26, 2017

@JonRowe I think @seuros 's option may be a good fit, I mean not adding them as default. WDYT @samphippen ?

@juank-pa
Copy link

juank-pa commented May 3, 2017

I noticed routing specs are being created by the scaffold generator. So isn't this contribution helping us have a sense of completeness? I think this could work but in any case, I'm also open to not having it by default. WDYT? @JonRowe @samphippen

@fables-tales
Copy link
Member

Hi @00dav00 I've found some time to come back to this. I think I like this overall, but I have some questions:

  • if I don't specify an action, what happens?
  • if I use a scaffold generator to do a full controller backed by a model, what happens?

@00dav00
Copy link
Author

00dav00 commented Aug 29, 2017

Hi @samphippen, thanks for puting some time into this, highly appreciated.

  1. if I don't specify an action, what happens?

If --routing-specs is passed to the generator but no action is given the spec file will be created but will contain no specs. Should I change this behavior to create route specs for the CRUD operations (like the scaffold routing generator) or the creation of this file should be skipped (like in the method for view specs)?

  1. if I use a scaffold generator to do a full controller backed by a model, what happens?

The scaffold generator is creating the routing specs by default. In opposition with the current PR, the scaffold generator will only skip the routing specs if the flag --no-routing-specs is provided. Also if no actions are sent the CRUD operations will be used to create the routing specs. I think this should be consistent between the two generators, WDYT @samphippen? Which approach should be used?

@00dav00
Copy link
Author

00dav00 commented Jun 4, 2019

@samphippen This has been here for a while now, do you think we will be able to move it forward or you consider it is not required?

class_option :view_specs, :type => :boolean, :default => true
class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
class_option :routing_specs, :type => :boolean, :default => false, :desc => "Generate routing specs"
Copy link
Member

Choose a reason for hiding this comment

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

Double spacing here, unless you were intending to align the :desc, in which case the latst needs a space removed.


def generate_routing_spec
return unless options[:routing_specs]

Copy link
Member

Choose a reason for hiding this comment

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

This should probably return is actions is empty like views...

require 'rails_helper'

<% module_namespacing do -%>
RSpec.describe <%= class_name %>Controller, <%= type_metatag(:routing) %> do
Copy link
Member

Choose a reason for hiding this comment

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

This describe should be a doc string, we don't need the constant here.

@00dav00
Copy link
Author

00dav00 commented Jun 5, 2019

Closing this one in favor of #2134

@00dav00 00dav00 closed this Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants