Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Filters on include_context are ignored #2941

Closed
zog opened this issue Mar 16, 2022 · 2 comments
Closed

Filters on include_context are ignored #2941

zog opened this issue Mar 16, 2022 · 2 comments

Comments

@zog
Copy link

zog commented Mar 16, 2022

Subject of the issue

Filters on include_context are ignored if passed in the wrong order

Your environment

  • Ruby version: 3.1.1
  • rspec-core version: 3.11.0

Steps to reproduce

# frozen_string_literal: true

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"

  gem "rspec", "3.11.0" # Activate the gem and version you are reporting the issue against.
end

puts "Ruby version is: #{RUBY_VERSION}"
require 'rspec/autorun'

RSpec.shared_context 'default context' do
  let(:value) { 1 }
end

RSpec.shared_context 'my context' do
  let(:value) { 2 }
end

RSpec.configure do |config|
  config.include_context 'default context', type: :bug_report
  config.include_context 'my context', :filter_me, type: :bug_report
end

RSpec.describe 'include filters', type: :bug_report do
  it 'should have value == 1' do
    expect(value).to eq 1
  end

  it 'should have value == 2', :filter_me do
    expect(value).to eq 2
  end
end

Expected behavior

The context should only be included on examples matching the filters

Actual behavior

The context is always included

Workaround

Inverting the filters order fixes the issue:

# frozen_string_literal: true

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"

  gem "rspec", "3.11.0" # Activate the gem and version you are reporting the issue against.
end

puts "Ruby version is: #{RUBY_VERSION}"
require 'rspec/autorun'

RSpec.shared_context 'default context' do
  let(:value) { 1 }
end

RSpec.shared_context 'my context' do
  let(:value) { 2 }
end

RSpec.configure do |config|
  config.include_context 'default context', type: :bug_report
  config.include_context 'my context', { type: :bug_report }, :filter_me
end

RSpec.describe 'include filters', type: :bug_report do
  it 'should have value == 1' do
    expect(value).to eq 1
  end

  it 'should have value == 2', :filter_me do
    expect(value).to eq 2
  end
end
@pirj
Copy link
Member

pirj commented Mar 16, 2022

This seems to be a duplicate of #1821, that is fixed in #2878, and will be released in RSpec 4.
I encourage you to use the 4-0-dev branch if you want to use it before the release.
Can you please confirm that 4-0-dev fixes the issue?

@JonRowe
Copy link
Member

JonRowe commented Mar 23, 2022

I tested this on 4-0-dev and it was fixed (using the snippet above) closing for now but please re open if you find an issue against 4-0-dev

@JonRowe JonRowe closed this as completed Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants