Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise exception when using :focus tag to avoid skipping RSpec tests #167

Merged
merged 4 commits into from
Mar 24, 2022

Conversation

ArturT
Copy link
Member

@ArturT ArturT commented Mar 3, 2022

Raise exception only when RSpec inclusion rule includes :focus tag.

problem description

When tests can be skipped by RSpec?

The problem occurs when at least one of the test files has :focus tag. And when you use

RSpec.configure do |c|
  c.filter_run_when_matching :focus
end

For instance, if a test file has content like this:

describe ArticlesController, :focus do
  it '1' do
    expect(true).to be true
  end

  # another way to make test focused is to add prefix f to it (fit)
  fit '2' do
    expect(true).to be true
  end
end

Then this sets RSpec filter to focus: true. You can see in RSpec output this: Run options: include {:focus=>true}
and as a result we can see in the RSpec output: All examples were filtered out so tests without the tag are skipped.

All further test files fetched from Queue are going to be skipped due to this filter :focus => true.

solution

Using the :focus tag should be a temporary change in the development environment when you only want to run tests with the :focus tag. In the CI environment, it is not recommended to use :focus tag because this can lead to skipping test cases. Especially it can lead to skipping random test file paths without :focus tag in the Knapsack Pro Queue Mode when the test files are loaded after the test file with :focus tag. Please remove :focus tags from your test files and commit the change and push to the repository. RSpec provides aliases fit, fdescribe and fcontext as a shorthand for it, describe and context with :focus metadata, making it easy to temporarily focus an example or group by prefixing an f. Please remove all occurrences of it or use an alternative solution: https://knapsackpro.com/faq/question/why-is-rspec-skipping-some-of-the-tests#if-you-have-too-many-test-files-with-focus-tag-and-you-dont-want-to-remove-the-tag-manually

@ArturT ArturT added the bug label Mar 3, 2022
@ArturT ArturT changed the title Raise exception when using :focus tag to avoid skipping RSpec tests Raise exception when using :focus tag to avoid skipping RSpec tests Mar 3, 2022
raise exception only when inclusion rule includes :focus tag
@ArturT ArturT requested a review from shadre March 24, 2022 11:56
@ArturT ArturT merged commit db557eb into master Mar 24, 2022
@ArturT ArturT deleted the art-rspec-skipping-tests branch March 24, 2022 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants