Jul 07 Rake task using methods in modules

tags: rake modules | comments

I normally don’t feel too confortable with the looks and manners of Rake tasks. The code looks a bit anti-DSL, and normally is not clear where to put helper methods, and also how to make them available or not to given tasks. So take a look at what I tried the other day: including modules in tasks and make them dependencies of other tasks:

read more »

Jun 22 stubbing captchas in cucumber

tags: captcha stub cucumber | comments

You use some captcha solution to avoid bots in your site, and you are a good kid and like everything well test-covered. Well, don’t sweat too much with weird solutions to validate your captcha, it’s an external thing you know, it’s pretty ok to stub it.

read more »

Jun 08 have_regexp custom matcher to check page content

tags: rspec matcher | comments

When writing expectations on pages I like to keep them loose so they break less. I normally use the have_text matcher and I can even get looser using regexps matching but even that can break due to line breaks introduced by rendering. This is what it should be in a perfect world:

read more »

May 12 Ruby Nation: Lots of RSpec syntax

tags: rspec syntax ruby nation | comments

For a week or two I was happily pleased with Jon Lark Larkowski RSpec presentation at Ruby Nation on RSpec syntax, and was eager to use that and other recommendations to improve my specs. Well it was time to test a helper in one of my Rails apps. Check it out, it is sweet.

read more »

Apr 29 hunting bugs with git bisect and submodules

tags: git bisect submodules | comments

You love git bisect to traverse your history running scripts and find where your code got broken, right? But then you find bisect is not aware of submodules don’t sweat it’s git in the end, you have the power.

read more »

Apr 13 Webkit browsers and ajax redirections

tags: webkit ajax chrome | comments

In one of my last tasks I have this page where an automatic download starts. I set jquery to wait for the page to load and then start an ajax request for the download. Everything was ok, except Chrome did not show any image from the CSS. The solution in the end was to use the old iframe tag and no fancy js.

read more »

Feb 12 paperclip attachments testing for the whole battery: RSpec and Cucumber

tags: paperclip rspec cucumber | comments

Paperclip is my favourite choice for attachments, and today I needed to spec and cuke my attachments. Even though there are ways to speed your attachments tests I prefer simple, and usable all over. The trick is to create a test attachment and attach it to your models. read more »

Feb 04 authlogic avoiding ending up with multiple sessions

tags: authlogic session rspec cucumber | comments

Authlogic is cool to handle your authentication. But in my new app the admin user was the one who created new users and updated them also. There I stumbled with a funny gotcha. Admin logged out and there was the user session of the users just created/updated. The thing is authlogic when you save a model that acts a authenticated you got a user session created. The trick is to tell authlogic to save but not creating a session. read more »

Jan 21 RSpec simple matcher to specify an array should be sorted

tags: rspec matcher array sort | comments

RSpec is a lot about readability. And its matchers are really a joy to aid you on that. And now it is even easier to add simple matchers for (in David’s own words) you to create your own custom matchers in just a few lines of code when you don’t need all the power of a completely custom matcher object.

read more »

Jan 12 Machinist and polymorphic associations

tags: machinist polymorphic | comments

You love machinist for fixtures creation, but then you need to blueprint a model that has a polymorphic association and that means two fields in your blueprint. Don’t worry, it’s dead easy using a helper class.

read more »