Our rspec_candy gem now gives you three matchers: be_same_number_as Tests if the given number is the "same" as the receiving number, regardless of whether you're...

...purposes". Internally the matcher compares normalized results of #to_s. be_same_second_as Tests if the given Time or DateTime is the same as the receiving Time or DateTime...

require 'spreadsheet' Spreadsheet.client_encoding = 'UTF-8' book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet :name => 'test' money_format = Spreadsheet::Format.new :number_format => "#,##0.00 [$€-407]" date_format = Spreadsheet::Format.new :number_format => 'DD.MM.YYYY...

...sheet1.column(2).default_format = date_format sheet1.row(0).push "just text", 5.98, DateTime.now book.write 'test.xls' That's how to insert Links into a excel cell book = Spreadsheet::Workbook.new sheet1 = book.create...

...and qualified:fields') This trait used to be a huge blob of code without tests and documentation, so I made a gem out of it. Check out https://github.com/makandra/dusen...

...for code, tests, and a huge README. You should use the Dusen gem and delete SearchableTrait in all future projects. Note that the syntax to define query processors has changed...

...SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=unknown state SSL Server Test This SSL Server Test can help finding out which SSL/TLS versions the server can handle...

medium.com

Advantages over a classic Rails monolith By (automatically) only requiring expected/allowed dependencies in tests, components cannot accidentally use (i.e. depend on) code they're not allowed to

...of the clear separation and dependencies. No need to know the whole application. Faster test runs, because only dependent components need to run. A growing team can still keep up...

...server from time to time. Before doing a full deploy, you might want to test that server in an isolated deploy. There is a single way to do this: the...

...run for servers matching {:roles=> }, but no servers matched. Instead, specify the server-under-test like this: HOSTFILTER=separate-sidekiq.makandra.de cap production deploy Capistrano is aware of this env variable and...

...staging', 'production']. Remove better_errors from Gemfile if existing and bundle. With Raven.capture_message('Test from development') you can test your setting on console. Raising an exception will now report...

Sometimes you need a file of some size (possibly for testing purposes). On Linux, you can use dd to create one. Let's say you want a 23 MB file...

...called test.file. You would then run this: dd if=/dev/zero of=test.file bs=1048576 count=23 The block size (bs) is set to 1 MB (1024^2 bytes) here, writing...

makandra dev
github.com

...through of unknown options to Cucumber Add --rerun=N option to rerun failed Cucumber tests up to N times. Reboots the test environment between runs, thus will pick up fixes...

If you want to freeze a different version of a dependency for your tests, prefer putting it into the Gemfile in your gem project directory. In the example above...

...gemspec like this: spec.add_dependency 'activesupport' Then, in your Gemfile, add the dependency for tests: gem 'activesupport', '~> 2.3'

makandra dev

This describes how to migrate an existing cucumber test suite to Spreewald. Add the gem Include spreewald into your cucumber environment by putting require 'spreewald/web_steps' require 'spreewald/email_steps' # ... or just

...web_steps, shared_steps, table_steps, email_steps etc. Comment it out. Run your test suite. It will probably complain about missing steps, those that didn't make it into...

...XrayWrapper [object HTMLInputElement]] (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError) I had the Terminal window running the test on my secondary screen, whereas the Selenium-webdriven Firefox always started on my primary one...

...Now if I had focused the secondary screen when running the tests, Selenium could not start Firefox and switch to it (probably because the screens are split), generating the above...

.../home/user/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/capistrano-3.14.1/lib/capistrano/tasks/deploy.rake:90:in `block (5 levels) in <top (required)>' 11: from /home/user/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/sshkit-1.9.0/lib/sshkit/backends/abstract.rb:50:in `test' 10: from /home/user/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/sshkit-1.9.0/lib/sshkit/backends/abstract.rb:137:in `create_command_and_execute' 9: from /home/user/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/sshkit-1.9.0/lib/sshkit/backends/abstract.rb:137:in `tap...

...silence some specific warnings. Add this to your initializers, or require it in your tests: silenced = [ /Not considered a useful test/, /use: should(_not)? have_sent_email/, ] # list of warnings...

makandra dev
github.com

capybara-lockstep can help you with flaky end-to-end tests: This Ruby gem synchronizes Capybara commands with client-side JavaScript and AJAX requests. This greatly improves the stability of...

...a full-stack integration test suite, even if that suite has timing issues...

makandra dev

...Listening on localhost:36309, CTRL+C to stop If you are running parallel tests with thin, this will clutter you output. Disable thin logging with these lines: # e.g. in features/support/thin.rb...

Thin::Logging.silent = true Note that this disables all logging in tests. Instead, you also might set a different logger with Thin::Logging.logger = . See Thin::Logging for details...

When using geordi for integration tests you might get the following error when trying to run geordi cucumber: unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium...

...WebDriver::Error::WebDriverError) This means, that the vnc window the tests is talking to has no proper firefox version running. To figure out the issue this might help you:

...they are wrapping the same native DOM elements: $('body') == $('body') // false In order to test if two jQuery objects refer to the same native DOM elements, use is:

Jasmine equality matcher for jQuery See here for a custom Jasmine matcher that tests if two jQuery objects are equal...

PostgreSQL supports the SQL OVERLAPS operator. You can use it to test if two date ranges overlap: => SELECT ('2001-02-16'::date, '2001-12-21'::date) OVERLAPS...

...date, '2002-10-30'::date); overlaps -------- false Also compare our card Test if two date ranges overlap in Ruby or Rails...

When testing Ruby code that prints something to the terminal, you can test that output. Since RSpec 3.0 there is a very convenient way to do that. Anything that writes...

...print) can be captured like this: expect { something }.to output("hello\n").to_stdout Testing stderr works in a similar fashion: expect { something }.to output("something went wrogn\n").to...

makandra dev

...if you make any error in programming. E.g. a simple typo would make the test above green. The block will catch the Spec:: exception and the test will be happy...

...headless chrome via Selenium. This might be useful for debugging issues with flaky integration tests or slow page simulations. page.driver.browser.network_conditions = {offline: false, latency: 5, download_throughput: 2 * 1024, upload...

...from you Rails timezone settings / system timezone. I usually have this use case in tests. Example Time.parse('2020-08-09 00:00') will return different results e.g...

In Ruby you can communicate between processes with sockets. This might be helpful in tests that validate parallel executions or custom finalization logic after the garbage collector. Here is an...