Posts for: #Tdd

Hanoi: Automated jQuery tests with QUnit

About a month ago, we have released adva-cms 0.2.0, the most relevant change was the migration from Prototype to jQuery. I always been a loyal Prototype fan, and, until then, I always tested my code with `unittest.js`, combined with `jstest.rb`.

Like other rewrite we needed to rely on a solid test layer, but what I noticed was the lack of a valid automation support for QUnit, the test framework used internally by the jQuery team. So, in a couple of days I built what we need, just creating a custom version of jstest.rb and changing a little bit QUnit, in order to communicate with it.

[]

Skip Mocha

Yesterday I confessed how messed up was CachedModels 0.0.2. The problem was pretty simple: I made some mistakes mocking up Memcached behaviors.

The Dilemma

I massively use Mocha for track how many calls CachedModels performs against the cache, and (ideally) for run test suite without any server active. But, this approach led me to broken results. Should I keep out Mocha from my tests?

The Solution

Why don’t mock the mock? We know, Ruby allows to add behaviors to classes at runtime, Mocha itself take this advantage. I added to my test_helper.rb the following code:
if ENV['SKIP_MOCHA'] == 'true' class Object def expects(*args) self end

def method_missing(method_name, *args, &block)
end

end

[]

Ruby on Rails: Test Model Domain Changes

You know how tests are fundamental for a well-developed project, for this reason we should create step-by-step a net of test cases. Of course we also should be able to change rapidly our tests as the same we do with our code. Ruby on Rails is a great framework, because its shortcuts, the wide usage of DSL etc.. All this stuff can save a lot of time, but what about tests? Are we really able to follow our code?

[]