module RBS::UnitTest::WithAliases
WithAliases module provides with_*** methods that helps writing tests which passes convertible objects
include WithAliases with_int do |i| # Yields Integer and RBS::UnitTest::Convertibles::ToInt end with_string.and_nil do |s| # Yields String, RBS::UnitTest::Convertibles::ToStr, and nil end
Public Instance Methods
(*untyped args) → void
(*untyped args) { (untyped) → void } → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 41 def with(*args, &block) return WithEnum.new to_enum(__method__ || raise, *args) unless block args.each(&block) end
Yields args objects
[T] (*T elements) { (array[T]) → void } → void
[T] (*T elements) → WithEnum[array[T]]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 64 def with_array(*elements) return WithEnum.new to_enum(__method__ || raise, *elements) unless block_given? yield _ = elements yield ToArray.new(*elements) end
Yields ::array objects
() { (bool) → void } → void
() → WithEnum[bool]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 105 def with_bool(&block) return WithEnum.new to_enum(__method__ || raise) unless block yield true yield false end
Yields ::bool objects
() { (boolish) → void } → void
() → WithEnum[boolish]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 111 def with_boolish(&block) return WithEnum.new to_enum(__method__ || raise) unless block with_bool(&block) [nil, 1, Object.new, BlankSlate.new, "hello, world!"].each(&block) end
Yields ::boolish objects
Also aliased as: with_untyped
(?untyped encoding) { (encoding) → void } → void
(?untyped encoding) → WithEnum[encoding]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 91 def with_encoding(encoding = Encoding::UTF_8, &block) return WithEnum.new to_enum(__method__ || raise, encoding) unless block block.call encoding with_string(encoding.to_s, &block) end
Yields ::encoding objects
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 52 def with_float(value = 0.1) return WithEnum.new to_enum(__method__ || raise, value) unless block_given? yield value yield ToF.new(value) end
Yields ::float objects
[K, V] (?Hash[K, V] hash) { (hash[K, V]) → void } → void
[K, V] (?Hash[K, V] hash) → WithEnum[hash[K, V]]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 71 def with_hash(hash = {}) return WithEnum.new to_enum(__method__ || raise, hash) unless block_given? yield _ = hash yield ToHash.new(hash) end
Yields ::hash objects
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 46 def with_int(value = 3, &block) return WithEnum.new to_enum(__method__ || raise, value) unless block yield value yield ToInt.new(value) end
Yields ::int objects
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 98 def with_interned(value = :&, &block) return WithEnum.new to_enum(__method__ || raise, value) unless block with_string(value.to_s, &block) block.call value.to_sym end
Yields ::interned objects
(?untyped io) { (io) → void } → void
(?untyped io) → WithEnum[io]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 78 def with_io(io = $stdout) return WithEnum.new to_enum(__method__ || raise, io) unless block_given? yield io yield ToIO.new(io) end
Yields ::io objects
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 84 def with_path(path = "/tmp/foo.txt", &block) return WithEnum.new to_enum(__method__ || raise, path) unless block with_string(path, &block) block.call ToPath.new(path) end
Yields ::path objects
(WithEnum[untyped] start, WithEnum[untyped] stop, ?bool exclude_end) { (range[untyped]) → void } → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 119 def with_range(start, stop, exclude_end = false) # If you need fixed starting and stopping points, you can just do `with_range with(1), with(2)`. raise ArgumentError, '`start` must be from a `with` method' unless start.is_a? WithEnum raise ArgumentError, '`stop` must be from a `with` method' unless stop.is_a? WithEnum start.each do |lower| stop.each do |upper| yield CustomRange.new(lower, upper, exclude_end) # `Range` requires `begin <=> end` to return non-nil, but doesn't actually # end up using the return value of it. This is to add that in when needed. unless defined? lower.<=> def lower.<=>(rhs) = :not_nil # steep:ignore MethodDefinitionInUndeclaredModule end # If `lower <=> rhs` is defined but nil, then that means we're going to be constructing # an illegal range (eg `3..ToInt.new(4)`). So, we need to skip yielding an invalid range # in that case. next if defined?(lower.<=>) && nil == (lower <=> upper) yield Range.new(lower, upper, exclude_end) end end end
Yields ::range objects
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/unit_test/with_aliases.rb, line 58 def with_string(value = '') return WithEnum.new to_enum(__method__ || raise, value) unless block_given? yield value yield ToStr.new(value) end
Yields ::string objects
() { (untyped) → void } → void
() → WithEnum[untyped]
Yields ::untyped objects
Alias for: with_boolish