Checking for the css class of the found element in capybara

Having an element like

My Text

and trying to check if the class is set to “.some-class”

page.find("#some-id").has_css?(".some-class")

does not work in capybara. This is due to the fact that #has_css? checks for
the css being available inside the element not on the element itself. But is
it still easy to check it by accessing the attributes hash.

page.find("#some-id")[:class].include?("some-class")

Works just fine.

MySQL Gem 2.8.1 on MacOSX Lion

Just because I keep googling it:

To install MySQL 2.8.1 on OS X Lion

1.

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

2.

env ARCHFLAGS="-arch x86_64" sudo gem install mysql -v='2.8.1' -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config

Thanks Stackoverflow

Slimy Vim

Since taking a look at clojure again I was looking
over at Emacs thinking, even though it feels unusable to me it has the nice
feature of evaluating an expression right here and now. Since I’m kind of
invested in both Vim as well as Textmate, with Vim being my current favorite,
I was looking around to get similar. What I came across first was running the
VimClojure Plugin which includes the Nailgunserver, running a single clojure instance evaluating the code you sent to it.
Even though it feels nice to use it mainly works for clojure and is kind of
heavy weight to set up. A simpler solution was described in a post about setting
up clojure on Vim and uses slime to pass
code to a screen window running some interpreter. The nice thing is it works the
same for ruby, python, nodejs, clojure, etc.. My current setup is available found at
Github

Ruby render :action => “new” does not call new method…

… Even though I should know that It drove me crazy the last hour. It’s important to remember when using render in error handling with nested resources. The following actually does not work, since when calling render :action => “new” in the error handling, @b will not be set, an therefore render will fail (probably unless @b is not used at all)

https://gist.github.com/661956.js

It’s important to actually set @b in this case even though it is not actually needed for the create

https://gist.github.com/661962.js

Just nice to know, because it actually feels like calling a controller but it doesn’t.

This variable access in ruby shouldn’t work, or should it?

Ok this is weird, and seems kind of dangerous.

http://gist.github.com/624138.js

In my opinion there should be an error thrown when I access, a local variable and it is undefined, it should not be passed to the instance and the similar named variable from the instance is passed back. Esspecially when using initializations like the following.

http://gist.github.com/624144.js?file=Variable%20initilization

A long discussion showed this is really something to think about wether it’s a bug or a feature…

Howto package a ruby gem

Today, to get used to the Ruby HTTP api I wrote a little gem to talk to the hostip.info service, which handles things like getting current IP, and location services like country and geo location. Since I also need to get used to packaging Software for my Thesis which will be written mostly in Ruby I decided to work my way through setting up a Ruby gem to be installed via the gem tool.

Coming from a background of C/ObjC and Python packaging software and libraries is not new to be and Ruby makes this really easy, too. I decided to do a quick walkthrough since I had to piece everything together from about 20 sources, most of which I will probably never find again anyway. The Process is documented on the Ruby-gems Webpage, but is not completely obvious. Over all its a 3 step Process:

  1. Setup the directory structure for the gem, and copy the code in the correct directories
  2. Setup a Rakefile which also functions as the spec file (Manifest) for the gem to build
  3. Build the gem

Part 1 is really easy, just setup the directories as follows

The lib directory is where all your code is going to live the pkg directory is the place where the gem will be located after the build. Also quite important are the tests which in my opinion should be included in every gem since they provide a nice way to check the gem against your current ruby install, and will also detect missing dependencies and so on. 2 more files are needed to complete the gem, the Rakefile and the README. I choose rdoc as the format for the README since it can be used by Ruby directly for documentation, and will also be parsed and displayed by SCMs like Github.

The last part to complete the whole setup is the Rakefile, it includes all the specifications, like author, webpage, version, included files, tests and so on. The Rakefile will later be used to build the gem. Since I build a real simple one, it might be a good idea to just look at my source to figure out the basic format.

Lastly the gem can be build by issuing rake in the gem directory which will put the finished gem in pkg to be installed via gem install, afterwards it can be tested via gem check -t GEMNAME.

Thats pretty much it! Of course I build a really simple gem to get started, gems can also include things like native code, which would be located in ext, also the build instructions can be as complex as needed because rake is as powerful or maybe even more powerful then unix make. All in all to Ruby gems to me seem like a really nice and easy way to package and publish code comparable to CPAN for perl or easy_install eggs for Python.

Check out the code at Bitbucket and feel free to contact me about things I’m doing wrong or right.

Hostip ruby gem update

Since I’ve been trying out the ruby way to package Software I was also interested in how easy it is to include a command line accessible bin file with the gem, and since the hostip ruby gem actually works really well I decided to include a script to access the functions from the command line. All that is to do to make that work is adding a bin directory to your gem and adding

bindir = ‘bin’

executables = [‘BINNAME’]

to your Gem specification.

If you update the gem to Version 0.2.0 it will also install a tool called hostip in your system path, which is /usr/bin on MacOSX by default for ruby gems, to get your current Internet routable IP as well as the city, country, and geo-location for that or any specified IP.

I actually use it quite often now to check if my proxy works etc. which is way faster from the command line than doing it by visiting a website like hostip or those millions other that offer that service.

Again for more info how it is made to work visit the gem on BitBucket.

Updated Dropbox Dropzone to handle folders as well

I just pushed the code to handle folders in my Dropbox Dropzone to GitHub. If a folder is dragged on the Dropzone it is now archived and uploaded to Dropbox as an archive to be shared.

Enjoy :)

PS: Love those guys at Aptonic my changes got pulled minutes after I sent the request.

Edit: Updated again to also handle multiple files dragged on, they are also zipped now instead of producing an error. Waiting for  Aptonic to pull, but I guess it will be up shortly