# Accessing helper module constants in rspec contexts

**URL:** <https://www.ruby-forum.com/t/accessing-helper-module-constants-in-rspec-contexts/84842>\
**Category:** Ruby\
**Created:** [February 8, 2007, 1:11am UTC](https://www.ruby-forum.com/t/accessing-helper-module-constants-in-rspec-contexts/84842 "2007-02-08T01:11:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [February 8, 2007, 1:11am UTC](https://www.ruby-forum.com/t/accessing-helper-module-constants-in-rspec-contexts/84842/1 "2007-02-08T01:11:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [February 8, 2007, 5:10am UTC](https://www.ruby-forum.com/t/accessing-helper-module-constants-in-rspec-contexts/84842/2 "2007-02-08T05:10:21Z")

</div>

On 2/7/07, Tekhne [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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](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

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [February 8, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/accessing-helper-module-constants-in-rspec-contexts/84842/3 "2007-02-08T17:05:35Z")

</div>

On Feb 7, 9:10 pm, “David C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s a known bug in rspec:
> 
> [http://rubyforge.org/tracker/index.php?func=detail&aid=7613&group\_id=](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 =]

Cheers,  
Pete

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [February 8, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/accessing-helper-module-constants-in-rspec-contexts/84842/4 "2007-02-08T19:40:53Z")

</div>

On 2/8/07, Tekhne [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Feb 7, 9:10 pm, “David C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > It’s a known bug in rspec:
> > 
> > [http://rubyforge.org/tracker/index.php?func=detail&aid=7613&group\_id=](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](http://rubyforge.org/mail/?group_id=797)

Cheers,  
David
