# \[sort of off topic\] BDD with Javascript

**URL:** <https://www.ruby-forum.com/t/sort-of-off-topic-bdd-with-javascript/152866>\
**Category:** Rails\
**Created:** [November 8, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/sort-of-off-topic-bdd-with-javascript/152866 "2008-11-08T16:42:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phylae](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@phylae](https://www.ruby-forum.com/u/phylae)\
**Post date:** [November 8, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/sort-of-off-topic-bdd-with-javascript/152866/1 "2008-11-08T16:42:12Z")

</div>

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://confreaks.com)  
([http://lsrc2008.confreaks.com/10-yehuda-katz-using-jquery-with-ruby-web-frameworks.html](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 🙂

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

Thanks

---

<div class="post-metadata">

**Author:** ![phylae](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@phylae](https://www.ruby-forum.com/u/phylae)\
**Post date:** [November 10, 2008, 7:59am UTC](https://www.ruby-forum.com/t/sort-of-off-topic-bdd-with-javascript/152866/2 "2008-11-10T07:59:44Z")

</div>

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](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](http://url=www.foo.com)]’;  
value\_of(replaceLinks(testString)).should\_be(‘[www.foo.com](http://www.foo.com)’);  
},

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

‘should replace UBB typical link without protocol’: function() {  
testString = ‘[click here](https://www.foo.com)’;  
value\_of(replaceLinks(testString)).should\_be(‘[click here](http://www.foo.com)’);  
},

‘should replace UBB typical link without protocol’: function() {  
testString = ‘[click here](http://www.foo.com)’;  
value\_of(replaceLinks(testString)).should\_be(‘[click here](http://www.foo.com)’);  
}  
});

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

---

<div class="post-metadata">

**Author:** ![phylae](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@phylae](https://www.ruby-forum.com/u/phylae)\
**Post date:** [November 10, 2008, 10:07am UTC](https://www.ruby-forum.com/t/sort-of-off-topic-bdd-with-javascript/152866/3 "2008-11-10T10:07:29Z")

</div>

On Nov 10, 6:58 am, “s.ross” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
