Retrospekcja, cz. 1

Dziś mija dokładnie rok od mojego wyjazdu dookoła świata. Ciężko uwierzyć, ale niewiele ponad rok wcześniej poznałem Wojtka, z którym ta wyprawa miała się odbyć. Trzy miesiące później okazało się, że obaj zawsze chcieliśmy zwiedzić Nową Zelandię, zatem dość naturalnie padło pytanie typu: A dlaczego by nie oblecieć przy okazji świata w koło? Po 10 miesiącach wytężonej pracy (trzeba było w końcu na ten wyjazd zarobić), byłem gotów opuścić Kraków i udać się na przygodę życia.

Sporo osób widziało już zdjęcia, które udało mi się zrobić, ale niewiele z nich poznało szerszy kontekst, a mnóstwo rzeczy zachowałem do tej pory tylko dla siebie. Dlatego właśnie marzyło mi się by dokonać retrospekcji; seria wpisów, które stworzę nie ma na celu opisywanie wszystkiego co robiłem dzień po dniu, lecz przypomnieniem sobie wrażeń i myśli – pamiątką dla mnie.

Read more…

Toggling Python’s unit test mock patchers

I have recently found out about handy start and stop patch methods in Python’s mock library (or unittest.mock since Python 3.3). I started using it immediately and one of the first improvements I could think of was the ability to toggle the patcher off/on for a single test case using a decorator.

If you are not familiar with start and stop methods you can start out reading mock documentation (or for 3.3+). If you can’t think of a use case, it’s probably not for you. :) Otherwise, you can find both the code and the example usage below.

Read more…

Highlighting current active page in Django

Every once in a while, you would like to highlight a current, active page in the navigation. There are number of solutions available to this problem, but none of them was flexible enough for me to use in my projects.

The CurrentPageMiddleware is very useful and saves a lot of time, but its main problem is that it only adds CSS classes to anchor elements, but what if you wanted to add CSS class to its parent element?

Read more…

Testing if a post is in a descendant category in WordPress

You can find a solution to this problem in WordPress Codex. The only issue being that it only allows you to pass a single post ID or an array of post IDs, not allowing you to use your category slug, not to mention multiple slugs.

The documentation of this function tells you to see get_term_by() if you want to use category name or slug, but why not extend this function to do this for you?

Read more…

Screencast: SilverStripe Behaviour Testing Framework – GSoC 2012

Read more…

Introducing SilverStripeExtension for Behat

During the second phase of GSoC an idea came into my mind. Why not allow other developers test their SilverStripe modules behaviourally?

There was already an extension created for basic interactions with the temporary database, but it was not in the state where you would be able to use it outside of the Sapphire framework.

But that’s the thing of the past. Now, let me introduce you to the new, shiny SilverStripeExtension.

Read more…

AJAX callback support for Behat with Mink (and jQuery)

SilverStripe relies heavily on AJAX interactions with feedback times varying from 200ms to multiple seconds. In order to make testing both stable and fast we needed a more sophisticated system than fixed timeouts.

This has already been implemented for the old spec-by-example module.

Read more…

Using subcontexts with Behat and Mink

Using subcontexts with Behat and Mink is easy. You only need to remember to only extend MinkContext (or use Mink as subcontext) once, because it has some basic step definitions already defined and Behat doesn’t allow redundant step definitions.

Read more…

Variable media queries in Less CSS

Version 1.3.0 of lesscss introduced nice features that were available in Sass earlier, but were missing in less – you can now nest media queries and they are bubbling.

What does that mean to us? Thanks to them, you can add media-specific styles without having to worry that all these media queries we put at the end of our stylesheets break the flow or use repeated selectors.

Read more…

Conditional intercepting of redirections with Behat and Mink

In behat documentation, the topic of intercepting redirections is discussed in the context of using the profiler to test some of the features that hit specific browsers.

The solution proposed there has a specific drawback: it only works when you are trying to test using either goutte or symfony driver.

However, if some of the features you want to test using different driver too – like selenium2, that supports redirections, but does not allow to intercept them – you have to try different approach.

Read more…