SameShirtEveryDay.com

Personal blog of the one called Alex Gorbatchev, from Toronto, Canada.
follow me on Twitter

HAML bug with :javascript filter and undefined local variable or method

Posted on April 19th, 2009 by Alex Gorbatchev. Tagged with , . In Ruby. No comments yet...

http://github.com/nex3/haml/issues#issue/2

on haml 2.0.9

require 'haml/engine'

template_broken = '
:javascript
  - [1, 2, 3, 4].each do |item|
    = "Hey #{item}"
'

puts Haml::Engine.new(template_broken).to_html

causes

(haml):3:in `to_html': undefined local variable or method `item' for #<Object:0x2bedf64> (NameError)
        from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `to_html'
        from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `instance_eval'
        from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `to_html'
        from haml.rb:9

Replacing :javascript filter with regular %script tag fixed the issue. It’s a workaround.

require 'haml/engine'

template_broken = '
%script
  - [1, 2, 3, 4].each do |item|
    = "Hey #{item}"
'

puts Haml::Engine.new(template_broken).to_html

False positives in rcov

Posted on April 18th, 2009 by Alex Gorbatchev. Tagged with , , , . In Ruby. No comments yet...

rcov_false_positives

I noticed that depending on the syntax used, rcov (0.8.1.2.0 win32) can give false positives. For example, when putting blocks on the same line as methods that execute them, if the method was called and block wasn’t, the line would still be colored as “covered”.

In the image above you can see that line #23 isn’t covered, where as #28 is. Problem is, I don’t have any tests yet hitting XML portion.

What’s even more interesting is that using { } syntax on multiple lines gives false positives just the same – you have to use do/end syntax specifically. Only, and only then rcov will process the block correctly.

Something to keep in mind.

Update: I have tested this on OSX and the issue is exactly the same.

Missing ‘a’ character on Windows with rspec and cucumber

Posted on April 18th, 2009 by Alex Gorbatchev. Tagged with , , , . In Rails, Ruby, Testing, Web Development. 10 comments!

cucumber_a_characters_missing

Trying to get a windows rails environment going this morning I stumbled upon something interesting – all ‘a’ characters were missing from cucumber and rspec output.

This has something to do with UTF-8 encoding and there’s a ticket and wiki post on cucumber about it, but no solution that I found acceptable.

Everything comes down to having change encoding in the current cmd window. This is achieved via a simple call to chcp 1252, but nobody want’s to do this every time, right?

To get this executed automaticaly and without resorting to serious registry editing, simply add this line to your cucmber.bat and any other batch files that are exhibiting this problem. You can find cucumber.bat in your /ruby/bin folder.

Here’s what it looks like:

chcp 1252
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "c:/ruby/bin/cucumber" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*

RIO – wrong number of arguments on rmtree, mkpath etc

Posted on December 12th, 2007 by Alex Gorbatchev. In Ruby. 3 comments!

It’s nice to do some Ruby once in a while. Lately I’ve been involved in a Silverlight project and haven’t touched Ruby in 2 months (hence the lack of activity on my Ruby blog). However, I’m making a build script in Ruby.

I have run into a weird exception when using my favorite IO gem RIO (btw, Noobkit page got beaten with the ugly stick and parser needs a spanking).

Exception occur when calling rio(...).rmtree or rio(...).mkpath or rio(...).mkdir. It reads as follows: “wrong number of arguments (0 for 1)”. I know for a fact that these methods don’t take any arguments, but just for kicks, passing a single random argument results in an ironic “wrong number of arguments (1 for 0)”.

Basically the problem came down to the fact that RIO doesn’t like Rake. I can live without Rake, but not without RIO.

Bash script to install Gems

Posted on October 24th, 2007 by Alex Gorbatchev. In Misc, Ruby. No comments yet...

I looked all over and couldn’t find a bash script which could check and if missing install a list of gems. I had to hack my own up:

GEMS=( `cat gems.txt` ) # gems.txt has one gem name per line

for gem in "${GEMS[@]}"; do
  found=`gem list $gem | grep -i $gem`
  if [ "$found" != "" ]; then
    parts=( $found )
    echo "Found ${parts[0]} ${parts[1]}"
    continue
  fi

  echo "---------------------------"
  echo "Installing $gem"
  sudo gem install $gem -y
  echo "---------------------------"
done
home
Subscribe to this blog Follow me on Twitter My bookmarks on Delicious My photography on Flickr