There is no such thing as a "default order" of rows in database tables.
For instance, when you paginate a result set: When using
LIMIT, it is important to use an
ORDER BY clause that constrains the result rows into a unique order. Otherwise you will get an unpredictable subset of the query's rows. You might be asking for the tenth through twentieth rows, but tenth through twentieth in what ordering? The ordering is unknown, unless you specified
If the application under test makes sound, you probably want to disable this during integration testing.
You can use the
args option to pass parameters to the browser. For Chrome:
Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, browser: :chrome, args: ["--mute-audio"]) end
I haven't found a corresponding command line option for Firefox.
Hat tip to kratob.
If you use Angular 1.4+ together with Angular Animate, all
ng-class etc. are animated on default.
If you want only some elements to be animated there are 2 possibilities: Either disable animations globally and only run animations if the element has a certain class or enable animations globally and add a certain class if no animation is wanted.
@app.config ['$animateProvider', ($animateProvider) ->
deadlock 0x7f8a4160a360: sleep:- (main) - /home/me/.rbenv/versions/1.8.7-p375/lib/ruby/gems/1.8/gems/bundler-1.14.3/lib/bundler/worker.rb:43 deadlock 0x7f8a38c03b08: sleep:- - /home/me/.rbenv/versions/1.8.7-p375/lib/ruby/gems/1.8/gems/bundler-1.14.3/lib/bundler/worker.rb:56 *** longjmp causes uninitialized stack frame ***: /home/me/.rbenv/versions/1.8.7-p375/bin/ruby terminated
… followed by a backtrace, memory map and more.
The culprit seems to be Bundler 1.14 when used with Ruby 1.8.7. [Downgrade to the maximu…
You can usually just use the
eq matched to compare two numbers:
If the actual value is a
BigDecimal, you might have issues when you match it against a
In these cases, try matching it against another
expect(deal.total_price).to eq BigDecimal(1200.99)
If you don't like the syntax, our rspec_candy gem has a matcher that will compare
Floats and `BigDecima…
When a fragment updates cannot find the requested element, you can now define a fallback selector to use instead.
[up-fallback] attribute has been added to all CSS selectors that update fragments, like for
You can also define fallbacks globally using the [
If you're using the Capybara webdriver, steps sometimes fail because the browser hasn't finished loading the next page yet, or it still has a pending AJAX request. You'll often see workarounds like
When I wait for the page to load Then ...
Workarounds like this do not work reliably, will result in flickering tests and should be avoided. There is no known reliable way to detect if the browser has finished loading the page.
Instead you should wait until you can observe the result of a page load. E.g. if yo…
We generally use multiple application servers (at least two) and you have to search on all of them if you don't know which one handled the request you are looking for. Capistrano can help you with that by running commands on multiple servers.
Logs usually live in
You can use
grep in this directory to only search the latest logs or
zgrep to also search older (already zipped) logs. `zg…
If you have a replication error with MySQL and you know the "error" is okay (e.g. you've executed the same statement at the same time on 2 masters which sync each other), you can skip this error and continue with the replication without having to set up the slave from the ground up.
stop slave; set global sql_slave_skip_counter = 1; start slave;
But what if you have multiple errors which you want to skip? (e.g. you've executed multiple statement at the same time on 2 masters which sync each other)
Still do not use a value highe…
This error message may occur when rspec gets loaded by rake, e.g. when you migrate the test database.
NoMethodError: undefined method 'last_comment' for #<Rake::Application:0x0055a617d37ad0>
Rake 11 removes a method that
rspec-core < 3.4.4 depends on. To fix, lock Rake to < 11 in your Gemfile:
gem 'rake', '< 11', # Removes a method that rspec-core < 3.4 depends on
sort method doesn't work as expected with German umlauts:
["Schwertner", "Schöler"].sort => ["Schwertner", "Schöler"] # you probably expected ["Schöler", "Schwertner"]
Also numbers in strings will be sorted character by character which you probably don't want:
["1", "2", "11"].sort # => ["1", "11", "2"] # you probably expected ["1", "2", "11"]
Also the sorting is case sensitive:
["a", "B"].sort # => ["B", "a"] # yo...
Sometimes you only want to
pop parts of the stash. Do this the way vice versa:
git stash pop git stash -p # Now move all the unnecessary parts back into the stash
Here's a pretty useful steps that hasn't made it into Spreewald yet.
It is best used with the auto-mapper for BEM classes in
When /^I hover above (.*) element$/ do |selector| page.find(selector_for(selector)).hover end
When I hover above the album's image element
→ triggers a hover event on
We have projects that have been developed using many different versions of Ruby. Since we do not want to constantly update every old project, we need to have many Ruby versions installed on our development machines.
Rbenv does that for us.
Rbenv installs ruby version and ruby gems to
~/.rbenv/versions/VERSION_NUMBER/.... This way many different Rubies can be installed at once.
When you run
bundler or any other Ruby binary
When you are changing the version of Rubygems or Bundler on a system where you've bundled into a specific directory (which is mostly the case on an application server), remember to wipe that bundle directory in addition to the user and system gems. This is required because deploying again will not overwrite the shared cached gems.
Reason is, the binaries included in your gems are turned into binstubs by Rubygems and thus implicitly rely on a certain Rubygems version. Especially when downgrading Rubygems, this may lead to issues.
Using uncountable resources is not recommended as it breaks Rails' magic, e.g. when using
form_for. You'll always be better off using simple pluralizable resources.
Rails automatically creates path names for routes defined via the
resource method. When you put
resource 'user' into
config/routes.rb, you can call
users_path and get the path to the
index action in the
However, if you have an uncountable resource like
Sheep, you cannot access the index action via
sheep_path, because it will…
There are some inconvenient Gem dependencies. Resolve them by adding/modifying these lines in your Gemfile:
gem 'guard-livereload', '>= 2.5.2', require: false # Fixes a security issue gem 'listen', '< 3.1' # 3.1 requires Ruby 2.2.5
It is not possible to install
guard-livereload 2.5.2 on Ruby 1.8.7 because it depends on
guard 2.8, which requires Ruby 1.9.