Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,765
    • Issues 44,765
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,329
    • Merge requests 1,329
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #18839
Closed
Open
Issue created Jul 20, 2017 by Grzegorz Bizon@grzesiek💡Maintainer

Rethink RSpec expectations with after and before hooks

Currently, following test example succeeds:

  context 'test' do
    let(:test) { double }

    it 'expects some message' do
      expect(test).to receive(:xxx)
    end
    
    after do
      test.xxx
    end
  end

It is also possible to set expectations in a before block.

This behavior is a little confusing, and in fact can lead to some problems, when we do a clean up in a after block. Example is https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/23223257 - we expect some messages sent to some object, but we receive more messages since we trigger a clean up in after block.

It does not seem right according to how I understand before and after semantics, but I might be wrong.

Does it warrant an issue in upstream project? 🤔

What do you think @rymai @rspeicher?

Assignee
Assign to
Time tracking