Skip to content

Commit

Permalink
test(ruby): fix Ruby 3.3 incompatibilies
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Jan 24, 2024
1 parent 01941dd commit 4e64e8d
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,24 @@ def respond_to_missing_public?(...)
end
end

it "is private" do
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { instance_proxy.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for #{target}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "is private" do
expect { instance_proxy.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for an instance of #{target.class}/)
end
else
it "is private" do
expect { instance_proxy.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for #{target}/)
end
end
# rubocop:enable RSpec/RepeatedDescription

specify do
expect { instance_proxy.respond_to_missing_public?(method_name, include_private) }
Expand Down
75 changes: 54 additions & 21 deletions spec/lib/convenient_service/core/concern/class_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,24 @@ def foo(*args, **kwargs, &block)
end
end

it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it).
#
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_class.foo }.to raise_error(NoMethodError).with_message(/undefined method `foo' for #{service_class}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it).
#
expect { service_class.foo }.to raise_error(NoMethodError).with_message(/undefined method `foo' for class #{service_class}/)
end
else
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it).
#
expect { service_class.foo }.to raise_error(NoMethodError).with_message(/undefined method `foo' for #{service_class}/)
end
end

specify do
Expand All @@ -253,14 +264,26 @@ def foo(*args, **kwargs, &block)
end
end

it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it), but has middlewares.
#
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_class.foo }.to raise_error(NoMethodError).with_message(/super: no superclass method `foo' for #{service_class}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it), but has middlewares.
#
expect { service_class.foo }.to raise_error(NoMethodError).with_message(/super: no superclass method `foo' for class #{service_class}/)
end
else
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it), but has middlewares.
#
expect { service_class.foo }.to raise_error(NoMethodError).with_message(/super: no superclass method `foo' for #{service_class}/)
end
end
# rubocop:enable RSpec/RepeatedDescription

if ConvenientService::Dependencies.ruby.version >= 3.0
##
Expand Down Expand Up @@ -298,14 +321,24 @@ def respond_to_missing_public?(...)
end
end

it "is private" do
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_class.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for #{service_class}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "is private" do
expect { service_class.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for class #{service_class}/)
end
else
it "is private" do
expect { service_class.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for #{service_class}/)
end
end
# rubocop:enable RSpec/RepeatedDescription

context "when `include_private` is `false`" do
let(:include_private) { false }
Expand Down
75 changes: 54 additions & 21 deletions spec/lib/convenient_service/core/concern/instance_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,26 @@ def foo(*args, **kwargs, &block)
end
end

it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it).
#
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_instance.foo }.to raise_error(NoMethodError).with_message(/undefined method `foo' for #{service_instance}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it).
#
expect { service_instance.foo }.to raise_error(NoMethodError).with_message(/undefined method `foo' for an instance of #{service_instance.class}/)
end
else
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it).
#
expect { service_instance.foo }.to raise_error(NoMethodError).with_message(/undefined method `foo' for #{service_instance}/)
end
end
# rubocop:enable RSpec/RepeatedDescription

specify do
expect { ignoring_exception(NoMethodError) { service_instance.foo } }.to delegate_to(ConvenientService, :reraise)
Expand All @@ -110,13 +122,24 @@ def foo(*args, **kwargs, &block)
end
end

it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it), but has middlewares.
#
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_instance.foo }.to raise_error(NoMethodError).with_message(/super: no superclass method `foo' for #{service_instance}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it), but has middlewares.
#
expect { service_instance.foo }.to raise_error(NoMethodError).with_message(/super: no superclass method `foo' for an instance of #{service_instance.class}/)
end
else
it "raises `NoMethodError`" do
##
# NOTE: Intentionally calling missed method that won't be included (no concerns with it), but has middlewares.
#
expect { service_instance.foo }.to raise_error(NoMethodError).with_message(/super: no superclass method `foo' for #{service_instance}/)
end
end

if ConvenientService::Dependencies.ruby.version >= 3.0
Expand Down Expand Up @@ -153,14 +176,24 @@ def respond_to_missing_public?(...)
end
end

it "is private" do
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_instance.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for #{service_instance}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "is private" do
expect { service_instance.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for an instance of #{service_instance.class}/)
end
else
it "is private" do
expect { service_instance.respond_to_missing?(method_name, include_private) }
.to raise_error(NoMethodError)
.with_message(/private method `respond_to_missing\?' called for #{service_instance}/)
end
end
# rubocop:enable RSpec/RepeatedDescription

context "when `include_private` is `false`" do
let(:include_private) { false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,18 @@ def next(...)
end
end

it "raises `NoMethodError`" do
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_instance.result }.to raise_error(NoMethodError).with_message(/super: no superclass method `result' for #{service_instance}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "raises `NoMethodError`" do
expect { service_instance.result }.to raise_error(NoMethodError).with_message(/super: no superclass method `result' for an instance of #{service_instance.class}/)
end
else
it "raises `NoMethodError`" do
expect { service_instance.result }.to raise_error(NoMethodError).with_message(/super: no superclass method `result' for #{service_instance}/)
end
end
end

Expand Down Expand Up @@ -180,12 +187,20 @@ def next(...)
end
end

it "raises `NoMethodError`" do
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
expect { service_class.result }.to raise_error(NoMethodError).with_message(/super: no superclass method `result' for #{service_class}/)
##
# NOTE: Depending on the `did_you_mean` version, an additional line may be added to the exception message, which is why the `with_message` string is replaced by regex.
#
# rubocop:disable RSpec/RepeatedDescription
if ConvenientService::Dependencies.ruby.version >= 3.3
it "raises `NoMethodError`" do
expect { service_class.result }.to raise_error(NoMethodError).with_message(/super: no superclass method `result' for class #{service_class}/)
end
else
it "raises `NoMethodError`" do
expect { service_class.result }.to raise_error(NoMethodError).with_message(/super: no superclass method `result' for #{service_class}/)
end
end
# rubocop:enable RSpec/RepeatedDescription
end

context "when super is defined" do
Expand Down

0 comments on commit 4e64e8d

Please sign in to comment.