The difference between a spec and a test (Behaviour Driven Development)

What is a spec

There was a time where I saw some tests which my colleagues made where the file name in the test folder would be: “users.spec.coffee”. So “spec” is short of specification and it is a totally different way of how we think  about tests.

Continue reading “The difference between a spec and a test (Behaviour Driven Development)”

Card.io issue not supporting Samsung S5 and other devices

card.io 5.4.2

Card.io is a card recognition SDK used by PayPal which allows you to easily scan your own credit/debit cards and get information about them in the code.

Problem

Using card.io from the source and not from Maven requires you to have the latest Android NDK with which the project will be built. But compiling it with the latest NDK introduces a bug which prevents the library from supporting several phones like Samsung S5, Honor 7 and others.

Continue reading “Card.io issue not supporting Samsung S5 and other devices”

Mockito anyString() vs any() – null handling

Sometimes, when I mock a method in Mockito, I used anyString instead of any and I get into a mess and my test fails. Why?

given(mUserRepo.getUser(anyString(). any())).willReturn(new User());

And what will happen if

mUserRepo.getUser(null);

UserRepo is called with null? Well, the matcher doesn’t work and the test fails. anyString() does not work with null values. If you pass null to a mocked service then use any() as a matcher.

Context in Android Databinding XML files

It is so easy guys, just don’t forget that DataBinding creates a field called context which you can access by default in your XML file. So you can write something like this:

<data>
   <variable name="name" type="String"/>
</data>
<layout>
  <TextView
      app:text="@{StringUtils.format(context, name)}" />
</layout>

And it will be just fine. You have the context from the parent view. Check it HERE.

Feature toggles in NodeJS

I had to implement a feature toggle recently.

What is a feature toggle?

I will keep it short. You have to add a new feature to your product, but you want that feature to be available only for certain type of users. What you do? Well, you just make an if check to see the user can see this feature and then you toggle it for him. Here is a sample check:

if(ToggleRouter.isEnabled("comments")) {
  // Display the feature to the user
}
Continue reading “Feature toggles in NodeJS”

Design Patterns – Books, tutorials & notes

Why design patterns?

Well, this question is very simple. Because they will broaden your knowledge and make you enjoy programming again. They will remind it you that programming is a skillful art which requires constant research for a purpose. All of the patterns are extremely practical and easily applied to real world examples.

Continue reading “Design Patterns – Books, tutorials & notes”

Simple role management for SailsJS

You have probably heard this form me. I am working on a Sails js project and I wanted to implement a simple role management. That means that I have several routes like: “/admin”, “/login”, “/users” and I want the admin route  to be accessed only from admins, login to be accessed from admin and users and the users route to be accessed from only the users.

Continue reading “Simple role management for SailsJS”