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?
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
way above trivial details like the quality or feature count of either of
Phlip
Just to let you know, I’ve pasted my Facebook library (with tests).
Details are here:
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).
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…
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.
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.
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…
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
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.
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
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.
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.
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.
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
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:
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.
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!!
–
Phlip
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.