Capybara now works 🎉

This commit is contained in:
riggraz
2019-08-27 20:33:44 +02:00
parent cd79046071
commit b195274161
3 changed files with 54 additions and 13 deletions

View File

@@ -4,6 +4,10 @@ RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN npm install -g yarn
# Install Chrome (needed by Capybara). TODO: optional installation, only if development
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
RUN mkdir /app
WORKDIR /app

26
spec/support/capybara.rb Normal file
View File

@@ -0,0 +1,26 @@
# Setup chrome headless driver
Capybara.server = :puma, { Silent: true }
Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--window-size=1400,1400')
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.javascript_driver = :chrome_headless
# Setup rspec
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
driven_by :chrome_headless
end
end

View File

@@ -1,20 +1,31 @@
require 'rails_helper'
# RSpec.describe "Session", type: :system do
RSpec.describe 'Session', type: :system do
# def log_in_as(user)
let(:user) { FactoryBot.create(:user) }
before(:each) { user.confirm } # devise helper to confirm user email
it 'allows guests to sign in' do
user_count = User.count
visit new_user_registration_path
fill_in 'Full name', with: 'Test Test'
fill_in 'Email', with: 'test@test.com'
fill_in 'Password', with: 'password'
fill_in 'Password confirmation', with: 'password'
click_button 'Sign up'
expect(User.count).to eq(user_count + 1)
end
# it 'allows users to log in' do
# visit new_user_session_path
# fill_in "Email", with: "user0@example.com"
# fill_in "Password", with: "password"
# fill_in "Email", with: user.email
# fill_in "Password", with: user.password
# click_button "Log in"
# expect(current_path).to eq(root_path)
# end
# let(:user) { FactoryBot.create(:user) }
# it 'allows a logged-in user to view profile settings' do
# log_in_as user
# visit edit_user_registration_path
# expect(current_path).to eq(edit_user_registration_path)
# end
# end
end