Forum: Ruby on Rails [sort of off topic] BDD with Javascript

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
90e140f8553ecdec1b0d7dbf608a0561?d=identicon&s=25 Pau Cor (phylae)
on 2008-11-08 16:42
I know this is a little off topic, but Rails is pretty much the only
place I use JavaScript at the moment, so I'm guessing that does come
into the equation a little bit.

I have learned to get quite a lot of the prototype. I choose prototype
as a library only because it ships with rails. I know the JavaScript I
write is not great. It gets the job done, and that's it. I want to bring
my JavaScript up to the next level.

One way I did that with Ruby was learning BDD with RSpec. So here's
question: what's the best way to go about learning/practicing BDD with
JavaScript?

I saw a really cool talk at confreaks.com
(http://lsrc2008.confreaks.com/10-yehuda-katz-using...)
about jQuery and ScrewUnit. It looks really cool, but I don't want to
decide just based one one video :)

So, what do you recommend for learning to do BDD with javascript? Which
frameworks, books, screencasts, etc?

Thanks
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2008-11-10 07:59
(Received via mailing list)
Hello--

On Nov 8, 2008, at 7:42 AM, Pau Cor wrote:

> One way I did that with Ruby was learning BDD with RSpec. So here's
> Which
> frameworks, books, screencasts, etc?

Wise of you to ask. I'll be curious to hear what others are using.
I've settled on jsspec for right now. It's not perfect, and it's not
at all integrated into the Rails test tasks, but it's pretty natural
when you are using rSpec for your Ruby code to use something with
similar syntactic sugar. You may want to have a read of this thread
re: screw.unit:

http://www.nabble.com/RSpec-vs-Screw.Unit-td20022203.html

My personal sense is that jsspec is just fine for what I'm using it to
accomplish, but that Screw.Unit is a more developed framework. That's
from reading, not side-by-side testing.

In terms of learning how, there is no way that's more correct than how
you learned rSpec. You probably looked at a lot of blog posts, some
better than others, maybe looked at the Peepcode, and got going. Now,
you know how to describe the behaviors. All you are doing is
translating it into a slightly different syntax. So, you might wind up
with something like this js (some functions of a simple UBB parser):

describe('replaceLinks in embeddeded URL case', {
   'should replace UBB embedded link with HTML link without protocol':
function() {
     testString = '[url=www.foo.com]';
     value_of(replaceLinks(testString)).should_be('<a
href="http://www.foo.com
">www.foo.com</a>');
   },

   'should replace UBB embedded link with HTML link with protocol':
function() {
     testString = '[url=http://www.foo.com]';
     value_of(replaceLinks(testString)).should_be('<a
href="http://www.foo.com
">www.foo.com</a>');
   },

   'should replace UBB typical link without protocol': function() {
     testString = '[url=www.foo.com]click here[/url]';
     value_of(replaceLinks(testString)).should_be('<a
href="http://www.foo.com
">click here</a>');
   },

   'should replace UBB typical link without protocol': function() {
     testString = '[url=http://www.foo.com]click here[/url]';
     value_of(replaceLinks(testString)).should_be('<a
href="http://www.foo.com
">click here</a>');
   }
});

Granted, the readability is not as good as rSpec's, but Javascript
ain't Ruby. I'm not certain how this would map to Screw.Unit, but it
didn't look like the mapping was too difficult.

HTH
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-10 10:07
(Received via mailing list)
On Nov 10, 6:58 am, "s.ross" <cwdi...@gmail.com> wrote:
> similar syntactic sugar. You may want to have a read of this thread  
> re: screw.unit:
>
I use the  Test.Unit framework that prototype uses for its unit tests
(you'll need to get the full package off the prototype website/git
repository for this) together with an updated version of the
javascript_test plugin (which lets you do stuff like rake
test:javacripts to run all of them rake test:javascripts TESTS=foo,bar
to run just those test suites etc...)

Fred
This topic is locked and can not be replied to.