woensdag 27 mei 2015

TDD RSpec Shared Examples

When writing shared examples, I often run into situations that the shared examples don't work as expected, since they mostly go untested. As I found no real examples of how to achieve this, I dived into the Rspec code and started my own experiments. So here's whatI came up with: (most of the times you're interested that the tests final when they are supposed to fail, so that's this idea about this test)

RSpec.shared_examples 'an errored resource' do |attributes|
  it 'always fails' do
    fail 'what did you expect?'
  end
end

To test this nice block of code, this is my test:


describe 'an errored resource' do
  let(:example_group) do
    RSpec.describe('group description')
  end

  it "fails the shared example" do
    example_group.include_examples('an errored resource')
    example_group.run
    example = example_group.examples.find { |x| x.description == 'always fails' }
    expect(example.exception.message).to eq('what did you expect?')
  end
end

So the test passes nicely...

maandag 4 oktober 2010

What to place in @Before/ setUp method

Last week, I attended a TDD course by @unclebobmartin, and one of te practices I saw a lot was putting ALL test setup code in the setup method. This resulted in some quote like “all test methods should ideally be two lines long”. This leads to code like this:


@Before public void setUp(){
//setting up common test fixture ...
//manipulating test fixture for test1 running ...
//manipulating test fixture to have test2 running ...
}

@Test public void test1(){
//execute ...
//verify ...
}


Personally, I disagree with this statement as I believe no code should be in the setup method that is not relevant for all off the tests in the test body, so my motto is more like: “all test methods should ideally be three lines long: a setup part, an execution part and a verification part.”  It makes a test understandable by just looking at the test method itself, and that is essential if you want to have code that is easy to maintain. This leads to the following code which is generally a lot cleaner:



@Before public void setUp(){
//setting up common test fixture ...
}

@Test public void test1(){
//manipulating test fixture to have test1 running
//execute ...
//verify ...
}

zaterdag 3 april 2010

droidconbe notes

These are my very personal notes on the Droidcon.be gathering on April 2, 2010. Presentations were very short, and we were too much distracted by the twitter wall that was more prominent than the speakers themselves. It was a lot like the first Flash applications: a lot of animation distracting from what was important and creating irritation. Organizers, please make the twitter wall less dominant next time, and reduce the display time: nobody cares about tweets send 2 days ago when you're at the conference....
I did some cherry picking here, as so many topics make it hard to review them all. (Full schedule on www.droidcon.be)
  • Google keynote: we were a bit late due to public transport issues and could only follow the final 10-15 minutes of the presentation, but the impression was a bit that Google send some representative that didn't have permission to tell something interesting. On topics that she knew were coming, she had no more information than "I don't know that". And she started the first round in the battle about who's responsible for not having paying apps in the Belgian store: "ask the providers".
    But my impression could be wrong as we missed the major part of the presentation, and other participants seemed to be satisfied...
  • Mobile Monday
    "This loose network has been recognized as a catalyst for mobile innovation. Mobile Monday defines itself as the community of professionals of mobility."
    Looks interesting. I already put their session on Augmented Reality on 3rd of May in my agenda...
  • Betagroup.be
    "The BetaGroup is a group of 2.100 Web Entrepreneurs in Belgium passionate about Internet, Software, Mobile Technologies and Online Media.
    We aim to connect Entrepreneurs, Creative Thinkers, Software Developers, Digital Marketers, Web Designers, Web Agencies, Advertisers, Publishers, VC’s and Business Angels to innovate together. We want to provide a platform to meet each other, present our projects and foster new collaborations."
    I think you need to check out these guys if you plan to start your own business, but personally, I'm not that entrepreneurial (yet).
  • OneSocialWeb: provides a framework for integrating social web services into your application using XMPP. (Hey, we were no so mad after all in the good old ReNA days to use XMPP for our prototypes.)
    However, I had a bit the feeling that they were focussing a bit too much on dedicated XMPP servers, and thus not harvesting the existing social networks. But overall feeling for me was: "I wish we had that 3 years ago."
  • Game publishing on Android: a lot of interesting facts and figures about mobile gaming. I hope we have access to the presentations soon.
  • Sportwereld sportsapp - cross platform development presented an application written for iPhone and Android using Appcelerator's Titanium development environment: you write your application in HTML5 + CSS3, have access to native stuff like GPRS, camera, accelerometer, and compile directly to native Android and iPhone applications. I also looked very neat, so I immediately downloaded the stuff! (Meanwhile I found out that it only works from Android 1.6 on, which is a bit a bummer for me, but hey, you can't have it all.)
  • Build apps with Flash for Android: I expected something like the Titanium topic, but hey, Adobe keeps disappointing me last years at conferences. No access to the camera, need Froyo and new Android machines to run Flash in the browser... I think I'll skip Flash for some time...
  • Android App: STIB Very much impressed! (Unfortunately, the bus I needed to go home was not an STIB bus...)
  • Closing keynote: Ramon's vision I liked it a lot: the guy was telling all of developpers the most import lesson: it's only people that matter in the end...

woensdag 13 januari 2010

Android/Samsung horror list

I bought a Samsung Galaxy Spica running Android 1.5 last week, and had my share of problems with it. Not sure the problems are more important than switching to another OS in general, but anyway.

* Missed two times my wake up alarm in the morning. Seems to be a known problem on android. This can have several causes: closing some process on the phone (which I didn't) or something like adapting the volume while you are creating the alarm... Big frustration.
* Prediction library is only in the language of the locale of the phone. Since I want to have Dutch locale, but write a lot of messages in English, this is a big one for me.
Some paying apps seem to fix this problem: TouchPal and BetterKeyboard. Too bad they don't have that by default on the OS.
* Paying apps are only available in some countries, but not in Belgium. To get them anyway, some unofficial page explains that you can get paying apps if put a SIM card from a country that is actually supported. I tried that with an italian vodaphone card, and it actually worked.
* Tethering is not working out of the box, but you can use PdaNet (paying app, but free version has only minor limitations). Usb tethering works fine that way, but for Bluetooth tethering, you need at least Android 2.0, and my phone currently only has 1.5. Still better than iPhone though...
* When listening to music using headphones, incoming calls still go through the external speaker. Quite annoying.
* Too much unwanted notification sounds that are hard/impossible to turn down: plug in charger: BEEP, remove headphone: BEEP, ... The trick is to put the phone to silent mode, and I discovered the alarms still ring if the phone is on silent mode.
* Locking the screen doesn't lock the buttons. So, you can actually put the phone in flight or silent modus, or even totally off while the screen is locked! This caused some missing alarm for me, and missing phone calls. I think I might need some sleeve of some kind to solve this problem...

woensdag 24 juni 2009

Working around a IE6 bug ... only to create new problems

Today, I ran into a bug that was mainly caused by trying to escape other bugs.
The IE6 bug I ran into seems to be an undocumented one, but it is possible that the lack of proper description caused me not to find it on the net. Here it is: when
applying a relative position and a filter image on a table cell (th or td), the onhover functionality of included cells doen't work anymore.
It costed me some time to discover this one, but the main question was: why the hell
would you apply a relative position to a table cell?
Well, that was to escape the problem that on IE6, setting the border-spacing to 0 in CSS is not supported there. Thanks to vacskamati,
a hack was exposed to solved this, exploiting bugs in IE6. But unfortunately, it also sets the position to relative...

maandag 15 juni 2009

Vertical scrollbar problems in IE6

The real story of the scrollbar width problem in IE6 is easier circumvented than I thought.
This is the actual problem: when declaring an inner box inside a scrollarea having a width of 100%,
the inner box takes over the width of the scrollarea, and the scrollarea gets bigger with the width
of the scrollbar. I guess it's the IE6 box problem revisited, although I was taught that it only happened
in quircks mode, so I never actually bothered about it..

220 px ruler
Here, the width is not as expected in IE6
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0  1  2  3  4  5  6  7  8  9  0


This is a solution I found on the net, but it is not satisfying for me: part of the content is also
hidden by the scrollbar, and it also assumes the scrolbar width is exactly 16px.
220 px ruler
Here, part of the content is hidden in IE6.
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5  6 7 8 9 0  1  2  3  4  5  6  7  8  9  0



Of course, we could remediate that by having another box inside like below, but that means
inserting extra HTML code only to fix this item...
220 px ruler
Here, no content is hidden in IE6.
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0  1  2  3  4  5  6  7  8  9  0



But the simplest solution is not use a width of 100%: the content seems to scale automatically
to the right width.
220 px ruler
This is the best solution.
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0  1  2  3  4  5  6  7  8  9  0

donderdag 4 juni 2009

New device, new inspiration

Tuesday, I bought a new device: a Mio Moov 510 GPS device. As usual, it took me quite some time to come to a decision, as I want to spend as less as possible and have as much functionality as possible. The reason I realized I needed a route planner after all is the usual annoyances when I'm driving and my wife needs to read the map. Last year, I borrowed a GPS enabled Mio PDA to drive to my holiday destination, and that was such a good experience that we decided we should never go on holidays without one anymore. And now with hew holidays to be planned, I had to made a decision on what to buy. As my wife needed a new mobile phone, I first tried to see if we could get a device that would do both. Choices seemed quite limited: I found one PDA device from Mio that had both functionalities, but the price including navigation software was about double the price of a standalone gps module, and the damn thing didn't have Wifi. Other choices included an Android phone, but the only turn by turn navigation system there is based on openStreetMap, but I didn't want to take the risk to use that a only database for driving around on my holidays. (Professionally, I would care less ;)). IPhone also fell off as there were only vague plans from TomTom on supporting the device, and the pricing would be too high anyway. So I decided to go for the Mio 510, and buy a low budget Bluetooth receiver so I could play with it from J2ME on my current mobile phone (Nokia 6300).


So I bought the Mio, and started to explore the stuff a bit. It turned out
that the Mio can store logs, which can be interpreted by the open source application GPSBabel, and thus allows me to export my tracks to google earth. As it also exports to gpx, chances are that I can use it to geotag my pictures too, which was the first case I wanted to do on my mobile!


So I am currently investigating how to get the Mio to store enough data for two weeks holidays, as the logs seem to grow very rapidly. I should try to get some statistics some day...


This is what currently is in the gpslog.ini file:

[GPS logging]
enabled = 1
maxfiles = 10
rotate = 1
maxfilesize = 2097152
location = \My Documents\


First thing I am trying now is to change the data location to store the data on the SD disk, as the space on the device is surely too limited to store this amount of data. I tried \Storage Card\, but that didn't seem to work. I found on gpspassion that the name of the folder is apparently in the registry, but I got no idea how to get there. Searches on the net also gave no results. So next thing I will probably try is to unlock the device using the informations on gpspassion.


Another problem I discovered is the short battery life: the device only has a 700mAh battery, which according the the manufacturer gives you 2,5 hours. I also have the feeling that this is rather exaggerated. Probably I should try to hook up extra NiMh batteries, since 4.8 volts is actually enough to drive the USB port. (USB specs claim 4.75 to 5.25 volts) Using2900mAh batteries should get me up and running for 5 times the current duration... Another track to investigate is solar panels, but I think I will be hard to found something that delivers (700 /2.5) 280mA * 5V. Probably, this problem is even more urgent than the previous one, as we were also planning to use the device on bike/walking trips...


Next thing to find out is an application to change the exif data inside my pictures...