Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails System Test on Docker

Rails System Test on Docker

TokyuRuby会議11 発表資料

https://tokyurubykaigi.github.io/tokyu11/

Fumiaki MATSUSHIMA

July 29, 2017
Tweet

More Decks by Fumiaki MATSUSHIMA

Other Decks in Programming

Transcript

  1. require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome,

    screen_size: [1400, 1400] end require "application_system_test_case" class PostsTest < ApplicationSystemTestCase test "visiting the index" do visit posts_url assert_selector "h1", text: "Post" end end
  2. require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome,

    screen_size: [1400, 1400] end require "application_system_test_case" class PostsTest < ApplicationSystemTestCase test "visiting the index" do visit posts_url assert_selector "h1", text: "Post" end end
  3. version: '2' services: web: build: . environment: - DATABASE_URL=postgres://postgres:@db -

    PORT=3000 - HOST=0.0.0.0 tty: true stdin_open: true ports: - 3000:3000 depends_on: - db - chrome volumes: - .:/app chrome: image: selenium/standalone-chrome-debug ports: - 5900:5900 db: image: postgres:9.5.4
  4. require "test_helper" require "socket" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium,

    using: :chrome, screen_size: [1400, 1400], options: {url:"http://chrome:4444/wd/hub"} def setup host! "http://#{IPSocket.getaddress(Socket.gethostname)}" super end end
  5. require "test_helper" require "socket" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium,

    using: :chrome, screen_size: [1400, 1400], options: {url:"http://chrome:4444/wd/hub"} def setup host! "http://#{IPSocket.getaddress(Socket.gethostname)}" super end end
  6. require "test_helper" require "socket" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium,

    using: :chrome, screen_size: [1400, 1400], options: {url:"http://chrome:4444/wd/hub"} def setup host! "http://#{IPSocket.getaddress(Socket.gethostname)}" super end end
  7. 100.times do |i| test "visiting the index #{i}" do visit

    posts_url assert_selector "h1", text: "Post" end end ブラウザ 時間 Chrome 25.269699s Headless Chrome 16.881625s PhantomJS 12.243397s https://github.com/mtsmfm/rails-system-test-example/pull/2
  8. まとめ - Docker を使うとホストに いれるものが減る - ヘッドレスっぽくありつつも VNC で入れて便利 -

    とはいえ --headlessの方が速い - どっちにしろ Docker で動かせる - CI だと --headless にするといい? - 作り始めるときは Docker 上で