Allow for individual test skiping
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by tracing how RBS tests process RSpec examples and how the %a{rbs:test:skip} annotation is recognized. Define a per-example opt-out that skips only the invalid-name case while keeping the valid-name checks active, then cover both behaviors with the example scenarios in the issue.
Written by the indexing model from the issue text.
Description
It would be awesome if you could turn RBS test on and off for single unit tests.
Given the following example:
class MyClass
attr_reader :name #: Symbol
# @rbs (name: String | Symbol) -> void
def initialize(name:)
validate_name(name)
@name = name.to_sym
end
private
# @rbs (untyped name) -> void
def validate_name(name)
raise ArgumentError, "Invalid name: #{name}" unless name.is_a?(String) || name.is_a?(Symbol)
end
end
and the following test:
RSpec.describe MyClass do
describe '.new' do
subject(:my_class) { described_class.new(name) }
# RBS test needs to skip this context as we're intentionally violating types here.
context 'when given an invalid name' do
let(:name) { 123 }
it { expect { my_class }.to raise_error(ArgumentError, /Invalid name/) }
end
# RBS test should not skip this context
context 'when given a valid name' do
let(:name) { 'foo' }
it { expect { my_class }.not_to raise_error }
it 'is expected to set the name' do
expect(my_class).to have_attributes(name: :foo)
end
end
end
end
While it's great that RBS can catch these type errors its only really beneficial if those who use your gem as a dependency are also using RBS on their project. So we still need to write in protections like this but are unable to test them because the test in this example will raise an RBS TypeError. Additionally we don't want to completely turn off RBS for the initialize method with the %a{rbs:test:skip} annotation as it's just this single test that will raise the error.
The obvious work around here is to have the name argument in the initializer be untyped however that reduces the clarity of the signature making the end user believe they may pass whatever they would like for name to the initializer.
- Dominant language
- Ruby
- Stars
- 2.2k
- Forks
- 263
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 64
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/rbs
-
InlineParser: `@rbs @ivar` annotation is reported as unused unless it is the first thing in the class bodyPossibly taken @ksss claimed this 50 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
Maintainers usually reply within 1 day
Similar issues
-
needs verification
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 13 days
-
🐛 bug 👩💻 équipe CE 🧑🏭 entreprises
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
betagouv/conseillers-entreprises#4808 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
yosiat/panko_serializer#250 ·