środa, 24 lutego 2016

Take screenshot in IntegrationTest with capybara when it fails

This is about saving screenshot on failing tests in capybara. There are bunch of advices how to do this in rspec but none for ActionDispatch::IntegrationTest. There is also a gem for this capybara-screenshot but I haven't got luck with this at all.

Here is how to do this with rails 4 integration test. Under the hood it uses minitest that have bunch of hooks we can use.


Most of code stolen from http://vumanhcuongit.github.io/testing/2016/01/26/take-screenshot-when-cucumber-test-failed/ and https://github.com/mattheworiordan/capybara-screenshot

wtorek, 27 października 2015

Refactoring - Value Object

Wanted to share neat refactor I've made some time ago

The all this is about keeping the same interface for adding new fields, in fact it is just creating nice Value Object
After quick search on internet it looks it is not good idea to inherit from Hash directly.
Hopefully we can create objects with []= operator so it behaves like Hash.

For generating proper output we need to write format() method that will convert booleans into required format.

Here You can see proper Value Object and it's usage compared to old code.


One bad thing about ruby: looks like you can't just tell in one operation that something is boolean, you need to check if it is TrueClass or FalseClass.

sobota, 19 września 2015

How to test video player in phantomjs

TL;DR;
You can't. Go home and use selenium.



Phantomjs just doesn't support video tag. What you can do is to change your app to emulate video element api, not great but something. The nice thing about this you can speed time ;)


czwartek, 25 września 2014

Track memory leaks in rails application.

So this day has come - your production server gets out of memory and you didn't notice millions of requests. After quick investigation you see that your ruby processes are just too fat(300MB? 500MB? 900MB?). You may wonder that some of the requests causes memory leaks.

If you're using passenger the quick workaround (just to minimize effects for now) could be killing worker after it grows too much: PassengerMaxRequests

Still we don't know what caused that. You might try to search for long requests and assume that they the one but long response doesn't need to mean memory leak.
You can easily count the number of objects created during the request.



If you are using ruby 2.1 you can gather more detailed information: http://stackoverflow.com/questions/20956401/how-do-i-track-down-a-memory-leak-in-my-ruby-code

środa, 27 sierpnia 2014

Playing with ember-leaflet and circle marker

Here are results of playing with ember-leaflet and awesome-markers. This is how you can use ember-leaflet to mark area on a map:


You can also add another layer with custom markers(awesome-markers):



To install this with ember-cli you need to:

wtorek, 19 sierpnia 2014

Ember.js testing focusOut

Quick note how to test focusOut in integration tests in ember.
I was writing signup form using easyForm with client side validations. Note that validations return a promise so we have async call. The feature was about displaying error when I leave field.
First I wrote this and it worked on local machine. But then on CI I started getting errors after running this again it occurs that it fails sometimes.

The solution was to invoke the blur even on element instead of going to another field.  Click helper is a async helper(http://emberjs.com/guides/testing/test-helpers/#toc_asynchronous-helpers) but it's probably waiting only for click event, not the corresponding ones.

środa, 17 lipca 2013

Deploying emberjs app on production

Things you should do when deploying your emberjs app on production.


Catch errors.

window.onerror - most basic but gives you not many message, file, line. In development you might think "yeah I know where is the error!". But in production you will get message, line and column from your one big js file. Moreover here ends errors from user browser extensions. So if you will see "Script error;" or one of my last favorite "The RPC server is unavailable" don't ask yourself wtf, just leave it.

Ember.onerror - better and gives us some kind of stacktrace. But it not covers everything. In ember we have promises and you may write @user.save().then => dummy.trim() That error will go into void and you will not be informed about this error. Sucks.

When you catch error:

  • Notify yourself about them. Write your own controller witch will send some email or use airbrake.io.
  • Track user actions? After bunch of errors without any stacktrace I've decided to track user actions(see on gits)
  • Limit errors. Sometimes your code will stuck in some loop and produce hundreds of errors you don't want them.

Leave some failover.

It is good to leave old version which use the old non spa. You may give the user choice if they want to try new version with better user experience or stay for now with old one. 
Still want somehow support old ie7(6)? Maybe your ember app works with them but it will be damn slow and time you spend for fixing bug for browser used by 1% of your users is not worth. 

Don't rollback everything.

If you want to rollback your spa from production don't touch api endpoints. Someone already uses your ember app and it may work for him. When you remove api endpoints it will definitely broke it.

You deployed fix and nothing changed?

Well probably it was not a good fix :)
But there is also situation when you deploy new assets on production it will not reload existing code in user browser so some errors from old codebase may still appears. Check the current js filename and compare it with error details.

Ember-data error handling? Forget.

Make sure that you handle 500 errors from api. They can happen when you have error in you api code but also when user have very bad connection and your http server just drops request. Normally (in no spa world) user see standard browser site that he should check connection. In ember everything will just stuck, your model object will come into isSaving state or isError and any further changes modifications will be not available. 

What we can do? 
Not much, currently (rc6.2) we don't have good error handling in ember-data. It is possible to detect error(http://discuss.emberjs.com/t/how-to-know-when-a-transaction-has-been-committed/1385/2 )
but after that you can try to rollback your transaction. The last option is just to reload page when you detect error.