1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
# frozen_string_literal: true
RSpec.describe "prepending initializer" do # rubocop:disable RSpec/DescribeClass
context "when the class's initializer takes arguments" do
context "when it only takes positional arguments" do
let(:class_with_memo) do
Class.new do
prepend MemoWise
def initialize(arg); end
end
end
it "does not raise an error when initializing the class" do
expect { class_with_memo.new(:pos) }.to_not raise_error
end
end
context "when it only takes keyword arguments" do
let(:class_with_memo) do
Class.new do
prepend MemoWise
def initialize(kwarg:); end
end
end
it "does not raise an error when initializing the class" do
expect { class_with_memo.new(kwarg: :kw) }.to_not raise_error
end
end
context "when it takes both positional and keyword arguments" do
let(:class_with_memo) do
Class.new do
prepend MemoWise
def initialize(arg, kwarg:); end
end
end
it "does not raise an error when initializing the class" do
expect { class_with_memo.new(:pos, kwarg: :kw) }.to_not raise_error
end
end
context "when the method takes positional arguments, keyword arguments, and a block" do
let(:class_with_memo) do
Class.new do
prepend MemoWise
def initialize(arg, kwarg:, &blk)
blk.call(arg, kwarg) # rubocop:disable Performance/RedundantBlockCall
end
end
end
it "does not raise an error when initializing the class" do
expect { class_with_memo.new(:pos, kwarg: :kw) { true } }.to_not raise_error
end
end
end
end
|