2023-06-02 - Testing Rails


main topics

Important

In order to run System Tests the Chrome path MUST be /usr/bin/google-chrome.


Versão em portugues

2:18 - iniciando applicação

16:00 - Inicia a parte de testes

35:00 - fixtures (works like a seed)

42:30 - fixtures accept erb syntax

44:30 - using TDD

58:50 - unit tests

1:05:10 - Travis CI

parei no 1:14:00


English Lecture

Boilerplate code

test/test_helper.rb

class ActiveSupport
  # ...
  # Devise test helpers
  include Warden::Test::Helpers
  Warden.test_mode!
end

Capybara.save_path = Rails.root.join("tmp/capybara")

config/environments/test.rb

# ...
Rails.application.configure do
  # ...
  config.action_dispatch.show_exceptions = true
end

Headless Chrome

test/application_system_test_case.rb

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
-  driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
+  driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
end

4 phases of testing

  1. setup
  2. exercise
  3. verify
  4. teardown

System Testing

In Rails terminology System Test is a test that uses browser.
Sometimes it's called End-to-End testing.

System Testing is resource hungry, use it only for core user journeys. Don't use System Testing for every little feature.

Capybara Actions

Useful link: https://github.com/teamcapybara/capybara#the-dsl

Formal reference: https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Actions