...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
...inserted data in a migration or when you had to kill -9 a frozen test process. Old Capybara versions already have the Database Cleaner gem as dependency. Otherwise add database...
...Rake task by copying the attachment into lib/tasks/clean_database.rake. Now you can e.g. clean the test database by saying on the shell: rake db:clean RAILS_ENV=test
...If you haven't installed Firefox 24 yet, the next time you run tests with Geordi, it will tell you how to install it. On a Rails 2 project:
-> Remove cucumber_spinner from Gemfile. We're not using it in parallel_tests anyway...
...expect(timerCallback).not.toHaveBeenCalled(); jasmine.clock().tick(101); expect(timerCallback).toHaveBeenCalled(); }); If you actually want the test to wait out the timer, your example function needs to accept a done argument, which...
...you then call when the test is expected to finish: it("causes a timeout to be called", function(done) { setTimeout(function() { timerCallback(); }, 100); setTimeout(function() { expect(timerCallback).toHaveBeenCalled();
...fix" this in multiple ways: Update your drivers on your machine with RAILS_ENV=test rake webdrivers:chromedriver:update Ignore the driver update-URL in your VCR configuration
...does not support Ruby 1.8.x anymore removes confusion with Rails' built in integration tests (you put capybara rspec integration tests into the spec/feature/... folder) and the :type metadata has...
...first detected element found by the identifier) has a new syntax for writing integration tests with capybara in rspec (describe => feature, it => scenario) Excerpt of some other major changes
The easiest way to freeze or travel through time in a Jasmine spec is to use the built-in jasmine.clock...
There is a kind of features in web applications that hinder automated integration tests. Examples include cookie consent banners or form captchas. Clearly, these should be disabled so you do...
...not have to explicitly deal with them in each and every test (like, every test starting with accepting the cookies notice). On the other hand, they must be tested as...
Consider this class: class Foo private def test puts "Hello" end end While you can say create a block to call that method (using ampersand and colon) on Ruby...
...Foo.new.tap(&:test) Hello => # ... you cannot do that on Ruby 1.9 or 2.0: 1.9.3 > Foo.new.tap(&:test) NoMethodError: private method `test' called for # ^ 2.0.0 > Foo.new.tap(&:test) NoMethodError: private method `test' called for...
...Specs with --backtrace option Run Cucumber features (with Geordi's --debug option) When all tests are green, look through your Gemfile and remove as many version constraints as possible.
Update rspec to '< 2' Lock haml to '= 3.1.7' Unlock andand Unlock rake Lock test-unit to '= 1.2.3' Lock database_cleaner to '< 1.3' Lock cucumber to '< 2'
...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...