RubyMine: Using pinned tabs will increase your productivity
I highly recommend that you make use of RubyMine's feature to pin tabs.
When you pin all "important" files, you can follow method definitions, wildly open files from search results and have a ton of open tabs -- without the problem of finding the stuff you were working on before.
Guide
- Pin the tabs of files that are currently in the focus of your work (important models, specs, etc):
- Right-click a tab and select "Pin tab"
- Or use a shortcut (see below)
- Work as usual.
- Once you opened other tabs because you searched ...
Click on a piece of text in Cucumber / Capyabra
The step definition below lets you write:
When I click on "Foo"
This is useful in Selenium features where the element you click on is not necessarily a link or button, but could be any HTML element with a Javascript event binding.
The easiest way to get this step is to use Spreewald. If you would like to add it manually, here is the step definition:
When /^I click on "([^\"]+)"$/ do |text|
matcher = ['*', { :text => text }]
element = page.find(:css, *matcher)
while be...
Speed up large Cucumber test suites
Test suites usually grow over time as more and more development time is spent on a projects. Overall run-time and performance of Cucumber suites in turn increases, too.
You can use the very same way Henning suggested for speeding up RSpec some time ago.
Put the following into features/support/deferred_garbage_collection.rb
Before do
DeferredGarbageCollection.start
end
After do
DeferredGarbageCollection.reconsider
end
We...
New cards feature: Personal RSS feed that includes public and private cards
Your account profile now links to a personal RSS feed. This RSS feed contains the newest public and private cards for all your decks.
New cards feature: Explicit language declaration for syntax highlighting
Makandra cards will auto-detect the language used for syntax highlighting.
This auto-detection sometimes fails for short code snippets. In such cases you can explicitly declare the language for Github-style code blocks:
```css
body {
font-size: 12px
}
```
Will turn into this:
body {
font-size: 12px
}
To disable syntax highlighting entirely use the text language:
```text
I am nothing without pretend
...
Bundler: Fatal error and 'no such file to load -- net/https'
Today, I ran into trouble on a fairly fresh installed VM, running Ubuntu. I tried to bundle install and got this stacktrace:
Fetching gem metadata from https://rubygems.org/.Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- net/https (LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/li...
When overriding #method_missing, remember to override #respond_to_missing? as well
When you use method_missing to have an object return something on a method call, always make sure you also redefine respond_to_missing?.
If you don't do it, nothing will break at a first glance, but you will run into trouble eventually.
Consider this class:
class Dog
def method_missing(method_name, *args, &block)
if method_name == :bark
'woof!'
else
super
end
end
end
This will allow you to say:
Dog.new.bark
=> "woof!"
But:
Dog.new.respond_to? :bark
=> false
```...
How to: Limit or disable textarea resizing in Chrome and Firefox
Consider this Sass:
.comment
width: 320px;
height: 240px;
Any textarea with the comment class will be sized 320 by 240 pixels. In WebKit browsers (Chrome, Safari, ...) or Firefox, this is only the initial size -- users can resize textareas to become bigger.
This is helpful to the user, but may be breaking your application layout in some cases.
If you want to disable it, don't introduce any proprietary CSS properties. Instead, set maximum width and/or height to the values of width and height:
.comment
wi...
Cucumber: Calling multiple steps from a step definition
When refactoring a sequence of steps to a new, more descriptive step, you can use the steps method and Ruby's %-notation like this:
Given 'I have an article in my cart' do
steps %(
When I go the article list
And I open the first article
And I press "Add to cart"
)
end
This way you can simply copy the steps over without any changes.
Warning: Apparently, steps processes its argument with the Gherkin parse...
Install rabbitmq plugins (e.g. management plugin) on Ubuntu 12.04
If you want to install rabbitmq plugins on Ubuntu 12.04 you can do this with:
/usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins
This binary is not in your default $PATH. Beause of this you have to give the full path.
Run specific version of bundler
You can specify the version of bundler to execute a command (most often you need an older version of bundler, but don't want to uninstall newer ones):
bundle _1.0.10_ -v
Bundler version 1.0.10
An example is rails 3.2, which freezes bundler at version ~> 1.0:
Bundler could not find compatible versions for gem "bundler":
In Gemfile: rails (~> 3.2) was resolved to 3.2.0, which depends on bundler (~> 1.0)
Current Bundler version: bundler (1.13.6)
You can solve this with:
gem install bundler -v 1....
Rails 3.1 gives you free down migrations
In Rails 3.1+, instead of defining a separate up and down method you can define a single method change:
class AddComparisonFieldsToReport < ActiveRecord::Migration
def change
add_column :reports, :compare, :boolean
update "UPDATE reports SET compare = #{quoted_false}"
add_column :reports, :compare_start_date, :date
add_column :reports, :compare_end_date, :date
end
end
Migrating up works as expected:
b rake db:migrate
== AddComparisonFieldsToReport: migrating ====================================
-- ad...
Setup your terminal to not scroll when there is new output
When you are scrolling up to investigate a test failure it is super annoying when the terminal scrolls back down whenever the running test outputs another line. Luckily you can disable this behavior:
- Gnome terminal: *Edit -> Profile preferences -> Scrolling", uncheck Scroll on output
- Terminator: Right click on terminal screen, Preferences -> Profile -> (for each profile) -> Scrolling, uncheck Scroll on output
Ruby 1.8.7-p370 released
It's the last bugfix release. We will get another year of security fixes, then no more patches.
Updated: Test a gem in multiple versions of Rails
Updated the card with our current best practice (shared app code and specs via symlinks).
has_defaults is now a gem
- has_defaults is now a gem, no longer a plugin.
- The plugin version no longer exists. Note that plugins are no longer supported in 3.2.
- If you are working on an application that has the plugin version of
has_defaultsthere is no advantage to be gained from upgrading the gem. The gem is there for you should you one day upgrade to Rails 3.2+. - Please don't use the defaults gem which we original forked away from in 2009. It sets defaults when a field is `bl...
Err http://de.archive.ubuntu.com [...] 404 Not Found [IP: 141.30.13.20 80]
I've got often this error on just one server:
Err http://de.archive.ubuntu.com precise/universe amd64 Packages
404 Not Found [IP: 141.30.13.20 80]
But there was no problem with the network connection or the de.archive.ubuntu.com server.
After I deleted the local lists cache with rm -r /var/lib/apt/lists it works again.
Consul 0.3.0 has a shortcut to quickly create an action map for CRUD controllers
In moderately complex authorization scenarios you will often find yourself writing a map like this:
class NotesController < ApplicationController
power :notes, :map => {
[:edit, :update] => :updatable_notes
[:new, :create] => :creatable_notes
[:destroy] => :destroyable_notes
}
end
Because this pattern is so common, Consul now has a shortcut :crud to do the same:
class NotesController < ApplicationController
power :crud => :notes
end
rake spec + rails_admin = weirdly failing specs
If you use rails_admin, your specs pass with the rspec binary, but not using rake spec (or rake parallel:spec etc), put this at the top of your spec_helper:
ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'false'
Don't ask.
This is probably also true for cucumber, your env.rb would be the right place.
How to deal with: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type [...] at
-
Check if you have puppetsync enabled on the master and client
[main] logdir=/var/log/puppet vardir=/var/lib/puppet ssldir=/var/lib/puppet/ssl rundir=/var/run/puppet factpath=$vardir/lib/facter templatedir=$confdir/templates pluginsync = true -
Check in
/var/lib/puppet/libthere should be a [...].rb somewhere. Delete it and look if it get copied again after with the next puppet run. -
If you are using environments make sure the puppetmaster is also in the correct environment. (d...
Get the initial username which you used to login to your Linux system
If you need the initial user which you used to login to your Linux system or the time when you login you can do:
whoami
One purpose of this could be the .bashrc to show different Bash Prompts for root to different users:
if [ $(whoami) = "root" ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[41;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
Difference between class_inheritable_attribute and class_attribute | martinciu's dev blog
How to make class_attribute behave like class_inheritable_attribte which no longer exists in Rails.
Rack dies when parsing large forms
- Rack has a limit for how many form parameters it will parse.
- This limit is 65536 by default.
- There is a bug in Rack that will incorrectly count the number of input fields in nested forms. In my case a form with 1326 input fields was enough to break the default limit.
- If Rack thinks your request is too large, the request will fail with a low-level Ruby message like Fix: "undefined method `bytesize' for #" or the standard Rails error box.
- You ...
RSpec claims nil to be false
RSpec's be_false behaves unexpectedly:
nil.should be_false
# passes, as the expectation returns true
If you want to check for false, you need to do it like this:
nil.should == false
# fails as expected