Accessing helper module constants in rspec contexts.

Discussion in 'Ruby' started by Tekhne, Feb 8, 2007.

  1. Tekhne

    Tekhne Guest

    I'm trying to learn rspec, and came across something unexpected with
    the following code. A little googling hasn't turned any answers up so
    far...

    module TestHelper
    CONSTANT = "constant"
    end

    context "A context" do
    include TestHelper

    specify "should allow unqualified access to included constants" do
    CONSTANT.should_eql "constant"
    end

    specify "should allow qualified access to all constants" do
    TestHelper::CONSTANT.should_eql "constant"
    end
    end

    ....I would expect both specifications to pass since I think that's the
    way Ruby itself behaves when using include (you get direct access to
    constants in the local scope when included, right?), but the
    unqualified specification fails. Is this a bug in rspec, a "feature"
    of rspec, a mistake on my part, or something else?
    Tekhne, Feb 8, 2007
    #1
    1. Advertising

  2. On 2/7/07, Tekhne <> wrote:
    > I'm trying to learn rspec, and came across something unexpected with
    > the following code. A little googling hasn't turned any answers up so
    > far...
    >
    > module TestHelper
    > CONSTANT = "constant"
    > end
    >
    > context "A context" do
    > include TestHelper
    >
    > specify "should allow unqualified access to included constants" do
    > CONSTANT.should_eql "constant"
    > end
    >
    > specify "should allow qualified access to all constants" do
    > TestHelper::CONSTANT.should_eql "constant"
    > end
    > end
    >
    > ...I would expect both specifications to pass since I think that's the
    > way Ruby itself behaves when using include (you get direct access to
    > constants in the local scope when included, right?), but the
    > unqualified specification fails. Is this a bug in rspec, a "feature"
    > of rspec, a mistake on my part, or something else?


    It's a known bug in rspec:

    http://rubyforge.org/tracker/index.php?func=detail&aid=7613&group_id=797&atid=3152

    Thanks for posting this - you may have actually shed some light on the
    problem by posing the qualified and unqualified references.

    Cheers,
    David

    >
    >
    >
    David Chelimsky, Feb 8, 2007
    #2
    1. Advertising

  3. Tekhne

    Tekhne Guest

    Tekhne, Feb 8, 2007
    #3
  4. On 2/8/07, Tekhne <> wrote:
    > On Feb 7, 9:10 pm, "David Chelimsky" <> wrote:
    > >
    > > It's a known bug in rspec:
    > >
    > > http://rubyforge.org/tracker/index.php?func=detail&aid=7613&group_id=...

    >
    > Ah, okay. Thanks a lot for the pointer. I should have searched the
    > tracker specifically. Next time =]


    No problem.

    Also - are you aware that there are lists specifically for rspec users
    and developers? I try to keep an eye on rspec related messages on the
    ruby-talk list, but the rspec lists have the eyes of a lot more people
    so you might get better traction on your rspec questions there:

    http://rubyforge.org/mail/?group_id=797

    Cheers,
    David

    >
    > Cheers,
    > Pete
    >
    >
    >
    David Chelimsky, Feb 8, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    0
    Views:
    414
    Albretch
    Aug 5, 2003
  2. jstorta
    Replies:
    1
    Views:
    523
    Arne Vajhøj
    Nov 18, 2007
  3. kevin
    Replies:
    1
    Views:
    370
    Kairi Zikpin
    Jul 21, 2006
  4. David Chelimsky
    Replies:
    0
    Views:
    111
    David Chelimsky
    Sep 15, 2009
  5. David Chelimsky
    Replies:
    0
    Views:
    109
    David Chelimsky
    Oct 3, 2010
Loading...

Share This Page