Sha256: 6cd3ee6239d35d9832095d30ec72731369f88a5f45b57fbd47b6de9da7f8ed7c

Contents?: true

Size: 931 Bytes

Versions: 29

Compression:

Stored size: 931 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module Rails
    module ActiveSupportTestCaseHelper
      extend T::Sig

      sig { params(node: Prism::CallNode).returns(T.nilable(String)) }
      def extract_test_case_name(node)
        message_value = node.message
        return unless message_value == "test" || message_value == "it"

        arguments = node.arguments&.arguments
        return unless arguments&.any?

        first_argument = arguments.first

        content = case first_argument
        when Prism::InterpolatedStringNode
          parts = first_argument.parts

          if parts.all? { |part| part.is_a?(Prism::StringNode) }
            T.cast(parts, T::Array[Prism::StringNode]).map(&:content).join
          end
        when Prism::StringNode
          first_argument.content
        end

        if content && !content.empty?
          content
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ruby-lsp-rails-0.3.11 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.10 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.9 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.8 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.7 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.6 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.5 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.4 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
ruby-lsp-rails-0.3.3 lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb