Rails 3.1 — SQL logging to STDOUT during testing (with rspec, test::unit, or cucumber)

Seemingly random SQL logging?
A simple fix, you probably have config.logger = Logger.new(STDOUT) in your test.rb or application.rb!

A simple fix, you probably have config.logger = Logger.new(STDOUT) in your test.rb or application.rb!
Need to use some information from your application in your new Coffeescript file? All you have to do is rename it with .erb.coffee or .
$ ->
$('#currency_select').change ->
window.location = window.location.pathname.replace(/^\/(<%=Country.currencies.keys.join '|'%>)|(?!(<%=Country.currencies.keys.join '|'%>))\//i, '/'+$(this + "option:selected").text())
The best part about it is that Rails still knows when to generate the file, it doesn't do it each time! The only thing you can't directly access are the routes (e.g. root_path(), etc), but a gem called js:routes can take care of that for you.
This is a simple one to fix. I had two Classes of the same name but with different scopes, one was a model and the other a class in a separate module under lib. You have three options in this scenario:
Choose more appropriate names
Move the module out of lib into a gem
Rename the filename of the Class under the lib/ folder, while retaining the same class name.
Selenium wasn't playing very nice with lightboxes during one of my tests, it just said it wasn't visible! Thanks! That helps all you have to do is wait silly:
When I wait until I can see "new_category"
And the step definition:
When /^I wait until I can see "([^"]*)"$/ do |selector|
page.has_css?("#{selector}", :visible => true)
end
Checking for a selected option within Cucumber/Capaybara is quite simple:
Then "hello" should be selected for "article_category_id"
And the step definition:
Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |value, field|
assert page.has_xpath?("//option[@selected = 'selected' and contains(string(), '#{value}')]")
end
You could easily extrapolate this for use within an unselected value, just by removing the selected bit:
Then /^"([^"]*)" should be seen within "([^"]*)"$/ do |value, field|
assert page.has_xpath?("//option[contains(string(), '#{value}')]")
end