Facebook plugin with test cases?

Railsters:

Here's the two Facebook plugins we have so far:

http://code.google.com/p/facebook-rails/
http://rfacebook.rubyforge.org/

Imagine my surprise when I discover that neither of them have unit tests!

If I considered unit tests to be the number one criteria for productivity - way above trivial details like the quality or feature count of either of those plugins - then neither qualify. How do you build a complex app like a Facebook portal without unit tests? (That's a rhetorical question, meaning please don't try to answer it.)

One of those plugins still embarrassingly has its generated default test case, test_this_plugin. Nobody replaced this with their real tests!

Is there a Facebook plugin out there with unit tests? Or any other _sustainable_ fix for this situation?

Or perhaps you could contribute to either project by submitting unit
tests? Just a thought...

Matt

Phlip wrote:

Railsters:

Here's the two Facebook plugins we have so far:

http://code.google.com/p/facebook-rails/
http://rfacebook.rubyforge.org/

Imagine my surprise when I discover that neither of them have unit tests!

If I considered unit tests to be the number one criteria for productivity - way above trivial details like the quality or feature count of either of those plugins - then neither qualify. How do you build a complex app like a Facebook portal without unit tests? (That's a rhetorical question, meaning please don't try to answer it.)

One of those plugins still embarrassingly has its generated default test case, test_this_plugin. Nobody replaced this with their real tests!

Is there a Facebook plugin out there with unit tests? Or any other _sustainable_ fix for this situation?

I'm nearly finished with a lightweight facebook library (doesn't include desktop stuff). It has a full test suite.

I did it because I needed it for Autopendium, and wasn't happy with including a plugin or gem that didn't have any test on a live production site.

Should be done within the next 48 hours (just have a little bit more to do, and then want to build a mini fb app with it to test it out.

If you need anything before then, email me and I'll send you what I've got.

Cheers
Chris

Thanks for your response - I'm digesting it. Until then, a little joke...

Autopendium :: Stuff about old cars http://autopendium.com

I have a 1949 Studebaker.

Of course, I had to replace the engine and tires.

And I replaced the chassis and seats.

But it occupies the same space!

Phlip wrote:

Thanks for your response - I'm digesting it. Until then, a little joke...

Autopendium :: Stuff about old cars http://autopendium.com
    
I have a 1949 Studebaker.

Of course, I had to replace the engine and tires.

And I replaced the chassis and seats.

But it occupies the same space!

Like it!
Chris
p.s. About to call it a day -- 1.35pm UK time, but will be back at work on the library tomorrow am. Will update with progress sometime tomorrow. All seems to be going quite smoothly ... so far

Phlip wrote:

Railsters:

Here's the two Facebook plugins we have so far:

http://code.google.com/p/facebook-rails/
http://rfacebook.rubyforge.org/

Imagine my surprise when I discover that neither of them have unit tests!

If I considered unit tests to be the number one criteria for productivity - way above trivial details like the quality or feature count of either of those plugins - then neither qualify. How do you build a complex app like a Facebook portal without unit tests? (That's a rhetorical question, meaning please don't try to answer it.)

One of those plugins still embarrassingly has its generated default test case, test_this_plugin. Nobody replaced this with their real tests!

Is there a Facebook plugin out there with unit tests? Or any other _sustainable_ fix for this situation?

Phlip

Just to let you know, I've pasted my Facebook library (with tests). Details are here:

http://pushrod.wordpress.com/2007/08/14/rails-ruby-facebook-and-tests-my-own-itch-scratched/

Haven't plugin-ized it yet, and am still working on my FB app, so it may well change as the app develops and has greater requirements.

However, it's got nearly all of the php lib's functionality (the main part missing is storing the fb object in a cookie), got a good number of tests (in fact they were written first), and is working for me. But I'd welcome some feedback (it's the first such thing I've written).

Cheers
Chris

Chris T wrote:

Just to let you know, I've pasted my Facebook library (with tests).
Details are here:

http://pushrod.wordpress.com/2007/08/14/rails-ruby-facebook-and-tests-my-own-itch-scratched/

Allow me to catch up - is this rFacebook, the existing plugin? or is it your new Facebook plugin _and_ its unit tests?

Don't blame me for counting the latter against you - the plugin market is so agile that the good ideas tend to conglomerate towards the market leaders faster than the fair competition can catch up...

Phlip wrote:

Chris T wrote:

Just to let you know, I've pasted my Facebook library (with tests).
Details are here:

http://pushrod.wordpress.com/2007/08/14/rails-ruby-facebook-and-tests-my-own-itch-scratched/
    
Allow me to catch up - is this rFacebook, the existing plugin? or is it your new Facebook plugin _and_ its unit tests?

Don't blame me for counting the latter against you - the plugin market is so agile that the good ideas tend to conglomerate towards the market leaders faster than the fair competition can catch up...

No, it's nothing to do with rFacebook. I couldn't get my head around that, and so it seemed simpler to write my own code based on the tests.

I looked at the the various elements of the Facebook php lib and tried to understand the behaviour, then wrote tests for that behaviour, then wrote the code.

By the way, it's not yet a plugin -- just a lib that you put in, er, /lib, and then you include the ControllerUtilities. However, it should be a very simple job to turn it into a plugin if there's any demand for it.

Primarily I wrote it to satisfy Autopendium's need for a Facebook library (with tests), and the lib approach worked fine for that. I'll try and write another post later on today with a walkthrough of usage, but if you have any comments on the tests or code in the meantime...

Cheers
Chris

Phlip wrote:

Chris T wrote:

Just to let you know, I've pasted my Facebook library (with tests).
Details are here:

http://pushrod.wordpress.com/2007/08/14/rails-ruby-facebook-and-tests-my-own-itch-scratched/
    
Allow me to catch up - is this rFacebook, the existing plugin? or is it your new Facebook plugin _and_ its unit tests?

Don't blame me for counting the latter against you - the plugin market is so agile that the good ideas tend to conglomerate towards the market leaders faster than the fair competition can catch up...

I've just posted a short intro to the library, including a bit about the Facebook request/response cycle. Even if you don't use the library (comments welcome, obviously), it should help you understand about the mythical Facebook object, and how it works.

http://pushrod.wordpress.com/2007/08/15/the-how-and-why-of-my-streamlined-rails-facebook-library/

Cheers
Chris

http://pushrod.wordpress.com/2007/08/14/rails-ruby-facebook-and-tests-my-own-itch-scratched/

To the cries of collaborative competition from your blog commenters I add:

I don't need unit tests saying rFacebook does its thing. The burden of their absence rests upon its maintainers. I need a system to unit test my website's connection to Facebook.

All entrants in the Great Rails Facebook Plugin Race need that, so we can run our tests without molesting the real Facebook.

Phlip wrote:

http://pushrod.wordpress.com/2007/08/14/rails-ruby-facebook-and-tests-my-own-itch-scratched/
    
To the cries of collaborative competition from your blog commenters I add:

I don't need unit tests saying rFacebook does its thing. The burden of their absence rests upon its maintainers. I need a system to unit test my website's connection to Facebook.

All entrants in the Great Rails Facebook Plugin Race need that, so we can run our tests without molesting the real Facebook.

So how does my (little) library stack up against that yardstick...

So how does my (little) library stack up against that yardstick...

I don't know. When I read the _top_ of the test suite, it seemed to concern itself with causing your Facebook interface to exist.

So you are probably going to claim I need to read to the _bottom_ of that file now. Jeeze good free help is hard to find! (-;

Phlip wrote:

So how does my (little) library stack up against that yardstick...
    
I don't know. When I read the _top_ of the test suite, it seemed to concern itself with causing your Facebook interface to exist.

So you are probably going to claim I need to read to the _bottom_ of that file now. Jeeze good free help is hard to find! (-;

My tests are very much written as part of the process of defining the behaviour. Not sure whether that's The Right Way, it's just how I do it, and It Works For Me. So I wrote a failing test which tries to instantiate a member of the Facebook class *before* I'd written the Facebook class (hence, it's the first test in the file).

Note, it doesn't assume at that point that the class provides an interface with Facebook's API, nor does it at any point make a call to the Facebook interface (so you can so we can "run your tests without molesting the real Facebook". In fact, there's even a test (line 225) to confirm that it doesn't :slight_smile:

Not requiring you of course to read down to even the middle of the file -- wrote the code for my own needs, and thought it might be useful to others. I'm not trying, however, to be an "entrant in the Great Rails Facebook Plugin Race." Life's too short, and there's much better things to do.

Cheers
Chris

Chris T wrote:

Note, it doesn't assume at that point that the class provides an
interface with Facebook's API, nor does it at any point make a call to
the Facebook interface (so you can so we can "run your tests without
molesting the real Facebook". In fact, there's even a test (line 225)
to confirm that it doesn't :slight_smile:

Right; but so far neither your plugin nor rFacebook explicitly says "write your site using these test facilities".

By comparison, Rails comes with goodies like the FunctionalTestCase, which gives us get :index, to test a web page with a ready-made system that matches what a real server would do. These systems are distinct from Rails's internal unit tests...

Not requiring you of course to read down to even the middle of the file
-- wrote the code for my own needs, and thought it might be useful to
others. I'm not trying, however, to be an "entrant in the Great Rails
Facebook Plugin Race." Life's too short, and there's much better things
to do.

Thus speaks the true entrant in the GRFPR!

Phlip wrote:

Chris T wrote:

Note, it doesn't assume at that point that the class provides an
interface with Facebook's API, nor does it at any point make a call to
the Facebook interface (so you can so we can "run your tests without
molesting the real Facebook". In fact, there's even a test (line 225)
to confirm that it doesn't :slight_smile:
    
Right; but so far neither your plugin nor rFacebook explicitly says "write your site using these test facilities".

By comparison, Rails comes with goodies like the FunctionalTestCase, which gives us get :index, to test a web page with a ready-made system that matches what a real server would do. These systems are distinct from Rails's internal unit tests...

Hmm. Not sure it's up to the library writer (NB it's not a plugin -- just a simple streamlined library that can easily be dropped in to the /lib folder) to provide tests above and beyond those for the library itslef. I don't see such tests in other plugins, even those with extensive suites. Also I guess it would assume that the user is using the same test framework as the library writer (RSpec or Test::Unit or something else).

Finally, it is Super Simple to look at the test code and see how to use it in your own code -- there's even a DummyController and DummyControllerTest defined to allow the ControllerUtilities module to be tested. And if that doesn't point the way, I don't know what does.

Of course, if that doesn't work for you, you can always do what I did and Roll Your Own.

GRFPR - so true. RFacebook was originally a quick library that I
wrote just for myself, and put it out there on my blog for others to
try out. Then came F8, and with it requests for updates, and more
features....and on and on. It gets harder to give it up with as you
invest more time :wink:

In any case, I'd just like to say thanks again to Chris for being so
insistent on having extensive unit testing. I really needed the kick
in the pants to finally get that in there (although it should have
been there in the first place, but chalk that up to being a bit of a
plugin newbie).

I blogged briefly about the addition of unit tests to RFacebook:

http://www.livelearncode.com/archives/26

I also requested developer help with the library, as I will have less
time in the coming months to maintain it. If anyone is interested,
please message me on Rubyforge.

cheers,
Matt

Matt P wrote:

In any case, I'd just like to say thanks again to Chris for being so
insistent on having extensive unit testing.

You have a typo there. You were clearly trying to write "Phlip".

(-;

I blogged briefly about the addition of unit tests to RFacebook:

http://www.livelearncode.com/archives/26

Where's the link to the tests themselves? (I can't remember how to install the plugin and see - sorry!!)

And I made this breakthru today: Mock the snot out of the FB plugin, right at the surface layer. Here's what's left of our login_as method:

  def login_as(user)
    session = @request.session

    if user &&= users(user)
      # TODO use user.id instead of 42??
      user.update_attribute :facebook_uid, 42 if user
      @request.session[:user] = user ? user.id : nil

      session[:rfacebook_fbsession] = {
        'user' => 42,
        'expires' => 1.day.from_now,
        'session_key' => 'key'
        }
      session[:user] = user.id
    else
      session[:user] = nil
    end
  end

Contrarily, here's what's left of the login filter on our controller:

  if RAILS_ENV != 'test'
    before_filter :require_facebook_login, :except => :load_sample_data_
  end

An 'if' statement in the production code does not a mock make. What - in my brief attempt to spelunk rFacebook, am I missing?

I also requested developer help with the library, as I will have less
time in the coming months to maintain it.

So will I!

We need everyone out there who's in a hetero relationship to start breeding! We need more Ruby programmers!!