[rspec-devel] [ rspec-Patches-7461 ] [PATCH] Contexts don't call Module::included when they include a module
noreply at rubyforge.org
noreply at rubyforge.org
Sat Dec 30 00:54:16 EST 2006
Patches item #7461, was opened at 2006-12-26 16:41
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=7461&group_id=797
Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Pat Maddox (pergesu)
Assigned to: Nobody (None)
Summary: [PATCH] Contexts don't call Module::included when they include a module
Initial Comment:
module MyModule
module ClassMethods
def foo
"foo"
end
end
def self.included(receiver)
receiver.extend ClassMethods
end
end
context "Test context" do
include MyModule
foo
end
blows up because foo isn't defined. It turns out that the included method isn't being called at all. Now regardless of whether you think it's okay to use included like this to automatically extend a class, or you think that you should explicitly extend a class instead, Contexts shouldn't break Ruby's included callback method.
This patch fixes it up. It just adds
mod.send :included, self
to Context and ContextEval.
I included a spec for it, but it comes with a warning. The "mod.send" line is required in Context for the spec to pass. But if you just use that in code, then the code will fail. You have to have "mod.send" in ContextEval as well. However, the spec doesn't fail if you don't call it in ContextEval. So basically, the call in ContextEval is necessary for the desired behavior, but isn't covered by a spec. I haven't been able to come up with a failing spec for it...so hopefully someone who knows the RSpec internals better than I can come up with it.
----------------------------------------------------------------------
>Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-30 05:54
Message:
How do you know that this doesn't work without mod.send in ContextEval?
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=7461&group_id=797
More information about the rspec-devel
mailing list