Using shared_examples within a module namespace without deprecation warning

68 views
Skip to first unread message

Hongli Lai

unread,
Aug 13, 2013, 2:00:00 PM8/13/13
to rs...@googlegroups.com
I have tests that basically look like this:

module Foo
  shared_examples_for "foo" do
    it "works" do
      true
    end
  end

  describe "bar" do
    it_behaves_like "foo"
  end
end

The reason why the RSpec commands are inside "module Foo" is because my namespace name is very long ("PhusionPassenger"), and I want to avoid prepending the namespace name to every class I refer to. Since a recent RSpec version, I'm getting a "Accessing shared_examples defined across contexts is deprecated" warning. How do I avoid this warning while still avoiding prepending my namespace before every class reference?

I cannot just "include PhusionPassenger" in the global context. That will pollute the global namespace with all sorts of classes, potentially overwriting existing ones.

Myron Marston

unread,
Aug 14, 2013, 1:11:10 AM8/14/13
to rs...@googlegroups.com
Hey Hongli,

In RSpec 2.14 we added a feature that allows users to scope shared example groups to the context they are declared in:


For backwards compatibility with other 2.x releases, it still supports using a shared example group from outside the scope if it cannot find it in the current scope, and prints a deprecation warning in this case.  Unfortunately, there was a slight bug in this that caused the warning to be wrongly printed in your case.  This was reported a bit ago and we have a fix ready:


I plan to cut another 2.14.x patch release soon (probably in the next day or two) with this fix in it.  Sorry for the trouble.

Myron

Myron Marston

unread,
Aug 14, 2013, 2:20:33 AM8/14/13
to rs...@googlegroups.com
I just released rspec-core 2.14.5 with this fix. 
Reply all
Reply to author
Forward
0 new messages