How to fix the Apple Mail search problem in MacOS X 10.7 Lion
After my update from MacOS X 10.6 Snow Leopard to 10.7 Lion the search function in Apple Mail stopped working.
There were no or too little search results, when I typed something in the search field.
It looked like my mailboxes couldn't be indexed by spotlight anymore.
And here is the simple solution:
- Mark your mailbox in the list of mailboxes on the left in your apple mail window by clicking on its name once.
- From the menu select "Mailbox" => "Rebuild".
- After the rebuild you should get the right search results again.
- Proceed wi...
Re-enable submit buttons disabled by the :disable_with option
Submit buttons in Rails come with a useful option :disable_with
which will disable the button when clicked and change its label to something like "Please wait...".
An annoying side effect of that feature is that when you use the back button to return to the form, the submit button will be greyed out and disabled.
A solution is to re-enable the submit button before leaving the page. This works in Rails 3:
$(window).unload(function() {
$.rails.enableFormElements($($.rails.formSubmitSelector));
});
davetron5000/methadone - GitHub
Framework to write command-line apps in Ruby. Comes with a nice way of processing parameter options, some utility classes and Cucumber steps for testing your CLI app.
How to fix "unknown role" errors in Capistrano recipes
When you have a complex recipe setup with multistage deployment you may run into this error:
`role_list_from': unknown role `something' (ArgumentError)
Consider this task definition:
namespace :foo do
task :bar, :roles => :something do
# do crazy stuff
end
end
Whenever we call foo.bar
in our recipe, Capistrano will fail if you deploy to a stage where none of the servers has the role the error complains about, "something
" in this case.
However, you can [hack around it](http://groups.google.com/group/ca...
Scenario outlines in Cucumber
Scenario outlines allow us to more concisely express repetitive examples through the use of a template with placeholders.
Bulk-change multiple table rows in a migration
Using rename_column
, remove_column
, etc. more than once in a migration makes that migration run slower than it should. Use change_table
instead.
Consider this migration:
add_column :users, :name, :string
remove_column :users, :first_name
remove_column :users, :last_name
rename_column :users, :cool, :awesome
Migrating in this case means that all those commands are processed step by step, causing 4 SQL statements to change the table. In turn, your database needs to modify the table structure 4 times. When working on hu...
Ubuntu 11.10: Playing sound over front and back panel (or headphones and speakers) at once
I have a pair of headphones connected to my desktop's back panel and a headset connected to the front panel. I used to play sound over both outputs, but this suddenly stopped working this week.
Apparently, (perhaps through some update) "jack sensing" got turned on, which disables the back panel as soon as you connect something to your front panel audio jack.
To disable this feature, I used alsamixer
(use the arrow keys to navigate right to "auto mute", and disable with the up key). For some reason the corresponding checkbox in the `gnome...
Error "execution expired (Timeout::Error)" when using Selenium and Webmock
If you get the above error when running tests in bulk (but not individually), it's actually the fault of Webmock.
Updating Webmock to version 1.7+ fixes this.
Be careful with "memoize"
ActiveSupport
's memoize
has a dangerous feature you might not know about.
Assume you have
class DeepThought
extend ActiveSupport::Memoizable
def life_universe_and_everything
# some lengthy calculation returning 42
end
memoize :life_universe_and_everything
end
Then #life_universe_and_everything
will of course cache the result after calculating it once. However, you can trigger a recalculation by calling #life_universe_and_everything(true)
.
If, however, your method looks like
de...
"Show me the page" fails to open a browser window
If you get an error like this:
Unable to launch /home/bruce/Projects/myproject/tmp/capybara/capybara-201110311210111407691101.html
... update your launchy
gem. It failed for us in version 0.4.x. We could fix the issue by upgrading to 2.0.5.
Cucumber.yml was found, but could not be parsed.
If you encounter the error message above when running cucumber, just execute...
rm rerun.txt
...in the Rails directory.
Or run...
tests
...from the geordi gem. This will do the work for you automatically.
Stub methods on any instance of a class in Rspec 1 and Rspec 2
RSpec 1 (Rails 2)
With the most recent spec_candy.rb
helpers you can say:
User.stub_any_instance(:foo => :bar)
user = User.new
user.foo
# => :bar
RSpec 2 (Rails 3)
RSpec 2 comes with this feature built in:
User.any_instance.stub(:foo => :bar)
user = User.new
user.foo
# => :bar
RSpec 3
-------...
Stub a request's IP address in a Cucumber scenario
The solution in this card is based on a stack overflow post by Leventix.
If you need to make request come from a fixed IP address for the duration of a Cucumber scenario, the code below lets you write this:
Given my IP address is 188.174.117.205
Rails 3
Given /^my IP address is "(.*?)"$/ do |ip|
ActionDispatch::Request.any_instance.stub(:remote_ip).and_return(ip)
end
Rails 2
-----...
Ruby 2.0 Implementation Work Begins: What is Ruby 2.0 and What’s New?
While 2.0 will include a number of syntax changes, new features and general improvements, mentioned below, it is anticipated to remain backward compatible with code written for 1.9.3 and Matz has stated that the changes are less significant than those made in the 1.8 to 1.9 jump.
Rails logs are not flushed automatically (in Rake tasks)
The Rails logger will store its content in a buffer and write it into the file system every 1000 lines. This will come back to bite you when using Rails.logger.info
to write log output during Rake tasks or on a production console.
You often won't notice this because for the development
and test
environments auto_flushing
is set to write after each line. On production environments the Rails logger writes only every 1000 lines -- and not upon shell or script ter...
Why your Cucumber feature loses cookies when run under Selenium
When your Cucumber feature seems to forget cookies / sessions when you run it with Selenium check if the test travels in time like here:
Given the date is 2017-10-20
When I sign in
Then I should see "Welcome!"
What happens here is that the Rails application serving pages runs in 2017, but the process running your browser still lives today. This huge gap in time will expire most cookies immediately.
If all you need is to freeze the time to a date, a workaround is to travel to the future instead.
Capybara can match elements outside of <body>
Capybara will match elements outside of a page's <body>
tag.
For example, the step definitions below match <link>
nodes in a page's <head>
:
Then /^my browser should auto-discover the "([^"]*)" feed$/ do |slug|
page.should have_css(
'head link' +
'[rel="alternate"]' +
"[href='http://www.example.com/#{slug}/feed.rss']" +
'[title="RSS feed (all cards)"]' +
'[type="application/rss+xml"]',
visible: false
)
end
Then /^my browser should not auto-discover any RSS fe...
Mailcatcher: An alternative to inaction_mailer
Looks simpler than inaction_mailer:
gem install mailcatcher
mailcatcher
Setup Rails to send mails to 127.0.0.1:1025. Usually you want the following config in config/environments/development.rb
and maybe in test.rb
or cucumber.rb
.
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'localhost',
:port => 1025
}
Now you can see sent mails in your browser when opening http://127.0.0.1:1080
Note: In order to s...
Single step and slow motion for cucumber scenarios using @javascript selenium
Single step and slow motion for Cucumber scenarios can come in handy, especially in @javascript
scenarios.
# features/support/examiners.rb
AfterStep('@slow_motion') do
sleep 2
end
AfterStep('@single_step') do
print "Single Stepping. Hit enter to continue"
STDIN.getc
end
If you're using spreewald, these tags are available as @slow-motion
and @single-step
(with dashes instead of underscores).
Note: You can also [prevent the selenium webbrowser wind...
Test that a form field has an error with Cucumber and Capybara
You can use the step definition below to say this:
Then the "Last name" field should have an error
Capybara
Then /^the "([^\"]*)" field should( not)? have an error$/ do |field, negate|
expectation = negate ? :should_not : :should
page.send(expectation, have_css('.field_with_errors', :text => field))
end
Prevent the selenium webbrowser window from closing after a failed @javascript step
When cucumber encounters a failing step in a @javascript feature, the selenium browser window instantly closes. Sometimes you do not want that, because you need to see what is going on. You can click through the data your feature created, when you add the following file to your features/support directory:
#features/support/examiners.rb
After('@leave_the_window_open') do |scenario|
if scenario.respond_to?(:status) && scenario.status == :failed
print "Step Failed. Press return to close browser"
STDIN.getc
...
How Non-negotiable Features Kill Software Products
features are pre-sold without any option to negotiate what’s important and what may be left out, you inevitably end up with too much complexity. Such pre-sold features not only tie your hands, but the client is also not able to change what he needs over time.
Selenium WebDriver 2.5.0, 2.6.0 fails when selecting options from select boxes
We are consistently having trouble with selenium-webdriver > 2.5.0
where whenever we try to select an option from a <select>
Capybara complains:
No such option 'Foo' in this select box. Available options: 'Foo', 'Bar', 'Baz' (Capybara::OptionNotFound)
This seems to happen with both old and new versions of Firefox. Our workaround so far is to freeze the gem at version 0.2.2
.
How to install a frozen version of Firefox for your Selenium tests
Whenever Firefox updates, all your Cucumber features that use Selenium break. This is annoying.
In order to remedy this, version 0.5.0 of our geordi gem comes with a script that helps you create an unchanging version of Firefox for your Selenium tests. In particular, this new copy of Firefox will have the following properties:
- It won't update itself with a newer version
- It can co-exist with your regular Firefox installation (which you can update at will)
- It will use a profile separate from the one...