Skip to content

GitLab Next

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
GitLab
GitLab
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 34,895
    • Issues 34,895
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 1,229
    • Merge Requests 1,229
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Metrics
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • GitLab.org
  • GitLabGitLab
  • Issues
  • #18839

Closed
Open
Opened 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
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: gitlab-org/gitlab#18839