For those of you who happen to also use ruby, and particularly rspec, I''ve been playing with a clone of rspec in javascript :) I suck at naming stuff, so it''s called js-spec, and depends on Proto 1.6. http://code.google.com/p/js-spec/ For now the functionality is very basic (1 day of coding), but includes: - several matchers, like something.should(equal(expected)), something.should(have(3, "items")) or something.shouldNot(respondTo("someMessage")) - all classes created via Class.create automatically gain ''should'' and ''shouldNot'' as instance methods (Function.wrap FTW!) - very very basic runner (console.log for all test output x__x) - filters (before all, before each, after each and after all) - it''s easy to define and register your own matchers To Do: - code an HTML report :) - test in something else than firefox - add more matchers, particularly stuff for DOM testing - redefine the internal API a bit so it''s easier to hook add stuff and a bit more DRY - write specs for the actual library :) Feedback is much appreciated ;-) Best, -Nicolas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Friday 21 December 2007, Nicolás Sanguinetti wrote:> For those of you who happen to also use ruby, and particularly rspec, > I''ve been playing with a clone of rspec in javascript :) > I suck at naming stuff, so it''s called js-spec, and depends on Proto > 1.6. > > http://code.google.com/p/js-spec/> To Do: > - code an HTML report :)Did you have a look at JSSpec? http://jania.pe.kr/aw/moin.cgi/JSSpec The UI looks nice, but I like your syntax better.> Feedback is much appreciated ;-)I''ve tried this simplistic spec var C = Class.create({ m: function() { return ''Hello''; } }); with (Spec) { describe(''A new C'', function() { with (this) { before(''each'', function() { this.c = new C(); }); it(''should respond to m'', function() { this.c.should(respondTo(''m'')); //''this'' is apparently needed }); it(''should greet me'', function() { this.c.should(be(''Hello'')); }); }}); } Spec.run(); I''ve run it in Firefox 2.0.0.11 using Prototype 1.6.0.1. The output I get is this [FAIL] should respond to m with: undefined [FAIL] should greet me with: undefined I''ve stepped through it in Firebug, however not very systematically. At least for the second test, apparently at some point the string ''Hello'' is converted into an array [''H'', ''e'', ''l'', ''l'', ''o'']. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 21, 2007 9:19 PM, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> > On Friday 21 December 2007, Nicolás Sanguinetti wrote: > > For those of you who happen to also use ruby, and particularly rspec, > > I''ve been playing with a clone of rspec in javascript :) > > I suck at naming stuff, so it''s called js-spec, and depends on Proto > > 1.6. > > > > http://code.google.com/p/js-spec/ > > > To Do: > > - code an HTML report :) > > Did you have a look at JSSpec?I only dad a brief look into it.> http://jania.pe.kr/aw/moin.cgi/JSSpec > > The UI looks nice, but I like your syntax better.:)> > Feedback is much appreciated ;-) > > I''ve tried this simplistic spec > > var C = Class.create({ > m: function() { return ''Hello''; } > }); > > with (Spec) { > describe(''A new C'', function() { with (this) { > before(''each'', function() { > this.c = new C(); > }); > it(''should respond to m'', function() { > this.c.should(respondTo(''m'')); //''this'' is apparently needed > }); > it(''should greet me'', function() { > this.c.should(be(''Hello'')); > }); > }}); > } > Spec.run();You can avoid this if you want, but then you have to also avoid it in the before("each"). I did it so every context runs sandboxed in a new, clean object, so you avoid name clashes.> I''ve run it in Firefox 2.0.0.11 using Prototype 1.6.0.1. The output I > get is this > > [FAIL] should respond to m with: undefined > [FAIL] should greet me with: undefinedYeah, it would have worked if you used ''return this.c.should...''. I know it''s stupid, it was a quick way out to have it working yesterday. I''ll commit in a little while the changes which include the HTML reporter and stop requiring ''return'' in every test, among other things :) Thanks for testing it out :)> I''ve stepped through it in Firebug, however not very systematically. At > least for the second test, apparently at some point the string ''Hello'' > is converted into an array [''H'', ''e'', ''l'', ''l'', ''o'']. > > Michael > > -- > Michael Schuerig > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org > http://www.schuerig.de/michael/-Nicolas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 22, 2007 1:56 AM, Nicolás Sanguinetti <godfoca-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can avoid this if you want, but then you have to also avoid it in > the before("each"). I did it so every context runs sandboxed in a new, > clean object, so you avoid name clashes.The "this" in the first sentence should''ve been quoted. Using "this.c.should..." inside the specs is only needed if you use "this.c = ..." in the before("each"). -N --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Saturday 22 December 2007, Nicolás Sanguinetti wrote:> On Dec 21, 2007 9:19 PM, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> > I''ve run it in Firefox 2.0.0.11 using Prototype 1.6.0.1. The output > > I get is this > > > > [FAIL] should respond to m with: undefined > > [FAIL] should greet me with: undefined > > Yeah, it would have worked if you used ''return this.c.should...''. I > know it''s stupid, it was a quick way out to have it working > yesterday. I''ll commit in a little while the changes which include > the HTML reporter and stop requiring ''return'' in every test, among > other thingsThis is one of the things I just don''t notice. I was completely flabbergasted why undefined was returned from a call to apply somewhere inside js-spec. Of course, I know that JavaScript needs explicit return statements, but I''m so used to Ruby that I simply don''t notice when they''re missing. I''ve looked into 0.2 and it still doesn''t work, at least for me, on Firefox 2.0.0.11. I think this line from Context#toElement is just too clever var element = new Element("div").insert(new Element("h3").update(this.name)).insert(new Element("ul")), list = element.down("ul"); The div is inserted alright, but the nested h3 and ul are not there and consequently list is undefined. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
It works fine in Firefox here (Mac). (I had 2.0.0.7, and upgraded to .11 and works fine in both of them) :S BTW, it also works in opera and safari, haven''t tested in IE, as I don''t have windows installed. And I tested your ''A new C'' example and also works. I changed a bit Context.toElement however and added a spec/index.html that runs several tests and pushed 0.2.1 up. Let me know if it works. Best, -Nicolas On Dec 22, 2007 8:53 AM, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> > On Saturday 22 December 2007, Nicolás Sanguinetti wrote: > > On Dec 21, 2007 9:19 PM, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote: > > > > I''ve run it in Firefox 2.0.0.11 using Prototype 1.6.0.1. The output > > > I get is this > > > > > > [FAIL] should respond to m with: undefined > > > [FAIL] should greet me with: undefined > > > > Yeah, it would have worked if you used ''return this.c.should...''. I > > know it''s stupid, it was a quick way out to have it working > > yesterday. I''ll commit in a little while the changes which include > > the HTML reporter and stop requiring ''return'' in every test, among > > other things > > This is one of the things I just don''t notice. I was completely > flabbergasted why undefined was returned from a call to apply somewhere > inside js-spec. Of course, I know that JavaScript needs explicit return > statements, but I''m so used to Ruby that I simply don''t notice when > they''re missing. > > I''ve looked into 0.2 and it still doesn''t work, at least for me, on > Firefox 2.0.0.11. I think this line from Context#toElement is just too > clever > > var element = new Element("div").insert(new > Element("h3").update(this.name)).insert(new Element("ul")), list > element.down("ul"); > > The div is inserted alright, but the nested h3 and ul are not there and > consequently list is undefined. > > Michael > > -- > Michael Schuerig > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org > http://www.schuerig.de/michael/ > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Saturday 22 December 2007, Nicolás Sanguinetti wrote:> It works fine in Firefox here (Mac). (I had 2.0.0.7, and upgraded to > .11 and works fine in both of them) :S > BTW, it also works in opera and safari, haven''t tested in IE, as I > don''t have windows installed. > > And I tested your ''A new C'' example and also works.Is (2).should(be(2)); supposed to pass? It fails with with: expected 2 to be === 2 (2).should(equal(2)); passes.> I changed a bit Context.toElement however and added a spec/index.html > that runs several tests and pushed 0.2.1 up. Let me know if it works.From the spec I get these errors in Firefox as well as Konqueror (3.5.8) # [failed]should handle failures correctly with: expected 2 to be > 1 # [pending]should handle pending specs # [error]should handle errors correctly with: undefined has no properties Anyway, I like js-spec a lot and hope I can help to polish a few rough edges. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 22, 2007 1:11 PM, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> (2).should(be(2));That''s something really messed up with ''instanced'' Numbers. typeof new Number(1) //=> ''object'' new Number(1) == new Number(1) //=> false The number to which you call ''should'' will use an instance of Number, while the other one will only be a "value" and won''t have any methods. Even worse, Object.isNumber(new Number(1)) returns false :-\ So I redefined Object.isNumber and then hacked Matcher.Be.=== to check if both are numbers first, in which case returns x == y. It works now, but I''m not really sure doing that is the best approach. If anyone has any ideas I''d be glad to hear them :) I''ve uploaded this as 0.2.2.> From the spec I get these errors in Firefox as well as Konqueror (3.5.8) > > # [failed]should handle failures correctly > with: expected 2 to be > 1 > # [pending]should handle pending specs > # [error]should handle errors correctly > with: undefined has no propertiesYeah, those 4 were supposed to be like that (show an example of what happens with the possible results), but I suppose I wasn''t very clear with the naming, as most people that looked at it asked me about those. I removed them from the example and will keep them in a separate test :) Thanks for all the help, -Nicolas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Nicolás, Looks like compressed versions fail when trying to "rake dist" - / matchers/be.js is missing Checking out repository directly works as expected. Am I missing something? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Apparently rake''s PackageTask didn''t go recursively down directories :-\ I''ve updated the packages with the code. Best, -Nicolas On Dec 22, 2007 3:14 PM, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Nicolás, > > Looks like compressed versions fail when trying to "rake dist" - / > matchers/be.js is missing > Checking out repository directly works as expected. > > Am I missing something? > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Saturday 22 December 2007, Nicolás Sanguinetti wrote:> Apparently rake''s PackageTask didn''t go recursively down directories > :-\ I''ve updated the packages with the code.I''ve attached a small patch for 0.2.2. The point is that I''d like to be able use js-spec on code that itself does not depend on any particular lib such as Prototype. For an example see http://schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/ Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 22, 2007 4:27 PM, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> On Saturday 22 December 2007, Nicolás Sanguinetti wrote: > > Apparently rake''s PackageTask didn''t go recursively down directories > > :-\ I''ve updated the packages with the code. > > I''ve attached a small patch for 0.2.2. The point is that I''d like to be > able use js-spec on code that itself does not depend on any particular > lib such as Prototype.Good idea :) Just commited it.> For an example see > > http://schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/ > > Michael > > -- > Michael Schuerig > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org > http://www.schuerig.de/michael/ > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---