Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spec for defined? on constant with const_missing #1215

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions language/defined_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@
defined?(DefinedSpecs::Undefined).should be_nil
end

it "returns nil when the constant is not defined and the outer module implements .const_missing" do
defined?(DefinedSpecs::ModuleWithConstMissing::Undefined).should be_nil
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic defining a new method in a class/module shared by multiple test cases may make them surprisingly coupled, what makes sense to avoid.

So I would add a new fixture module/class specifically for this test case, e.g. DefinedSpecs::ModuleWithConsMissing instead.


it "does not call .const_missing if the constant is not defined" do
DefinedSpecs.should_not_receive(:const_missing)
defined?(DefinedSpecs::UnknownChild).should be_nil
Expand Down
6 changes: 6 additions & 0 deletions language/fixtures/defined.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ def method_no_args
end
end

module ModuleWithConstMissing
def self.const_missing(const)
const
end
end

class SuperWithIntermediateModules
include IntermediateModule1
include IntermediateModule2
Expand Down