Nerdblog.pl

Testing your generators with rspec and ammeter

Generators in Rails are awesome and fun and probably one of the reasons Rails became so successful. If you ever wrote one for any reason, you probably know that Rails has Rails::Generators::TestCase class, useful for checking if the script you've written has created all files correctly. But what if you're like us and prefer using rspec rather than Rails'es bundled testing tools?

Read more

Rails Magic #2

Let's assume you have a model with a range type (Rails supports these for PostgreSQL since 4.0).

> foo = Foo.new
> foo.some_range = 1..5
> foo.save!
> foo.some_range
 => 1..5
> foo.reload
> foo.some_range
 => 1...6

Wait.. what? It silently converted inclusive range into exclusive one?

And before somebody says "ooh, but it's the same range anyway, right?", here's the reason I even noticed the problem:

> (1..5).last
 => 5
> (1...6).last
 => 6

WELL, looks like we have a problem. It wouldn't be so bad if there was any sane way of converting exclusive ranges to inclusive ones in Ruby other than (begin..(end-1)).

Still, as @katafrakt_pl noticed:

> (1..5).last(1).first
 => 5
> (1...6).last(1).first
 => 5

...maybe I'll just wrap that in custom class, like Rails people are planning to do.

Testing is not a guaranteed recipe for high quality software

One final word for this short intro: testing is not, and will never be, a guaranteed recipe for high quality software. The value you get out of it is proportional to your ability to architect software correctly. A tested, yet poorly architected app is further evidenced by its tests passing, leaving you under the illusion it's good quality software when it's not.

@julio_ody

Gdzie są moje kosmiczne zabawki?!

Od kilku lat jaram się nowoczesnymi technologiami i śledzę na bieżąco wszystkie fajniejsze zabawki pojawiające się na kickstarterach lub w mediach. Część z tych zabawek przemówiła do mnie na tyle, że byłem gotowy rzucać w ludzi pieniędzmi tylko po to, żeby dostać je jak najwcześniej, nawet w koślawej, niekompletnej wersji. Niestety, wygląda na to, że praktycznie każda zabawka, którą albo preorderowałem, albo przynajmniej wytrwale śledziłem oczekując na wersję końcową okazała się albo bezużyteczna, albo przereklamowana, albo nadal nie została wydana. Ten wpis będzie marudzeniem na kilka z nich, zostaliście ostrzeżeni.

Read more

Bootstrap-sass mixins cheat sheet

I've been working with Twitter Bootstrap a lot lately and the absence of any mixins list was driving me crazy.

Until now. I've created a simple app that parses SCSS files of bootstrap-sass gem and creates a neat list (with additional links to GitHub so you can quickly see the code snippet and make sure you're using the right one).

You can see it here, on my new playground server I'll be using for projects like this one.

If you have anything you wish to add or modify, feel free to send me a pull request!