mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Populate previous_def/super with captured block args
The previous_def and super keywords do not propagate blocks. See: https://github.com/crystal-lang/crystal/issues/10399 This works around the issue by populating arguments if the method uses a block.
This commit is contained in:
parent
b52593dbde
commit
65a4b8e756
2 changed files with 88 additions and 3 deletions
|
@ -29,6 +29,15 @@ Spectator.describe "GitHub Issue #48" do
|
|||
def union : Int32 | String
|
||||
42.as(Int32 | String)
|
||||
end
|
||||
|
||||
def capture(&block : -> T) forall T
|
||||
block
|
||||
end
|
||||
|
||||
def capture(thing : T, &block : T -> T) forall T
|
||||
block.call(thing)
|
||||
block
|
||||
end
|
||||
end
|
||||
|
||||
mock Test, make_nilable: nil
|
||||
|
@ -95,4 +104,22 @@ Spectator.describe "GitHub Issue #48" do
|
|||
allow(fake).to receive(:union).and_return(:test)
|
||||
expect { fake.union }.to raise_error(TypeCastError, /Symbol/)
|
||||
end
|
||||
|
||||
it "handles captured blocks" do
|
||||
proc = ->{}
|
||||
allow(fake).to receive(:capture).and_return(proc)
|
||||
expect(fake.capture { nil }).to be(proc)
|
||||
end
|
||||
|
||||
it "raises on type cast error with captured blocks" do
|
||||
proc = ->{ 42 }
|
||||
allow(fake).to receive(:capture).and_return(proc)
|
||||
expect { fake.capture { "other" } }.to raise_error(TypeCastError, /Proc\(String\)/)
|
||||
end
|
||||
|
||||
it "handles captured blocks with arguments" do
|
||||
proc = ->(x : Int32) { x * 2 }
|
||||
allow(fake).to receive(:capture).and_return(proc)
|
||||
expect(fake.capture(5) { 5 }).to be(proc)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue