Add first sign in feature specs

This sets up capybara with the new headless chrome driver and adds the
necessary requires in order to run single spec file. So far, there was
no other way than doing `bundle exec rake` due to missing requires.
This commit is contained in:
Pau Perez
2017-07-29 13:47:39 +02:00
committed by Jorge Morante
parent 881b531b8f
commit 390cc4cae4
4 changed files with 67 additions and 0 deletions

View File

@ -60,6 +60,9 @@ group :test do
gem 'shoulda', ">= 3.5"
gem 'fabrication'
gem 'faker'
gem 'capybara', '~> 2.4.4'
gem 'capybara-selenium', '~> 0.0.6'
gem 'chromedriver-helper', '~> 1.0'
end
group :production do

View File

@ -53,6 +53,8 @@ GEM
sshkit (>= 1.6.1, != 1.7.0)
arbre (1.1.1)
activesupport (>= 3.0.0)
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (6.0.4)
ast (2.4.0)
autoprefixer-rails (6.3.1)
@ -90,6 +92,14 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara-selenium (0.0.6)
capybara
selenium-webdriver
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chromedriver-helper (1.2.0)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
chronic (0.10.2)
coderay (1.1.2)
coffee-rails (4.1.0)
@ -138,6 +148,7 @@ GEM
i18n (~> 0.5)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.23)
formtastic (3.1.5)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
@ -160,6 +171,7 @@ GEM
has_scope (~> 0.6)
railties (>= 4.2, <= 5.2)
responders
io-like (0.3.0)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
@ -303,6 +315,7 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
rubyzip (1.2.1)
sass (3.4.21)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
@ -312,6 +325,9 @@ GEM
tilt (>= 1.1, < 3)
select2-rails (4.0.1)
thor (~> 0.14)
selenium-webdriver (3.11.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
@ -376,6 +392,8 @@ DEPENDENCIES
capistrano-rails (~> 1.1)
capistrano-rbenv (~> 2.1)
capybara (~> 2.4.4)
capybara-selenium (~> 0.0.6)
chromedriver-helper (~> 1.0)
coffee-rails
dalli
database_cleaner (= 1.3.0)

View File

@ -0,0 +1,29 @@
require 'spec_helper'
describe 'sign in' do
let!(:user) do
Fabricate(:user, email: 'user@timeoverflow.org', password: 'papapa22')
end
context 'with a valid password' do
it 'signs the user in' do
visit '/login'
fill_in 'user_email', with: user.email
fill_in 'user_password', with: 'papapa22'
click_button I18n.t('application.login_form.button')
expect(page).to have_content(I18n.t('application.navbar.sign_out'))
end
end
context 'with an invalid password' do
it 'shows an error' do
visit '/login'
fill_in 'user_email', with: user.email
fill_in 'user_password', with: 'wrong_password'
click_button I18n.t('application.login_form.button')
expect(page).to have_content(I18n.t('devise.failure.invalid'))
end
end
end

View File

@ -7,9 +7,26 @@ require 'rspec/rails'
require 'capybara/rails'
require 'database_cleaner'
require 'fabrication'
require 'selenium/webdriver'
require 'faker'
I18n.reload!
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.register_driver :headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless disable-gpu) }
)
Capybara::Selenium::Driver.new app,
browser: :chrome,
desired_capabilities: capabilities
end
Capybara.javascript_driver = :headless_chrome
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }