Ryan Platte wrote:

> For Rails apps, by way of not testing the library('s JavaScript
> output): stub out RJS's JavaScriptGenerator ('page' object)?

Ultimately we are up against a "log string test". That's where you call an 
emulator or a real deal of some type, it emits a log of its behavior, and 
you parse into this log.

You could, for example, take some server program, turn its log level up, 
call a high level function, read the log file as a string, and perform 
Regular Expressions on it to pull out target data. (/Error (.*)/ is a good 
start!;)

Next, you might write a mock that records the calls sent to it as a sequence 
of data items, like the MockGraphics example I started this thread with.

Here's the diagnostic when an assert_rjs fails:

Content did not include:
 $("moose_panel").width = "50%";.
<"$(\"wiki_panel\").width = \"50%\";\n$(\"mouse_panel\").width = 
\"50%\";\nElement.update(\"mouse_panel\", \"<iframe height=\\\"100%\\\" 
src=\\\"/character/hammy_squirrel\\\" id=\\\"test_frame\\\" 
width=\\\"100%\\\"/>\");\nElement.show(\"mouse_panel\");"> expected to be =~
</\$\("moose_panel"\)\.width\ =\ "50%";/>.

Note that's not even perfectly robust for a log string test. I could write 
page['moose_panel'].width = '50%', then a few lines later write 
page['mouse_panel'].width = '50%', and this won't catch the bug: assert_rjs 
:page, 'moose_panel', :width=, '50%'. It would find the first line spelled 
right, not the later line spelled wrong.

A better Log String Test would snarf each line as it tested.

Don't get me wrong - assert_rjs is an excellent place to start; it's a 
lowest common denominator that at least matches Rails' incredible talent for 
lean and expressive statements. I would use it first before seeking a way to 
test semantics.

But that's what a mock RJS jigger would do - test that we called our RJS 
object in such-and-so ways.

> That was
> the first thing I thought when I heard about RJS. Surfing the code, it
> looks quite possible using Mocha if it was desirable. I haven't thought
> through all the ramifications. The OP includes testing the source page
> -- maybe also some work on the APIs to link to and submit forms to Ajax
> actions would permit those to be stubbed out as well.

I want a test case that fails if two Ajax commands overlap each other and 
blot each other out. That requires emulating DOM, and I really think someone 
smarter than I could do the equivalent in 2% of the lines of code I 
envision.

> Has someone already created such a beast? (Besides Google's GWT?)

http://www.google.com/search?domains=code.google.com&sitesearch=code.google.com&q=test

They seem aware of JUnit. ;-)

-- 
  Phlip
  http://www.greencheese.us/ZeekLand <-- NOT a blog!!!