Monthly Archives: January 2015

Viewing Cucumber Logs

I have spent so many workarounds trying to make up for the fact I couldn’t see proper logs while running cucumber tests. Five million ‘save_and_open_page’s, trying to ‘puts’ ridiculous things, switching between branches to try and pinpoint when things broke, switching databases and comparing performance to development.

Then I got a bit more sophisticated and started to try and use –backtrace (only good if a Cucumber error, no good for errors in your app). Even looking in the test.log file wasn’t always useful.

But for some reason, the following logs are better/more detailed than what is just in test.log. I’m not sure why…The magic line, that I never want to forget:

tail -f log/test.log

(or cucumber.log, if your log file is called that and not test.log)
Leave a reply

Custom Mime Types for Beginners

Did you know that you can add Mime types (data types) to your Rails app to allow you to use the same URL for different response types?

For example, you might want to use your show method, e.g. /books/2,  with different responses depending on what MIME type you suggest.
e.g.
html response – showing information about your book in html
json response – information about the book in json
pdf response – a pdf download about book 2
circus response – a specially formatted version of the books/2 data

The last one, ‘circus’, is obviously made up, but you CAN create new Mime types, called whatever you like. So you might want to make the data-type called ‘circus’ available and have a special format return on that URL when the data type is Circus.

All you need to do is

1.  Add the Mime type if it isn’t already there
In config/initializers/mime_types.rb add
Mime::Type.register "text/circus", :circus
(Since it is in an initializer, you will need to restart your server to pick up this change)

2. Make the response available in your controller action
def show
respond_to do |format|
format.html # render html
format.circus { #render circus }
end
end

3. Add the view you want
In your views folder,  you would put the circus template into a show.circus.erb file

4. Then in your request, set your data-type as ‘circus’ (E.g. in your form or Ajax request).

 

Leave a reply