# Odd Behavior During Testing

**URL:** <https://www.ruby-forum.com/t/odd-behavior-during-testing/141266>\
**Category:** Radiant CMS\
**Created:** [June 24, 2008, 7:11am UTC](https://www.ruby-forum.com/t/odd-behavior-during-testing/141266 "2008-06-24T07:11:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [June 24, 2008, 7:11am UTC](https://www.ruby-forum.com/t/odd-behavior-during-testing/141266/1 "2008-06-24T07:11:11Z")

</div>

I’m completely lost here. Can anyone shed some light on this?

In the SnS extension I have created the following…

In styles\_n\_scripts\_extension.rb (activate method):  
SiteController.send :include, SiteControllerExtensions

In the /lib/site\_controller\_extensions.rb file:  
module SiteControllerExtensions; end (Yes, it’s empty. I stripped  
everything out trying to debug)

In the failing spec (describing SiteController):  
it “should render an existing page” do  
get :show\_page, :url =\> ‘/’  
response.body.should == “Hello World!”  
end

Apparently, the SiteController also mixes-in the login\_system which  
creates its own before\_filter that calls the #authenticate method. This  
method, in turn, calls no\_login\_required? SiteController _should_  
respond ‘true’ – that no login is required. But here’s where it gets  
weird…

If I comment out my include line (the one in the extension’s activate  
method above) SiteController does, indeed respond ‘true’ to  
no\_login\_required? But, the minute I add in that include and mix in my  
extensions – even with _nothing_ in my mixed-in module –  
SiteController starts responding ‘false’ – that login is required. My  
spec’ed get request then returns a redirect to the login page.

This only happens when running specs. Testing with a server in  
development mode works fine. Thoughts anyone?

-Chris

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [June 25, 2008, 4:30pm UTC](https://www.ruby-forum.com/t/odd-behavior-during-testing/141266/2 "2008-06-25T16:30:07Z")

</div>

Anyone?

Further testing shows that when I don’t include my module, I can verify  
during any controller’s spec that:  
controllers\_where\_no\_login\_required = [SiteController]

As soon as I mix it in (even though it’s an empty module), during the  
environment init and just before specs start to run:  
controllers\_where\_no\_login\_required = [SiteController]

But once the specs start to run, I get:  
controllers\_where\_no\_login\_required = []

Which, of course, messes up the tests.

Sounds like rSpec could be getting in the way but I don’t even know  
where to start here. Can anyone provide some insight – or even just  
suggest some way to start tackling this?

-Chris

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [June 25, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/odd-behavior-during-testing/141266/3 "2008-06-25T18:10:33Z")

</div>

Does the site work ok when you boot the server? Or is it only tests  
that are broken?

-Alex

> **[Beautiful Pixel](https://beautifulpixel.com/)**
>
> A log of random code experiments and semi-useless thoughts from some software developer named Alex...

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [June 25, 2008, 7:12pm UTC](https://www.ruby-forum.com/t/odd-behavior-during-testing/141266/4 "2008-06-25T19:12:47Z")

</div>

Only tests (specs, actually).
