.../regex/.test(...) is converted to a string as defined by the specs, which means e.g. .test(null) is equal to .test("null"). Globally matching regex objects remember the last index they...
...matched. Multiple calls to test() will advance this pointer: matcher = new RegExp("foo", "g") // <- "global" flag matcher.test("foobar") // => true matcher.lastIndex // => 3 (where the regexp stopped scanning) matcher.test("foobar") // => false matcher.lastIndex...
You may have asked yourself how you're able to keep your test databases clean, if you're running multiple databases with full read and write access at...
development: primary: <<: *default database: my_app_development migration: <<: *default database: my_app_migration test: &test primary: <<: *default database: my_app_test_<%= ENV['TEST_ENV_NUMBER'] %> pool: 20 migration: <<: *default...
In Cucumber, scenario outlines help avoiding tests that are basically the same, except for a few variables (such as different inputs). So far, nothing new. The problem
...your test should (or should not) do something, like filling in a field only for some tests? Scenario Outline: ... When I open the form And I fill in "Name" with...
Within development and test environments, Rails is usually configured to show a detailed debug page instead of 404s. However, there might be some cases where you expect a 404 and...
...want to test for it. An example would be request-specs that check authorization rules. (If you use a gem like consul for managing authorization rules, you should always check...
...navigate to Settings -> Editor -> File and Code Templates. Example You can navigate to the test file of the currently open file with the shortcut Ctrl + T. If no test file...
...exists, you can generate a new test file. If you are not pleased with the output, you can adjust the related code template. To do this, open the project settings...
...close them as well! See the suggested helper at the bottom of this card. Test support If you access Redis in tests, I suggest introducing a helper method. Example for...
...redis ||= Redis.new(url: REDIS_URL) end end RSpec.configure do |config| config.include(RedisHelpers) end Your Tests may then say redis.get('example'). But I still want to use a global
...Let's say for example, you maintain a gem and want to run automated tests against multiple rails versions. When you need to bundle one of your secondary Gemfiles, the...
...out, e.g. when hunting down a bug or embedding a Rails app into the tests of a gem. What you do is basically: Put everything (gems, application config, database migrations...
If you need to test interaction with a remote API, check out the VCR gem as an alternative to Webmock or stubbing hell. The idea behind VCR is that is...
...HTTP requests and logs the interaction in a .yml file. When you run the test again, requests and responses are stubbed from the log and the test can run offline...
...get Jasmine specs running in a Rails project using Webpacker, with the browser based test runner. Should be easily adaptable to a pure Webpack setup. Step 1: Install Jasmine
...Javascript, we will create two additional packs. The first only contains Jasmine and the test runner. The second will contain our normal application code and the specs themselves.
...What you can do is change the time zone of the process running your tests by setting a TZ=CET (or TZ=PDT or TZ=UTC etc.) environment variable.
...way, when the test process spawns another process to run a browser, it will inherit the environment and also believe it lives in that zone. To do so, run the...
These steps are now part of Spreewald. Here are some useful examples how to use the attached Cucumber Timecop steps...
Testing your responses in Rails allows to parse the body depending on the response MIME type with parsed_body. get '/posts.json' response.parsed_body # => [{'id' => 42, 'title' => 'Title'}, ...]
When testing your command line application with Aruba, you might need to stub out other binaries you don't want to be invoked by your test. Aruba Doubles is a...
I recently stumbled over a problem that my feature tests broke in CI because of a mismatching chromedriver version. In this specific project we have a fixed Chromium version in...
...a Debian 12 environment instead of Chrome. The tests however used a recent chrome version instead. $ chromedriver --version ChromeDriver 117.0.5938.149 (e3344ddefa12e60436fa28c81cf207c1afb4d0a9-refs/branch-heads/5938@{#1539}) $ chromium --version Chromium 117.0.5938.149 built on...
Jasmine comes with two matchers that test for equality. The first is toBe: expect(first).toBe(second) toBe passes when first === second. Unfortunately this is useless for non-primitive values...
...teach toEqual additional notions of equality. E.g. the following code will teach toEqual to test two jQuery collections for equality: beforeEach -> jasmine.addCustomEqualityTester (first, second) -> if first instanceof jQuery && second instanceof...
When you need to see the content of a page (i.e. not all the HTML but the relevant text body...
# Redis db#1 is used for development. db_number = 1 if rails_env == 'test' normalized_test_number = [ENV['TEST_ENV_NUMBER'].to_i, 1].max db_number += normalized_test...
While we are used to run our JavaScript tests on a test page within our Browser, it's also possible to run them on the command line with NodeJS. I...
...think that's actually the most common way to run JS tests. Given a Vue project that uses Jest (via vue-cli-service) with the following package.json: { "scripts": { "test": "vue...
...favicon.ico in your project but also PNGs of different sizes and backgrounds, you should test if all those files are actually reachable. Here are a few selectors to get you...
...pass visible: false for each selector so Capybara can find them. Example The following test was taken from a project using ActionDispatch::IntegrationTest. Though we usually use RSpec, this should...
...to 127.0.0.1:1025. Usually you want the following config in config/environments/development.rb and maybe in test.rb or cucumber.rb. config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => 'localhost', :port => 1025 } Now you can see...
Don't use reruns as a mean to work around flaky tests. You should always try to fix those instead of rerunning them regularly. Setup Configure RSpec to persist...
...the result of your test runs to a file. This is necessary to be able to rerun examples. Add this to your spec/spec_helper.rb : config.example_status_persistence_file_path = 'spec/examples.txt'
Webpack is the future. We're using it in our latest Rails applications. For tests, we want to compile assets like for production. For parallel tests, we want to avoid...
Here is our solution for all that. Its concept should work for all test suites. Copy the following to config/initializers/webpacker_compile_once.rb. It will patch Webpacker, but only for the test...
These methods are available to you: page.driver.browser.switch_to.alert.accept page.driver.browser.switch_to.alert.dismiss page.driver.browser.switch_to.alert.text # the confirmation text Spreewald gives you steps like these: