Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !1902

WIP: improve how we test controllers

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Pablo Brasero requested to merge github/fork/pablobm/better-controller-testing into main Feb 11, 2021
  • Overview 4
  • Commits 1
  • Pipelines 0
  • Changes 2

An experiment to see how the issue I described at https://github.com/thoughtbot/administrate/pull/1880#issuecomment-777665333 can be solved. I'll repeat here...

Some of our controller tests don't actually run Rails's test rendering code. Instead they capture the call to render with a mock, extract the value of :locals, and run expectations on that. As a result, nothing is actually rendered, and Rails tells us that the result was a :no_content.

The capture is done with capture_view_locals, which can be seen at https://github.com/thoughtbot/administrate/blob/e1ae45cf44a6b7fce13865175bb5e596ad448ba9/spec/support/controller_helpers.rb

To compound the problem, I don't think there is a standard way of achieving this. It's possible to test :locals, but only in a very limited way, by comparing exact values. See:

https://github.com/rails/rails-controller-testing/blob/4b15c86e82ee380f2a7cc009e470368f7520560a/lib/rails/controller/testing/template_assertions.rb#L104-L108

This is a first attempt at fixing the situation. It's a "if you can't beat them, join them" approach, where I extend the helper to capture more than just :locals.

Other options:

  • Write this test differently, not relying on this helper.
  • Move it to an integration test or something like that.
  • Don't use locals, and instead use instance variables as it's conventional with Rails.
  • Contribute to rails-controller-testing, and add a method that would help us here.
  • Other...?
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/pablobm/better-controller-testing