Here is an example of what I was talking about. Framework agnostic and
easy to extend:
https://github.com/rosenfeld/rails-sandbox-assets
As you can see, adding support for the Jasmine test runner on top of the
gem above is pretty simple:
https://github.com/rosenfeld/rails_sandbox_jasmine
Any chances of getting something like this built into Rails 4?
Cheers,
Rodrigo.
Em 23-05-2012 00:05, Rodrigo Rosenfeld Rosas escreveu:
A while ago I started a topic here asking for including any framework
for testing client-side code built into Rails and integrated to
generators as well.
Rails 4 would be a great opportunity for including such a feature.
By that time, most (including me) have suggested Jasmine as such a
framework. But actually I don't really care which framework would be
chosen as it could be easily replaced.
For example, it is pretty clear for me that Konacha has set the proper
way of dealing with such kind of tests:
https://github.com/jfirebaugh/konacha
Basically its approach is to provide two useful tasks:
konacha:serve - starts an isolated application sharing the asset
pipeline for in-browser test runner;
konacha:run - suitable for CI, although I'm still not sure what
approach to take for implementing such task, so this could be added in
the future, after the other task, which approach is more obvious to
opt for.
But it has a single issue that is too easy to be fixed - it is not
framework agnostic:
https://github.com/jfirebaugh/konacha/issues/37
If Rails provided the idea used by Konacha built in, but providing
hooks so that other gems could easily set up the template for their
JavaScript runners, this would be a great solution to client-side
integrated test solution.
Rails wouldn't even have to add support for common libraries, like
Sinon.js or Jasmine. It could include any test runner.
For example, since Rails opts for test/unit assertions style as well
as jQuery as default choices, it would make sense to keep with that
style by choosing QUnit, which is also developed by the jQuey team and
uses the assertions style:
https://github.com/jquery/qunit
http://docs.jquery.com/QUnit
I wouldn't use the default QUnit in the same way I don't use test/unit
for my Ruby tests, but it should be trivial to just add a gem composed
by one or two files that would enable me to use Jasmine while taking
advantage of the assets pipeline.
Of course I can already have something like this working in current
Rails, but the approach taken by Konacha seems so straightforward,
clean and simple to me that it seems that every runner should take a
similar approach basically changing only some settings like the
template of the runner as well as the pattern where to look for test
files.
It doesn't make sense for all similar gems to rewrite all the common
infrastructure. And it would be great to transmit the idea that
client-side code testing is as much important as server-side testing.
Actually chances are that client-side code will be more and more
important as time passes. And still, Rails seems to be ignoring that
by not providing tests for the CoffeeScript generated assets.
I wasn't sure about what approach to take at the time I first proposed
including any JavaScript testing framework into Rails, but now I'm
pretty convinced that Konacha's simple approach is the correct one to
take.
We would just need to add some hooks to make it framework-agnostic,
and that shouldn't be hard to do.
Any thoughts about this?
Kind regards,
Rodrigo.
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.