[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
Thu Feb 1 08:33:25 EST 2007


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: runner module
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Pat Maddox (pergesu)
>Assigned to: David Chelimsky (dchelimsky)
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: 2007-02-01 13:33

Message:
I went ahead and applied this w/ a note in ContextEval re: the un-spec'd line of code.

Applied in rev 1453.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-12-30 06:11

Message:
That makes sense. It also leads me to believe that there should be a way to create a spec that fails without the line in ContextEval. Can you share a spec and code that only works if the line exists in ContextEval? That might help come up w/ a spec for it.

----------------------------------------------------------------------

Comment By: Pat Maddox (pergesu)
Date: 2006-12-30 06:01

Message:
I wrote the failing spec and implemented the code, which
didn't require ContextEval.  Then I used that in my project,
and it didn't work.  The error was an undefined method on a
ContextEval instance.  I then added the send to ContextEval,
and it worked fine.

----------------------------------------------------------------------

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