how to test Ruby On Rails RESTful

I had a bit of a mystery while trying to test out how RESTful routing of Ruby on Rails worked.

My controller looked like:

respond_to do |format| format.html # show.rhtml format.yml { text = '' text = boottime.logical_host.macaddress + ":\r\n" text += " geometryX: " + lastcc.geometryX.to_s + "\r\n" text += " geometryY: " + lastcc.geometryY.to_s + "\r\n" render :context_type => "text/yaml", :text => text } end

and my test case looked like:

get :show, :id => mac

When I first tried doing:

get :show, :id => mac+'.yml'

it failed to work. That’s now how to do it. I went through many attempts, and finally realized that the extension should be “yaml” not, “yml” (and in the respond_to) as well.

get :show, :id => mac, :format => 'yaml' assert @response.body.include?("geometryX") assert @response.body.include?("geometryY")

works. Silly me.