Last active
May 22, 2017 15:02
-
-
Save tomazy/410a0610b55a457c66b14a95699d6998 to your computer and use it in GitHub Desktop.
Testing Rails app with Docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./docker-compose.yml | |
version: "3" | |
services: | |
app: | |
build: . | |
env_file: | |
- .env | |
ports: | |
- 3000:3000 # app | |
- 35729:35729 # live reload | |
links: | |
- postgres | |
volumes: | |
- app-sync:/app:nocopy | |
test: | |
build: . | |
env_file: | |
- .env.test | |
ports: | |
- 3005:3005 # Capybara listens here | |
links: | |
- postgres | |
- selenium | |
volumes: | |
- app-sync:/app:nocopy | |
command: bin/spring server | |
environment: | |
TEST_APP_HOST: test | |
TEST_APP_PORT: 3005 | |
SELENIUM_HOST: selenium | |
RAILS_ENV: test | |
networks: | |
default: | |
aliases: | |
- test | |
postgres: | |
image: postgres:9.4 | |
ports: | |
- 5432 | |
volumes: | |
- './postgres-data:/var/lib/postgresql/data' | |
selenium: | |
image: selenium/standalone-chrome-debug | |
ports: | |
- 5900:5900 | |
volumes: | |
app-sync: | |
external: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./spec/features/feature_helper.rb | |
# ... | |
SELENIUM_HOST = ENV['SELENIUM_HOST'] | |
TEST_APP_HOST = ENV['TEST_APP_HOST'] | |
TEST_APP_PORT = ENV['TEST_APP_PORT'] | |
Capybara.register_driver :selenium_remote do |app| | |
Capybara::Selenium::Driver.new( | |
app, | |
browser: :remote, | |
url: "http://#{SELENIUM_HOST}:4444/wd/hub", | |
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome | |
) | |
end | |
Capybara.javascript_driver = :selenium_remote | |
Capybara.server_port = TEST_APP_PORT | |
Capybara.server_host = '0.0.0.0' | |
Capybara.app_host = "http://#{TEST_APP_HOST}:#{TEST_APP_PORT}" | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment