Google Groups Home
Help | Sign in
assert_event_logged ???
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
taryn  
View profile
 More options Mar 3, 11:37 pm
From: taryn <googleGro...@taryneast.org>
Date: Mon, 3 Mar 2008 20:37:55 -0800 (PST)
Local: Mon, Mar 3 2008 11:37 pm
Subject: assert_event_logged ???
Does anyone know of a way to test whether or not a log event actually
made it into the log?
We want to make sure that some of our important events (eg "user x was
archived by user y") actually make it into the log.

but AFAICS there's no way to get information back *out* of logger -
it's input-only.

I could hook up something ugly by setting up a fake logger and
checking if it's empty after running a block of code... but I was
hoping for something more elegent.

Any clues?
Anyone done this before?
Anyone think it's a stupid idea (and willing to share why)?

Taryn


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xavier Shay  
View profile
 More options Mar 3, 11:41 pm
From: Xavier Shay <xavier-l...@rhnh.net>
Date: Tue, 4 Mar 2008 15:41:18 +1100
Local: Mon, Mar 3 2008 11:41 pm
Subject: Re: [rails-oceania] assert_event_logged ???
> I could hook up something ugly by setting up a fake logger and
> checking if it's empty after running a block of code... but I was
> hoping for something more elegent.

This is classically how you automatically test external services (see  
action mailer tests, see activemessaging tests)

Xav


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cameron Barrie  
View profile
 More options Mar 3, 11:42 pm
From: Cameron Barrie <pho...@mvpaustralia.com.au>
Date: Tue, 4 Mar 2008 15:42:23 +1100
Local: Mon, Mar 3 2008 11:42 pm
Subject: Re: [rails-oceania] assert_event_logged ???
Could you check if the logger.class was sent a method such as info or  
error?

Cameron

On 04/03/2008, at 3:37 PM, taryn wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
taryn  
View profile
 More options Mar 3, 11:45 pm
From: taryn <googleGro...@taryneast.org>
Date: Mon, 3 Mar 2008 20:45:51 -0800 (PST)
Local: Mon, Mar 3 2008 11:45 pm
Subject: Re: assert_event_logged ???
Ya - done it with ActionMailer - but that seems less ugly because you
can actually access data *from* ActionMailer. For Logger I'd have to
set up a temporary logger file, then use some sort of dodgy system
calls to manually go through the file to figureout the strings in
it. :P
This feels ugly to me.
I'd much prefer to be able to do something like
assert_equal my_msg, logger.last_message

 ;)

On Mar 4, 3:41 pm, Xavier Shay <xavier-l...@rhnh.net> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
taryn  
View profile
 More options Mar 3, 11:46 pm
From: taryn <googleGro...@taryneast.org>
Date: Mon, 3 Mar 2008 20:46:45 -0800 (PST)
Local: Mon, Mar 3 2008 11:46 pm
Subject: Re: assert_event_logged ???

On Mar 4, 3:42 pm, Cameron Barrie <pho...@mvpaustralia.com.au> wrote:

> Could you check if the logger.class was sent a method such as info or
> error?

Not sure how I'd do that. Do you know?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lachie  
View profile
 More options Mar 3, 11:50 pm
From: Lachie <lach...@gmail.com>
Date: Tue, 4 Mar 2008 15:50:13 +1100
Local: Mon, Mar 3 2008 11:50 pm
Subject: Re: [rails-oceania] assert_event_logged ???

On Tue, Mar 4, 2008 at 3:37 PM, taryn <googleGro...@taryneast.org> wrote:

>  Does anyone know of a way to test whether or not a log event actually
>  made it into the log?
>  We want to make sure that some of our important events (eg "user x was
>  archived by user y") actually make it into the log.

>  but AFAICS there's no way to get information back *out* of logger -
>  it's input-only.

I've written a rails log parser, but its crude and only reads logs
from a fairly specific version of rails.

What I've done in the past is have a separate log (I called it an audit log).
The output was tab delimited and in a machine readable format, with fields like
time of event in epoch seconds
the component (maybe UsersController)
an event label (maybe user_archived)
then some event specific parameters (user x, user y, etc)

Then reading the logs back later for analysis or, say auditing is very easy

I'd unit test and implement it as its own specific class. From the
components which use it, mock up your audit logger's interface

You could implement it as a singleton:

class Audit
  def self.log(event,*args)
    ...
  end
end

call it in your code like

Audit.log(:user_archived,user_x.id,user_y.id)

would that work?

>  I could hook up something ugly by setting up a fake logger and
>  checking if it's empty after running a block of code... but I was
>  hoping for something more elegent.

>  Any clues?
>  Anyone done this before?
>  Anyone think it's a stupid idea (and willing to share why)?

>  Taryn

--
Lachie
http://blog.smartbomb.com.au
http://www.flickr.com/photos/lachie/

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cameron Barrie  
View profile
 More options Mar 3, 11:50 pm
From: Cameron Barrie <pho...@mvpaustralia.com.au>
Date: Tue, 4 Mar 2008 15:50:13 +1100
Local: Mon, Mar 3 2008 11:50 pm
Subject: Re: [rails-oceania] Re: assert_event_logged ???
I'm sure you could create some sort of observer on the class that the  
logger object is instantiated from and assert that it is sent a  
method call for info or error(which ever one your calling).

Cam

On 04/03/2008, at 3:46 PM, taryn wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pete Yandell  
View profile
 More options Mar 3, 11:59 pm
From: Pete Yandell <p...@notahat.com>
Date: Tue, 4 Mar 2008 15:59:02 +1100
Local: Mon, Mar 3 2008 11:59 pm
Subject: Re: [rails-oceania] assert_event_logged ???

On 04/03/2008, at 3:37 PM, taryn wrote:

> Does anyone know of a way to test whether or not a log event actually
> made it into the log?
> We want to make sure that some of our important events (eg "user x was
> archived by user y") actually make it into the log.

If you're using rspec, you can grab my Not A Mock plugin and use call  
recording to track calls to the logger, something like:

   it "should log correctly" do
     RAILS_DEFAULT_LOGGER.track_method(:info)
     # Run your test
     RAILS_DEFAULT_LOGGER.should have_received(:info).with(...)
   end

More info on Not A Mock, including installation instructions are here: http://notahat.com/not_a_mock

- Pete


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lachie  
View profile
 More options Mar 3, 11:59 pm
From: Lachie <lach...@gmail.com>
Date: Tue, 4 Mar 2008 15:59:28 +1100
Local: Mon, Mar 3 2008 11:59 pm
Subject: Re: [rails-oceania] Re: assert_event_logged ???
On Tue, Mar 4, 2008 at 3:50 PM, Cameron Barrie

<pho...@mvpaustralia.com.au> wrote:

>  I'm sure you could create some sort of observer on the class that the
>  logger object is instantiated from and assert that it is sent a
>  method call for info or error(which ever one your calling).

Yeah, if you want to test the normal logger, use a mock

I'm using RR at the moment. I'd do it like

mock(your_object.logger).debug("the expected message")

If your_object.logger doesn't receive the debug message with "the
expected message" the test will FAIL.

other mocking libs can do the same thing, you'll just have to look up the doco

For test unit, I'd recommend either RR or Mocha (Mocha being the more mature)

--
Lachie
http://blog.smartbomb.com.au
http://www.flickr.com/photos/lachie/

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
taryn  
View profile
 More options Mar 3, 11:59 pm
From: taryn <googleGro...@taryneast.org>
Date: Mon, 3 Mar 2008 20:59:55 -0800 (PST)
Local: Mon, Mar 3 2008 11:59 pm
Subject: Re: assert_event_logged ???
Interesting idea. So basically have a generic log and an "event log"
for important, auditable events. Cool... and I'd write my own accessor
methods for the latest methods - which would require keeping around
the last few messages, or whatever.

Cool idea, but sadly not a quick-to-implement one ;)
More of a long-term solution - which I assume will not make it past
the PM. :(
But I'll put t to him anyway.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
taryn  
View profile
 More options Mar 4, 12:01 am
From: taryn <googleGro...@taryneast.org>
Date: Mon, 3 Mar 2008 21:01:28 -0800 (PST)
Local: Tues, Mar 4 2008 12:01 am
Subject: Re: assert_event_logged ???

On Mar 4, 3:50 pm, Cameron Barrie <pho...@mvpaustralia.com.au> wrote:

> I'm sure you could create some sort of observer on the class that the
> logger object is instantiated from and assert that it is sent a
> method call for info or error(which ever one your calling).

This sounds like a good idea for the current system. I'll have a look
into observers - of which I have only passing aquaintence through the
user notifier ;)

Thanks both of you :)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Palmer  
View profile
 More options Mar 4, 12:11 am
From: Matt Palmer <mpal...@hezmatt.org>
Date: Tue, 4 Mar 2008 16:11:42 +1100
Local: Tues, Mar 4 2008 12:11 am
Subject: Re: assert_event_logged ???

On Mon, Mar 03, 2008 at 08:46:45PM -0800, taryn wrote:

> On Mar 4, 3:42 pm, Cameron Barrie <pho...@mvpaustralia.com.au> wrote:
> > Could you check if the logger.class was sent a method such as info or
> > error?

> Not sure how I'd do that. Do you know?

Mock objects.

require 'mocha'

class MockLogTest < Test::Unit::TestCase
        def test_will_pass
                RAILS_DEFAULT_LOGGER.expects(:info).at_least_once.with("something funny")
                RAILS_DEFAULT_LOGGER.info("something funny")
        end

        def test_will_fail
                RAILS_DEFAULT_LOGGER.expects(:info).at_least_once.with("something funny")
                RAILS_DEFAULT_LOGGER.info("something else")
        end
end

- Matt


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoff Tench  
View profile
 More options Mar 4, 12:29 am
From: "Geoff Tench" <geoff.te...@gmail.com>
Date: Tue, 4 Mar 2008 16:29:29 +1100
Local: Tues, Mar 4 2008 12:29 am
Subject: Re: [rails-oceania] assert_event_logged ???