Skip to content

Commit

Permalink
sets up rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieIGG committed Nov 13, 2019
1 parent 272e868 commit 6b982b5
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 117 deletions.
Binary file added .webdrivers/chromedriver
Binary file not shown.
1 change: 1 addition & 0 deletions .webdrivers/chromedriver.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
73.0.3683.68
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ end
group :development, :test do
gem "bullet"
gem "pry"
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem "factory_bot_rails"
gem "rspec-rails", "~> 3.8"
gem "ffaker"
Expand Down
21 changes: 21 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ GEM
bindex (0.8.1)
bootsnap (1.4.5)
msgpack (~> 1.0)
bootstrap (4.3.1)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0)
builder (3.2.3)
bullet (6.0.2)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
bundler-audit (0.6.1)
bundler (>= 1.2.0, < 3)
thor (~> 0.18)
byebug (11.0.1)
capybara (3.29.0)
addressable
mini_mime (>= 0.1.3)
Expand Down Expand Up @@ -133,6 +138,10 @@ GEM
i18n (1.7.0)
concurrent-ruby (~> 1.0)
jmespath (1.4.0)
jquery-rails (4.3.5)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.2.0)
kaminari (1.1.1)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -174,6 +183,7 @@ GEM
normalize-rails (4.1.1)
orm_adapter (0.5.0)
pg (1.1.4)
popper_js (1.14.5)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
Expand Down Expand Up @@ -261,6 +271,14 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sassc (2.2.1)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (3.142.6)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
Expand Down Expand Up @@ -329,13 +347,16 @@ DEPENDENCIES
autoprefixer-rails
aws-sdk-s3 (~> 1.9)
bootsnap (>= 1.4.2)
bootstrap (~> 4.3.1)
bullet
bundler-audit (>= 0.5.0)
byebug
capybara (>= 2.15)
devise
devise_invitable (~> 1.7.0)
factory_bot_rails
ffaker
jquery-rails
kaminari
listen (>= 3.0.5, < 3.2)
mini_magick
Expand Down
12 changes: 0 additions & 12 deletions spec/controllers/landing_controller_spec.rb

This file was deleted.

8 changes: 5 additions & 3 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

FactoryBot.define do
factory :user do
sequence(:email) { |n| "test_user#{n}@mail.com" }
password { "12345678"}
password_confirmation { "12345678" }
sequence (:email) { |n| "#{n}_#{FFaker::Internet.email}" }
password { '12345678' }
password_confirmation { '12345678' }
created_at { Date.today }
end
end
51 changes: 0 additions & 51 deletions spec/features/user_spec.rb

This file was deleted.

6 changes: 4 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# frozen_string_literal: true

# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'

require File.expand_path('../config/environment', __dir__)

# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'
require 'simplecov_helper'
# require 'simplecov_helper'
# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
Expand Down
101 changes: 52 additions & 49 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# frozen_string_literal: true

require 'capybara/rails'
require 'capybara/rspec'

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down Expand Up @@ -44,53 +49,51 @@
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus`
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
config.filter_run_when_matching :focus
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = "doc"
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# # This allows you to limit a spec run to individual examples or groups
# # you care about by tagging them with `:focus` metadata. When nothing
# # is tagged with `:focus`, all examples get run. RSpec also provides
# # aliases for `it`, `describe`, and `context` that include `:focus`
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
# config.filter_run_when_matching :focus
#
# # Allows RSpec to persist some state between runs in order to support
# # the `--only-failures` and `--next-failure` CLI options. We recommend
# # you configure your source control system to ignore this file.
# config.example_status_persistence_file_path = "spec/examples.txt"
#
# # Limits the available syntax to the non-monkey patched syntax that is
# # recommended. For more details, see:
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
# config.disable_monkey_patching!
#
# # Many RSpec users commonly either run the entire suite or an individual
# # file, and it's useful to allow more verbose output when running an
# # individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = "doc"
# end
#
# # Print the 10 slowest examples and example groups at the
# # end of the spec run, to help surface which specs are running
# # particularly slow.
# config.profile_examples = 10
#
# # Run specs in random order to surface order dependencies. If you find an
# # order dependency and want to debug it, you can fix the order by providing
# # the seed, which is printed after each run.
# # --seed 1234
# config.order = :random
#
# # Seed global randomization in this process using the `--seed` CLI option.
# # Setting this allows you to use `--seed` to deterministically reproduce
# # test failures related to randomization by passing the same `--seed` value
# # as the one that triggered the failure.
# Kernel.srand config.seed
end
39 changes: 39 additions & 0 deletions spec/support/system_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'selenium/webdriver'

# The default 'chrome_headless' capybara driver lacks the 'no-sandbox'
# option, and crashes when run inside the development container:
Capybara.server = :puma, { Silent: true }

Capybara.register_driver :chrome_headless do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 100
client.open_timeout = 100

chrome_options = %w[
headless disable-gpu no-sandbox disable-dev-shm-usage window-size=1400,1400
]
chrome_binary = '/usr/bin/chromium'

options = Selenium::WebDriver::Chrome::Options.new args: chrome_options,
binary: chrome_binary

Capybara::Selenium::Driver.new app,
browser: :chrome,
options: options,
http_client: client
end

RSpec.configure do |config|
# For "normal" system tests (i.e. no javascript UI, etc) use the :rack_test
# driver:
config.before :each, type: :system do
driven_by :rack_test
end

# For system tests involving javascript use the :chrome_headless driver:
config.before :each, type: :system, js: true do
driven_by :chrome_headless
end
end
27 changes: 27 additions & 0 deletions spec/system/session_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

RSpec.feature 'Login', type: :system do
context 'log in' do
scenario 'should be succesful' do
user = FactoryBot.create(:user)
visit new_user_session_path
within('form') do
fill_in 'Email', with: user.email
fill_in 'Password', with: '12345678'
click_on('Log in')
end
expect(current_path).to eq root_path
end

scenario 'should fail' do
user = FactoryBot.create(:user)
visit new_user_session_path
within('form') do
fill_in 'Email', with: user.email
fill_in 'Password', with: '12345679'
click_on('Log in')
end
expect(page).to have_content('Log in')
end
end
end

0 comments on commit 6b982b5

Please sign in to comment.