Create autocompletion dropdown for Cucumber paths in Textmate
Ever wanted autocompletion for paths from paths.rb
in Cucumber? This card lets you write your steps like this:
When I go to path *press tab now* # path is replaced with a list of all known Cucumber paths
This is how you do it
(key shortcuts apply for TextMate2)
-
Open the bundle editor (ctrl + alt + + B)
-
Create a new Item ( + N), select "Command"
-
Paste this:
^
#!/usr/bin/env ruby -wKU
require File.join(ENV['TM_SUPPORT_PATH'], 'lib', 'ui.rb')cucumber_paths = File.join ENV['TM_PROJECT_DIRECTORY'], 'features'...
Resque + God + Capistrano
Attached is a working config to deploy an application with Capistrano that needs to monitor Resque workers with God.
God will run as the deployment user, no need to register it as a system service.
Put this into your config/deploy.rb
:
namespace :god do
def god_is_running
!capture("#{god_command} status >/dev/null 2>/dev/null || echo 'not running'").start_with?('not running')
end
def god_command
...
Net::SSH::Exception: could not settle on encryption_client algorithm
TL;DR: Update the 'net-ssh' gem by adding to your Gemfile
:
gem 'net-ssh', '=2.9.1'
Now run bundle update net-ssh
. It has no dependencies so it shouldn't update other gems.
If you're using Ruby 1.8.7 and want to update net-ssh to a version > 2.9.1
you also need to add this to your gemfile:
gem 'backports', :require => false
... and in your deploy.rb
add this:
require 'backports/1.9.2/array/select'
Background
You propably have an older version of Capistrano and thereby an older version of `n...
Exclusive cronjobs with flock and whenever
I had a very frequent cronjob that in rare cases could be relatively slow. To avoid multiple instances of this cronjob running in parallel, I decided to use flock
to ensure that only one instance could run at a time.
flock
works by acquiring a lock to a file, and if it can do so running a command. In order not to wait but simply give up when the file is locked, you can add -n
:
flock /tmp/my.task.lock -n -c "bin/my-long-running-job"
Using whenever, and since this was a rake task, the follo...
Disabling Spring when debugging
Spring is a Rails application preloader. When debugging e.g. the rails
gem, you'll be wondering why your raise
, puts
or debugger
debugging statements have no effect. That's because Spring preloads and caches your application once and all consecutive calls to it will not see any changes in your debugged gem.
Howto
Disable spring with export DISABLE_SPRING=1
in your terminal. That will keep Spring at bay in that terminal session.
In Ruby, [you can only write environment variables that subproc...
Adjust cron jobs to allow full backtraces for rake tasks
As we get an exception notification, when a cron job fails, we wish to have the full backtrace in this mail. A rake task doesn't output the full backtrace by default, so you need the --backtrace
option.
Trigger
You will find fail mails with a shortened backtrace
#[...]
Tasks: TOP => some_namespace:some_task
(See full trace by running task with --trace)
What rake wants from you
Running the rake task like rake some_namespace:some_task --backtrace
How this works with whenever
Define a own job_type and use it for r...
Accessing Rails config in webpack(er)
It is possible to access Rails config (for example secrets) from within your webpack bundles, thanks to rails-erb-loader. When using webpacker, the setup is like this:
-
Install
rails-erb-loader
:yarn add rails-erb-loader
-
Add this to your
config/webpacker/environment.js
:environment.loaders.prepend('erb', { test: /\.erb$/, enforce: 'pre', use: [{ loader: 'rails-erb-loader', }] })
-
Start using erb. For examp...
Fix: "undefined method `bytesize' for #<Array>"
I believe that when WEBrick has trouble bringing up your Rails application, the WEBrick component that is supposed to print you a pretty error message has a bug and sometimes fails with this message:
"undefined method `bytesize' for #<Array>"
Starting the application in Passenger gave me a stacktrace in log/development.log
that pointed to the actual problem.
Possible causes discovered by looking at the logs
-----------------------------------------------------...
Sending errors to sentry from development
For the initial setup or changes in the sentry reporting it might be useful to enabled reporting of sentry in development. Don't commit these changes and prefer to report to the staging environment. As other developers might be confused of these errors try to given them a proper message and delete them afterwards.
- Add
config.raven_dsn = 'your-dns'
inconfig/environments/development.rb
. - Add development to existing environments in the
Raven.configure
block:config.environments = ['development', 'staging', 'production']
. - ...
Cucumber: How to find unused step definitions
Cucumber has an output format that prints step definitions only. You can use this to find unused ones:
- Temporarily add
require_relative 'env'
to the top of the first file in features/support.--dry-run
makes Cucumber skip loadingenv.rb
. - Open a really wide terminal window.
bundle exec cucumber --dry-run --format stepdefs | grep -B1 'NOT MATCHED' --no-group-separator | grep features/step_definitions
This will print all unused step definitions from your project – however, the result will include false positives. Step...
Gemspecs must not list the same gem as both runtime and development dependency
When you're developing a gem, never list the same dependency as both runtime and development dependency in your .gemspec
.
So don't do this:
spec.add_dependency 'activesupport'
spec.add_development_dependency 'activesupport', '~> 2.3'
If you do this, your gemspec will not validate and modern versions of Bundler will silently ignore it. This leads to errors like:
Could not find your-gem-0.1.2 in any of the sources
What to do instead
If you want to freeze a different version of a dependency for your t...
"cannot load such file -- nokogiri/nokogiri" (or any other Gem with native extensions on rvm and Ruby >= 2)
After running bundler / gem install I could not load nokogiri lately. It died with cannot load such file -- nokogiri/nokogiri
.
This is not a problem of the gem but is due to a broken native extensions installation routine.
When installing nokogiri manually and with verbose output by using gem install -V nokogiri -v 1.5.6
, you can see the problem scrolling by when the native extension is built:
/usr/bin//install -c -m 0755 nokogiri.so /home/thomas/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.5.6/lib/home/thomas/.rvm/rubies/ruby-2.0.0-p...
Shell script to deploy changes to production and not shoot yourself in the foot
Geordi, our collection of command line tools, has been extended by another command deploy-to-production
. This script encapsulates the following workflow:
- Pull the production branch.
- Show which commits from the master would make it to production with this deploy.
- Ask if you want to proceed.
- If yes, merge the master into the production branch, push and deploy with
bundle exec cap production deploy:migrations
The script will ask you for the names of your master branch, production branch an...
How to upgrade Cucumber on Rails 3+
-
Run
bundle update cucumber capybara cucumber-rails
to update to the newest versions. -
Backup your
features/support/path.rb
to be able to add your own paths again after the cucumber installation script in step 4. -
Backup your
features/support/env.rb
file to be able to reintegrate parts like your blueprints setup:ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'spec/support/blueprints'
-
Run `$ rails generate cucumber:install --capyba...
PSA: Dont allow private gems to be pushed to rubygems.org
If you make a gem with Bundler, you will get a rake release
task that will instantly publish your gem to rubygems.org for all the world to admire. For private gems this is very bad.
To make sure this cannot happen, rubygems 2.2+ allows you to restrict eligible push hosts:
Gem::Specification.new 'my_gem', '1.0' do |s|
# ...
s.metadata['allowed_push_host'] = 'https://gems.my-company.example'
end
In case you already messed up, [follow these instructions to get your gem removed](http://help.rubygems.org/kb/rubygems/removing-an-a...
Zeus promises to make rails development faster
I am talking about development speed. When your application starts growing and you start adding gems, it starts to take really long to start up, be it the server, console or just running a single spec.
Zeus is smart, you don’t have to put it in your Gemfile or run it with Bundler, all you need to do is create a JSON config file via
zeus init
and then start the serverzeus start
.
After that, you’re ready to go, all you need to do is prefix every command with zeus. That means
rails server
becomeszeus server
, `rails console...
uninitialized constant MysqlCompat::MysqlRes (NameError)
If you get a stacktrace complaining about uninitialized constant MysqlCompat::MysqlRes
a system library update might broke your gem.
You might have switched from MySQL to MariaDB, but forgot to rebuild your MySQL gems.
Try fully removing and re-installing the gem:
gem uninstall mysql mysql2
bundle install
Sunspot and Solr on Tomcat: Trouble with Umlauts
We experienced problems with Sunspot and Solr on Tomcat: Umlauts (ä, ö, ü) were not correctly handled on Tomcat while everything was okay on the local development machines (your local Sunspot service you start with the sunspot:solr:run
task is based on Jetty).
We use a stemmer that reduces "Sänger" to "sang" and "Sanger" to "sang" as well.
Though, results for "Sänger" where empty on Tomcat.
This is due to a UTF-8 bug in RSolr (see Github for some discussion on that).
The bug is fixed in a ...
Geordi 1.5.1 released
- Improve
geordi cucumber
: Only attempt @solo run when the specified files contain the @solo tag, skip @solo run if any filename is passed with a line number (e.g.features/example.feature:3
) - Improve
geordi deploy
: Find stages by their prefix (e.g.s
-> staging,m
-> makandra), bundle if needed, check the selected stage exists - Improve
geordi server
: Takes port as argument (e.g.geordi ser 3001
), option--public
(-P
) starts the server with-b 0.0.0.0
to make it accessible from other machines in the local network, e.g. ...
Fix Rubygems error: undefined method `source_index' for Gem:Module
You are probably using Ruby 1.8.7 with a too recent versions of Rubygems.
Downgrade your Rubygems to the latest version that works with 1.8.7.
See also
- Fix Rubygems warning: Gem.source_index is deprecated, use Specification
- Fix Rubygems binary error: undefined method `activate_bin_path' for Gem:Module (NoMethodError)
- [Bundler: Gemfile.lock is corrupt & gems are missing from the DEP...
Fix warning: Cucumber-rails required outside of env.rb
After installing Bundler 1.1 you will get the following warning when running tests:
WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called.\
To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile
The warning is misleading because it has nothing to do with moving cucumber-rails
into a :test
group. Instead you need to change your Gemfile
to say:
gem 'cucumber-rails', :require => false
Katapult 0.3.0 released
Katapult 0.3.0 brings Rails 5 and Ruby 2.5 support with a new design, plus a ton of smaller features, fixes and improvements.
Features
- Generating a Rails 5.1.4 app on Ruby 2.5.0
- Dropped asset pipeline in favor of Webpacker
- The generated application now has a sleek, simple design based on Bootstrap
- Employing Unpoly
- New application model DSL shortcut
crud
for "create a model and a web UI with crud actions" - The generated application model is now a transformable e...
No more file type confusion in TextMate2
When using TextMate2 with the cucumber bundle, it does not recognize step definitions (e.g. custom_steps.rb
) as such but believes they are plain Ruby files. But there is help!
Solution
Add these lines to the bottom of your .tm_properties
file (in ~/
for global settings, in any directory for per-project settings):
[ "*_steps.rb" ]
fileType = "source.ruby.rspec.cucumber.steps"
Apparently, this works for any files. Define a regex and specify custom settings. The attached article lists all available configuration options (whic...
Listing all gems on a private gem server
You can use gem list
to list all gems available from a remote gem server:
gem list -r --clear-sources -s 'https://user:password@gemserver.tld/'
This is useful to debug cases where Bundler complains of a gem existing in more than one gem source.