Add feature spec support

This commit is contained in:
Petko Bordjukov 2018-11-11 00:06:20 +02:00
parent ec9f192128
commit 4049ad354b
7 changed files with 105 additions and 18 deletions

View File

@ -64,7 +64,7 @@ group :development do
gem 'guard-rspec' # Continuous testing with Guard gem 'guard-rspec' # Continuous testing with Guard
gem 'rails-erd' gem 'rails-erd'
gem 'pry-rails' gem 'pry-rails'
gem 'hirb' # gem 'hirb'
gem 'awesome_print' gem 'awesome_print'
gem 'quiet_assets' gem 'quiet_assets'
gem 'capistrano' gem 'capistrano'
@ -80,6 +80,13 @@ group :development, :test do
gem 'factory_girl_rails' gem 'factory_girl_rails'
gem 'faker' gem 'faker'
gem 'capybara' gem 'capybara'
gem 'selenium-webdriver'
gem 'byebug'
gem 'simplecov' gem 'simplecov'
gem 'i18n-tasks' gem 'i18n-tasks'
end end
group :test do
gem 'database_cleaner'
end

View File

@ -35,7 +35,8 @@ GEM
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.4.0) addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
airbrussh (1.1.1) airbrussh (1.1.1)
sshkit (>= 1.6.1, != 1.7.0) sshkit (>= 1.6.1, != 1.7.0)
arel (6.0.4) arel (6.0.4)
@ -58,6 +59,7 @@ GEM
bootswatch-rails (3.3.5) bootswatch-rails (3.3.5)
railties (>= 3.1) railties (>= 3.1)
builder (3.2.3) builder (3.2.3)
byebug (10.0.2)
capistrano (3.6.1) capistrano (3.6.1)
airbrussh (>= 1.0.0) airbrussh (>= 1.0.0)
capistrano-harrow capistrano-harrow
@ -74,19 +76,22 @@ GEM
capistrano3-puma (1.2.1) capistrano3-puma (1.2.1)
capistrano (~> 3.0) capistrano (~> 3.0)
puma (>= 2.6) puma (>= 2.6)
capybara (2.10.1) capybara (3.10.1)
addressable addressable
mime-types (>= 1.16) mini_mime (>= 0.1.3)
nokogiri (>= 1.3.3) nokogiri (~> 1.8)
rack (>= 1.0.0) rack (>= 1.6.0)
rack-test (>= 0.5.4) rack-test (>= 0.6.3)
xpath (~> 2.0) regexp_parser (~> 1.2)
xpath (~> 3.2)
carrierwave (0.11.2) carrierwave (0.11.2)
activemodel (>= 3.2.0) activemodel (>= 3.2.0)
activesupport (>= 3.2.0) activesupport (>= 3.2.0)
json (>= 1.7) json (>= 1.7)
mime-types (>= 1.16) mime-types (>= 1.16)
mimemagic (>= 0.3.0) mimemagic (>= 0.3.0)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
choice (0.2.0) choice (0.2.0)
chunky_png (1.3.8) chunky_png (1.3.8)
coderay (1.1.1) coderay (1.1.1)
@ -101,6 +106,7 @@ GEM
copy_carrierwave_file (1.3.0) copy_carrierwave_file (1.3.0)
carrierwave (>= 0.9) carrierwave (>= 0.9)
crass (1.0.4) crass (1.0.4)
database_cleaner (1.7.0)
debug_inspector (0.0.2) debug_inspector (0.0.2)
devise (4.2.0) devise (4.2.0)
bcrypt (~> 3.0) bcrypt (~> 3.0)
@ -109,7 +115,7 @@ GEM
responders responders
warden (~> 1.2.3) warden (~> 1.2.3)
devise-i18n (1.1.0) devise-i18n (1.1.0)
diff-lcs (1.2.5) diff-lcs (1.3)
docile (1.1.5) docile (1.1.5)
domain_name (0.5.20160826) domain_name (0.5.20160826)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
@ -152,7 +158,6 @@ GEM
guard-compat (~> 1.1) guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0) rspec (>= 2.99.0, < 4.0)
highline (1.7.8) highline (1.7.8)
hirb (0.7.3)
http-cookie (1.0.3) http-cookie (1.0.3)
domain_name (~> 0.5) domain_name (~> 0.5)
i18n (0.9.5) i18n (0.9.5)
@ -229,6 +234,7 @@ GEM
slop (~> 3.4) slop (~> 3.4)
pry-rails (0.3.4) pry-rails (0.3.4)
pry (>= 0.9.10) pry (>= 0.9.10)
public_suffix (3.0.3)
puma (3.10.0) puma (3.10.0)
quiet_assets (1.1.0) quiet_assets (1.1.0)
railties (>= 3.1, < 5.0) railties (>= 3.1, < 5.0)
@ -281,13 +287,13 @@ GEM
refile-mini_magick (0.2.0) refile-mini_magick (0.2.0)
mini_magick (~> 4.0) mini_magick (~> 4.0)
refile (~> 0.5) refile (~> 0.5)
regexp_parser (1.2.0)
responders (2.3.0) responders (2.3.0)
railties (>= 4.2.0, < 5.1) railties (>= 4.2.0, < 5.1)
rest-client (1.8.0) rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0) http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0) mime-types (>= 1.16, < 3.0)
netrc (~> 0.7) netrc (~> 0.7)
rmagick (2.16.0)
rqrcode (0.10.1) rqrcode (0.10.1)
chunky_png (~> 1.0) chunky_png (~> 1.0)
rspec (3.5.0) rspec (3.5.0)
@ -313,6 +319,7 @@ GEM
rspec-support (3.5.0) rspec-support (3.5.0)
ruby-graphviz (1.2.2) ruby-graphviz (1.2.2)
ruby_dep (1.5.0) ruby_dep (1.5.0)
rubyzip (1.2.2)
sass (3.4.22) sass (3.4.22)
sass-rails (5.0.6) sass-rails (5.0.6)
railties (>= 4.0.0, < 6) railties (>= 4.0.0, < 6)
@ -321,6 +328,9 @@ GEM
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
search_object (1.1.1) search_object (1.1.1)
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
shellany (0.0.1) shellany (0.0.1)
simple_form (3.3.1) simple_form (3.3.1)
actionpack (> 4, < 5.1) actionpack (> 4, < 5.1)
@ -377,8 +387,8 @@ GEM
unicode-display_width (1.1.1) unicode-display_width (1.1.1)
warden (1.2.6) warden (1.2.6)
rack (>= 1.0) rack (>= 1.0)
xpath (2.0.0) xpath (3.2.0)
nokogiri (~> 1.3) nokogiri (~> 1.8)
yaml_db (0.4.2) yaml_db (0.4.2)
rails (>= 3.0, < 5.1) rails (>= 3.0, < 5.1)
rake (>= 0.8.7) rake (>= 0.8.7)
@ -394,6 +404,7 @@ DEPENDENCIES
bootstrap-sass bootstrap-sass
bootstrap-sass-extras bootstrap-sass-extras
bootswatch-rails bootswatch-rails
byebug
capistrano capistrano
capistrano-rails capistrano-rails
capistrano3-puma capistrano3-puma
@ -401,6 +412,7 @@ DEPENDENCIES
carrierwave carrierwave
coffee-rails coffee-rails
copy_carrierwave_file copy_carrierwave_file
database_cleaner
devise devise
devise-i18n devise-i18n
factory_girl_rails factory_girl_rails
@ -409,11 +421,11 @@ DEPENDENCIES
font-awesome-sass font-awesome-sass
globalize globalize
guard-rspec guard-rspec
hirb
i18n-tasks i18n-tasks
jbuilder jbuilder
jquery-datatables-rails jquery-datatables-rails
jquery-rails jquery-rails
mini_magick
mini_racer mini_racer
morrisjs-rails morrisjs-rails
nested_form nested_form
@ -428,11 +440,11 @@ DEPENDENCIES
raphael-rails raphael-rails
refile refile
refile-mini_magick refile-mini_magick
rmagick
rqrcode rqrcode
rspec-rails rspec-rails
sass-rails sass-rails
search_object search_object
selenium-webdriver
simple_form simple_form
simplecov simplecov
slim-rails slim-rails

View File

@ -18,6 +18,7 @@ Rails.application.configure do
# Use localhost for default host # Use localhost for default host
config.action_mailer.default_url_options = {host: 'localhost:3000'} config.action_mailer.default_url_options = {host: 'localhost:3000'}
config.action_mailer.default_options = {from: 'no-reply@example.com'}
# Print deprecation notices to the Rails logger. # Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log config.active_support.deprecation = :log

View File

@ -33,6 +33,7 @@ Rails.application.configure do
# Use localhost for default host # Use localhost for default host
config.action_mailer.default_url_options = {host: 'localhost:3000'} config.action_mailer.default_url_options = {host: 'localhost:3000'}
config.action_mailer.default_options = {from: 'no-reply@example.com'}
# Randomize the order test cases are executed. # Randomize the order test cases are executed.
config.active_support.test_order = :random config.active_support.test_order = :random

View File

@ -1,5 +1,5 @@
require 'simplecov' # require 'simplecov'
SimpleCov.start 'rails' # SimpleCov.start 'rails'
# This file is copied to spec/ when you run 'rails generate rspec:install' # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test' ENV["RAILS_ENV"] ||= 'test'
@ -15,6 +15,7 @@ require 'rspec/rails'
# end with _spec.rb. You can configure this pattern with the --pattern # end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/support/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run. # Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line. # If you are not using ActiveRecord, you can remove this line.
@ -27,7 +28,7 @@ RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your # If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false # examples within a transaction, remove the following line or assign false
# instead of true. # instead of true.
config.use_transactional_fixtures = true #config.use_transactional_fixtures = true
# RSpec Rails can automatically mix in different behaviours to your tests # RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and # based on their file location, for example enabling you to call `get` and

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

@ -0,0 +1,19 @@
Capybara.default_max_wait_time = 5
Capybara.asset_host = 'http://localhost:3000'
Capybara.server = :puma, { Silent: true }
RSpec.configure do |config|
# config.before(:each, type: :feature, js: true) do
# driven_by :selenium, using: :headless_chrome, screen_size: [1920, 1080]
# end
end
RSpec.configure do |config|
config.alias_example_group_to :feature, capybara_feature: true, type: :feature
config.alias_example_group_to :xfeature, capybara_feature: true, type: :feature, skip: "Temporarily disabled with xfeature"
config.alias_example_group_to :ffeature, capybara_feature: true, type: :feature, focus: true
config.alias_example_to :scenario
config.alias_example_to :xscenario, skip: "Temporarily disabled with xscenario"
config.alias_example_to :fscenario, focus: true
end

View File

@ -0,0 +1,46 @@
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
if config.use_transactional_fixtures?
raise(<<-MSG)
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
(or set it to false) to prevent uncommitted transactions being used in
JavaScript-dependent specs.
During testing, the app-under-test that the browser driver connects to
uses a different database connection to the database connection used by
the spec. The app's database connection would not be able to access
uncommitted transaction data setup over the spec's database connection.
MSG
end
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, type: :feature) do
# :rack_test driver's Rack app under test shares database connection
# with the specs, so continue to use transaction strategy for speed.
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
if !driver_shares_db_connection_with_specs
# Driver is probably for an external browser with an app
# under test that does *not* share a database connection with the
# specs, so use truncation strategy.
DatabaseCleaner.strategy = :truncation
end
end
config.before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end
end