If you have problems with SSH session timing out, add the following to your /etc/.ssh/config
:
Host *
ServerAliveInterval 55
ServerAliveCountMax 2
Capybara's has_css?
matcher has a couple of options you might find useful.
Use the :count
option like this:
Then /^I should see (\d+) users?$/ do |count|
page.should have_css('ul#users li', :count => count.to_i)
end
Use the :text
option like this:
Then /^I should see a user with name "([^\"]*)"$/ do |nam...
Hooks lets you define hooks declaratively in your ruby class. You can add callbacks to your hook, which will be run as soon as you run the hook.
Even when you're using bundler, it might be significant in which order your gems are listed in your Gemfile
. This can happen when gems are running around calling require
or require_dependency
on other gems or application classes when loaded (don't do that!).
A known culprit of this is the (otherwise wonderful) resource_controller gem, which requires ApplicationController
when loaded. When your ApplicationController
requires later-loaded gems when loaded, Rails will not boot.
He...
This post will describe how I stumbled upon a code path in the Linux kernel which allows external programs to be launched when a core dump is about to happen. I provide a link to a short and ugly Ruby script which captures a faulting process, runs gdb to get a backtrace (and other information), captures the core dump, and then generates a notification email.
It can be useful to have a Ruby expression like condition ? positive_case : negative_case
in MySQL queries:
UPDATE users SET monthly_debit = IF(subscriber, 19, 0)
[ ] [ ]=
**
! ~ + -
* / %
+ -
>> <<
&
^ |
<= < > >=
<=> == === != =~ !~
&&
||
.. ...
? :
= %= { /= -= += |= &= >>= <<= *= &&= ||= **=
defined?
not
or and
if unless while until
begin/end
For more information see Table 18.4 in The Pragmatic Programmer's Guide.
A good tool to generate strong passwords and secrets is "apg". You can get it with
sudo apt-get install apg
To create a strong secret for sessions, hashed Paperclip paths, etc. say
apg -m128 -a1 -E\'\"
Arguments explained:
-m
parameter defines the secret length-a1
makes apg choose from all 7-bit ASCII characters instead of just the alphabet-E\'\"
excludes quote characters so you can easily paste the secret into a Ru...Inside before
:each
blocks you can refer to variables that you introduce via let
later on.
They do not need to be defined ahead of your before block and can be different for individual sections.
It works just like that:
describe User do
describe '#locked?' do
before :each do
subject.should_receive(:current_plan).and_return plan
end
context 'when expiring today' do
let(:plan) { stub(:expiry => Date.today) }
it 'should be false' do
subject....
Ruby gem that provides an AR-style interface for the Pivotal Tracker API.
You need to install the following packages before you can build the Paperclip gem:
sudo apt-get install imagemagick librmagick-ruby
If you have several submit elements (input
s or button
s with type="submit"
) that each cause different things to happen (e.g. you might have a button that sends an extra attribute) you might run into trouble when submitting the form by pressing the return key in a field.
When nothing fancy like a tabindex
is defined it seems as if the first submit element inside a form is chosen (and has its attributes submitted) when pressing return.\
So, if possible, put your "default" (aka least harmful) submit element before others.
NB: If you s...
If you need to call a state_machine
event and do not want to re-define resource_controller
's create
method, try this:
create.before do
object.state_event = :launch_spaceship
end
If a SSH shell dies (from timeout for example), you cannot kill it with the usual CTRL-C
or CTRL-Z
. Instead, press
[ENTER]~.
(That is ENTER TILDE PERIOD
).
Note that you should disable the Java plug-in in your browsers after installation.
Java 11
sudo apt install openjdk-11-jre-headless
Java 10
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Java 8
You probably want to get rid of OpenJDK (which is installed by default and leads to bad RubyMine performance):
...
Both these approaches will keep your GET
parameters -- and will only work for GET
requests.
Capybara:
When /^I reload the page$/ do
visit [ current_path, page.driver.request.env['QUERY_STRING'] ].reject(&:blank?).join('?')
end
Webrat:
When /^I reload the page$/ do
visit url_for(request.params)
end
For a step that distinguishes between drivers (Selenium, Rack::Test, Culerity), check [n4k3d.com](http://n4k3d.com/blog/2011/02/02/reloading-the-page-in-cucumber-with-capybara-and-seleniu...
Cucumber step argument transforms can be a powerful way to make your steps more flexible.
Note however that if your transform only matches a substring (no ^
and $
markers at the beginning and end), you are still expected to return a replacement for the whole string that was piped through the transform. If you don't do that, you will truncate that string and possibly make the calling step match where it should not.
Let's say you want a transform that replaces subs...
So this is the simulation that I use in my Agile Testing class, as well as in other contexts where I want to teach lessons about increasing Agility. The mechanics of the simulation itself are very general: the simulation models the organization of a software company. It just happens to work really well for making Agile concepts very visible, and visceral.
RSpec's context
(which is basically an alias for describe
) takes over your whole application. No object may have its own context
method, or you will always receive errors like
"No description supplied for example group declared on ~/project/app/..."
The easiest workarounds:
context
describe
instead of context
in your specs, and put this into your spec_helper.rb
:\/etc/crontab
/etc/cron.d/*
/etc/cron.hourly/*
/etc/cron.daily/*
/etc/cron.weekly/*
/etc/cron.monthly/*
crontab -l
and edit with crontab -e
. You'll need to su
to the respective user to view or edit her crontab.When you need to delete rows from a table, and the delete conditions require a joined table, MySQL needs to know which table you want to delete from.
Let's say that Post belongs_to :author
. In order to delete all posts from the author named "Eric", write
DELETE posts FROM posts LEFT JOIN authors ON posts.author_id = authors.id WHERE authors.name = 'Eric'
Notice the additional "posts" between DELETE
and FROM
.
Some web fonts with bad hinting can be fixed by applying auto-hinting with Font Squirrel.
You can use
record.send(:update_without_callbacks)
or
record.send(:create_without_callbacks)
This can be used as a lightweight alternative to machinist's make
or FactoryGirl's create
, when you just need objects in the database but don't care about any callbacks or validations. Note that create_without_callbacks
does not return the object, so you might want to do
record = Record.new.tap(&:create_without_callbacks)
Rails 3 no longer comes with update_without_callbacks
or `crea...
We use RTeX for PDF exports.
While converting LaTeX to PDF, RTeX opens a temporary file which has problematic permissions: Both group and world can read those files.
Although the temp files should go away they sometimes live longer than one would expect.
We patched RTeX to fix this (and have more secure permissions). Place the code below into config/initializers/rtex.rb