Skip to content

Where to test non-client-facing behaviors from controller actions? #2373

Open
@rpbaptist

Description

@rpbaptist

We were having an internal discussion about this.

Looking at #1839 and considering the documentation has not been changed since it leaves me with questions.

Use request specs to describe the client-facing behavior of the application

Starting background jobs or sending notification mails is not client-facing behaviour. So that should not be covered in request specs. So far so good.

Controller specs can be used to describe the behavior of Rails controllers. As of version 3.5, however, controller specs are discouraged in favor of request specs (which also focus largely on controllers, but capture other critical aspects of application behavior as well).

And here it's stating we should be using request specs for everything previously tested in conrollers. So I am wondering what the recommendation is for non client-facing behaviour. If controller tests are not to be used, and request specs should not test client-facing behavior, then where would you recommend testing them?

This is the kind of tests I currently use for controllers:

expect { post(:create, params: {}) }.to have_enqueued_job(DoSomethingJob).with(model, foo: :bar)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions