-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathrails_helper.rb
96 lines (81 loc) · 3.35 KB
/
rails_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'pundit/rspec'
require 'selenium/webdriver'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_base_class_for_anonymous_controllers = false
config.include FactoryBot::Syntax::Methods
config.include ActiveSupport::Testing::TimeHelpers
# DB cleaning
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
init_mock_omniauth
DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.before(:all) do
FactoryBot.reload
end
config.after(:each, js: true) do |example|
if example.exception
save_timestamped_screenshot(Capybara.page)
end
end
config.around(:each, caching: true) do |example|
Rails.configuration.action_controller.perform_caching = true
example.run
Rails.configuration.action_controller.perform_caching = false
end
end
Capybara.register_driver :chrome do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--window-size=1280,1024'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
Capybara.register_driver :headless_chrome do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
browser_options.args << '--window-size=1280,1024'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
Capybara.javascript_driver = ENV['CHROME'] ? :chrome : :headless_chrome
def save_timestamped_screenshot(page)
timestamp = Time.zone.now.strftime("%Y_%m_%d-%H_%M_%S")
filename = "#{method_name}-#{timestamp}.png"
screenshot_path = Rails.root.join("tmp", "screenshots", filename)
page.save_screenshot(screenshot_path)
end
Capybara.default_max_wait_time = 3.seconds