If you need a controller you need a controller spec, its not practical to 
instantiate a controller on your own, one of the many reasons why they are 
recommended against by the Rails team now.

Otherwise you need to test the behaviour of the end result, e.g. create a set 
of shared examples for your concern and use them in every 
request/system/integration test for the routes concerned.

Jon Rowe
---------------------------
[email protected]
jonrowe.co.uk

On 27 February 2019 at 11:00, belgoros wrote:
> On Wednesday, 27 February 2019 11:49:28 UTC+1, Jon Rowe wrote:
> > Hi
> >
> > A concern is just a bunch of methods you include into a class. You can test 
> > them either independently by bringing the concern into a plain old class, 
> > or if you need to use controller methods you can bring them into a 
> > controller. There is a anonymous controller in controller specs you can use 
> > for this purpose.
> >
> > However the Rails team have deprecated controller tests (and therefore 
> > controller specs) in favour of request specs, because the way that Rails 
> > controllers operate are not well suited towards unit tests (they are always 
> > a form of integration test due to the way that the Rails stack was 
> > designed).
> >
> > So it depends on what you are testing.
> >
>
> Thank you, Jon, for your response.
> As I'd like to test just the methods defined in the above module (concern), 
> as far as I understood, I could put a test no matter in which folder under 
> spec directory.
> For example:
>
> #spec/controllers/concerns/response_spec.rb
> require 'rails_helper'
> class FakeController < ApplicationController
>
> end
> RSpec.describe Response do
>
> end
>
> So if it is OK, the above FakeController should include my concern methods. 
> But how to test them ?

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/dejalu-217-ebda68a8-514d-4caf-8a98-fc7e9fa35b52%40jonrowe.co.uk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to