makandra dev

...both Gemfile as well as Gemfile.lock to the repository. Use bundle to execute your tests using the current bundled environment. Make sure you didn't break anything: bundle exec spec...

Update your scripts Most of us have some alias scripts to run all tests (e.g. ~/bin/tests). Update those scripts so they use bundle exec like this: #!/bin/sh

...a problem when using Selenium with Firefox. We recommend using ChromeDriver for your Selenium tests. This setup allows to test focus/blur events in Cucumber tests (using Selenium). For background information...

...solve Selenium focus issues. Cucumber step definition: # This step is needed because in Selenium tests, blur events are not triggered # when the browser has no focus. When /^I unfocus the...

The step definition below allows you to write: Then I should see an HTML redirect to "http://www.makandracards.com" in the...

...fast binstubs like bin/rails or bin/rspec which avoid Rails boot time. You want parallel_tests to speed up full test runs of large test suites. Unfortunately, you do not want...

...parallel_tests to use your Spring binstubs as those parallelized tests will share data and/or loose some information. There are some issues about this on GitHub and there is a...

In case your integration tests crash with a message like below, try to upgrade Capybara to a newer version (3.35.3 was good enough). You might encounter this issue when you...

Most of these will not work in newer projects because these use the Capybara/Rack::Test combo in lieu of Webrat. Find input fields Then /^there should be a "([^"]+)" field$/ do...

If you want to test that a certain text is contained within the document title of your page, you can do so using Selenium and a step such as

...Selenium note, I found yet another solution for the problem to hide your selenium tests away. This has the advantages ^ not to require a gem (so you do not force...

...at the running webdriver if necessary Simply make a script that runs your cucumber tests and runs this before: vncserver :6 -localhost -nolisten tcp -SecurityTypes None &>/dev/null DISPLAY=":6"

makandra dev
github.com

...for the first time (bundle install, create database.yml, create databases, migrate), optionally run all tests (--test) or load a dump (--dump staging) update: update a Rails project that has been...

...open a shell on a Capistrano target, optionally selecting the server with --select-server tests: run all employed tests; checks for: Cucumber, RSpec, Test::Unit and rake with-firefox-for...

...same regardless of the driver Capybara is using (drivers are e.g. the headless Rack::Test or Selenium). It is a stupid idea to call #node on such a Capybara node...

...used by the driver, e.g. instances Nokogiri::XML::Element if you are using Rack::Test, or of Selenium::WebDriver::Element if you are using Selenium. Because the API of these...

...return means "exit the lambda" How to define a lambda With the lambda keyword test = lambda do |arg| puts arg end With the lambda literal -> (since Ruby 1.9.1)

...also are next and continue How to define a block With the proc keyword: test = proc do |arg| puts arg end With Proc.new: test = Proc.new do |arg| puts arg

Travis CI is a free continuous integration testing service. However, it is really fragile and will break more than it will work. If you choose to use it anyway, learn...

...add before_script: rvm rubygems latest-1.8 --force to .travis.yml. However, if you run tests for multiple Ruby versions, you need to add before_script: travis:prepare to .travis.yml. In...

...will encounter validation errors being added twice occasionally. This happened to me when during tests: a spec was referring to Foo, which was not yet loaded, because it was in...

...ran its manual validation method twice. Consider the fun you'll have when running tests in parallel...

...ETags can again match. Before I make this change I like to add a test that ensures I did it correctly. For this add the following code to spec/requests/default_etag_spec.rb. You...

...ActionView::Base).to receive(:image_path).and_return('image') # CSRF protection is disabled in tests by default. Activate it for this spec as # randomly masked CSRF tokens are a major...

Then /^I should get a response with status (\d+)$/ do |status| response.status.should include(status) end Capybara Then /^I should...

...their default distribution from Ubuntu 14.04 (trusty) to 16.04 (precise). This might break your test setup for new builds. You can solve this issue by freezing your test distribution in...

...builds might have started failing on the usual psql -c 'create database active_type_test;' -U postgres with an error psql: could not connect to server: No such file or...

You want to test your 1GE or 10GE internet uplink? We needed to ensure we have full 10GE to the backbone for a customer project. Using netcat To test whether...

If your application does something specific on certain hostnames and you want to test this in a feature, you need to tell Capybara to assume a different host.

...scenario (i.e. you do not need an After step to clean up). Notes: Selenium tests will actually visit the app_host, so you can't really use it for those...

This is an awful way to test whether a number is shown on the screen: Then I should see "5" It is awful because the step above is green for...

...see the number 5 The step also works if you you'd like to test that the number is followed by a unit: Then I should see the amount...

The Rails sandbox In development, Rails' sandbox mode might be useful. Testing and the migration codebase The migration code should live in some subdirectory in the project...

...steps, instead of implementing some complicated Sidekiq batch logic etc. You need to write tests as you will usually have to refactor your code several times, and need to know...

Note: This technique is confusing and slows down your test suite. Copy the attached code to features/support. This gets you a new Cucumber tag @no_parallel which ensures that the...

...scenarios not tagged will @no_parallel can still run in parallel with the tagged test. Please read the previous sentence again. This can help when multiple test processes that access...

...pending Cucumber step (or feature) that also uses an existing VCR cassette, your pending test may fail at the very end with an error like this: There are unused HTTP...

...your VCR is configured to complain about cassettes that contain extra requests which your test did not use. This is often a good configuration. If you do not want to...

...should extract that behavior into a trait or module. This card describes how to test that extracted behavior without repeating yourself. Note that the examples below use Modularity traits to...

...app/models/page.rb class Page < ApplicationRecord include DoesSanitizeHtml end # app/models/template.rb class Template < ApplicationRecord include DoesSanitizeHtml end Testing test trait usage with a shared example group When two classes share behavior through a...

...need a special version of chrome because it has some features you need for testing, like in this card. You do not need to use that Version apart from tests...

end Capybara::Selenium::Driver.new(app, :browser => :chrome) end You can use this for tests with a special chrome versions as well, you can have several - see this card