Tag Archives: Ruby

Controlling a jQuery datepicker with Watir

In my last post I talked about some issues using a dropdown with Watir, the context I was using that in was to complete a jQuery datepicker field that contained both a year and month dropdown.

In case anyone needs the code to be able to do this with Watir Webdriver here it is;

@title = div(:class, 'ui-datepicker-title')
text_field(:class, 'datepicker').click
@title.select(:class, 'ui-datepicker-year').select_value('2006')
@title.select(:class, 'ui-datepicker-month').select('Jan')
table(:class, 'ui-datepicker-calendar').a(:class, 'ui-state-default').click

@title is just a container for the div that contains it.

The two lines with .select will change the value of the year and month dropdowns, there is an change event associated with these inside of jQuery so it will update the calendar automatically for you.

The final line is a bit of a hack because each day doesn’t have a unique id or class, in my test I didn’t really care about the day so I just picked the first standard weekday but you could use :index, 5 or something with the a function and play about to pick the appropriate day.

Share this on

Write simple rspec tests on one line for fun and profit

If you have a test set up that performs one assertion then you can condense your test into one line, this makes things way more readable and shortens your tests.

For example:

it "should return a response header with JSON in it" do
  response.header['Content-Type'].should include 'json'
end 

Can become:

it { response.header['Content-Type'].should include 'json' }

When you have lots of small tests like this it really helps to make your tests easier to read, which will in turn help you in keeping them up to date and sharing them with other people.

Share this on

Adding Data Attributes using haml_tag

Normally when using haml_tag you can add attributes by typing something like; haml_tag :a, class: 'my-class'

Unfortunately because of the hyphen in data attributes the same pattern doesn’t work if you try and add them, so haml_tag :a, data-id: '5' will crap itself.

What you can do though is call something like; haml_tag :a, data: {id: '5'} which will output the following HTML; <a data-id='5'></a>

You can also add multiple data attributes like so; haml_tag :a, data: {id: '5', type: 'arbitrary code'} which is pretty handy.

Share this on

Getting the rmagick 2.12.2 gem working on Mac OS X

So getting rmagick 2.12.2 working on Mac OS X isn’t the easiest thing in the world, but it is possible.

The first thing I should say is that this assumes you already have ImageMagick installed on your machine, the second thing is that there is a rmagick 2.13.2 gem, which seems to work out of the box.

In my case I couldn’t use 2.13.2 so I had to get things working with 2.12.2.

If you Google this issue there are loads of solutions out there, unfortunately all the low hanging fruit didn’t work for me, these are things like;

  • Making sure ImageMagick is installed
  • Telling the ruby gem where ImageMagick lives with -- --with-opt-dir

Thanks to this link I was able to get it sorted.

Here is a dump of the fix that you type into the terminal;

cd /usr/local/Cellar/imagemagick/6.8.0-10/lib
ln -s libMagick++-Q16.7.dylib   libMagick++.dylib
ln -s libMagickCore-Q16.7.dylib libMagickCore.dylib
ln -s libMagickWand-Q16.7.dylib libMagickWand.dylib
Share this on

Ruby Podcasts I have been recommended

This is just a dump of ruby related podcasts that were recommended to me on Twitter by some lovely folk, keeping them here so I don’t forget to check them out.

Thanks to Pete Hawkins, Arlen Walker and Johnathan Barrett for the recommendations.

Share this on