Allow for individual test skiping

Aberta
#2,130 2 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
ruby
Domínio
testing

Direção de pesquisa

Comece rastreando como os testes de RBS processam os exemplos de RSpec e como a anotação %a{rbs:test:skip} é reconhecida. Defina um opt-out por exemplo que ignore apenas o caso de nome inválido, mantendo ativas as verificações de nomes válidos, e então cubra ambos os comportamentos com os cenários de exemplo da issue.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Ruby
Estrelas
2.2k
Forks
263
Merge médio
1d 20h
PRs com merge (30d)
64

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de ruby/rbs

Todas as issues de ruby/rbs

Issues semelhantes

Mais issues de Ruby

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.