[sort of off topic] BDD with Javascript

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-jquery-with-ruby-web-frameworks.html)
about jQuery and ScrewUnit. It looks really cool, but I don’t want to
decide just based one one video :slight_smile:

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

Thanks

Hello–

On Nov 8, 2008, at 7:42 AM, Pau C. 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(‘www.foo.com’);
},

‘should replace UBB embedded link with HTML link with protocol’:
function() {
testString = ‘[url=http://www.foo.com]’;
value_of(replaceLinks(testString)).should_be(‘www.foo.com’);
},

‘should replace UBB typical link without protocol’: function() {
testString = ‘click here’;
value_of(replaceLinks(testString)).should_be(‘click here’);
},

‘should replace UBB typical link without protocol’: function() {
testString = ‘click here’;
value_of(replaceLinks(testString)).should_be(‘click here’);
}
});

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

On Nov 10, 6:58 am, “s.ross” [email protected] 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