-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathspec_helper.rb
More file actions
97 lines (85 loc) · 2.75 KB
/
spec_helper.rb
File metadata and controls
97 lines (85 loc) · 2.75 KB
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
97
ENV["RAILS_ENV"] ||= 'test'
require 'opal'
require 'opal-jquery'
begin
require File.expand_path('../test_app/config/environment', __FILE__)
rescue LoadError
puts 'Could not load test application. Please ensure you have run `bundle exec rake test_app`'
end
require 'rspec/rails'
require 'hyper-spec'
require 'pry'
require 'timecop'
RSpec.configure do |config|
config.color = true
config.fail_fast = ENV['FAIL_FAST'] || false
config.fixture_paths = [File.join(File.expand_path(File.dirname(__FILE__)), "fixtures")]
config.infer_spec_type_from_file_location!
config.mock_with :rspec
config.raise_errors_for_deprecations!
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
config.before :each do
Rails.cache.clear
end
config.before :suite do
if defined?(MiniRacer)
MiniRacer_Backup = MiniRacer
Object.send(:remove_const, :MiniRacer)
end
end
config.around(:each, :prerendering_on) do |example|
if defined?(MiniRacer_Backup)
MiniRacer = MiniRacer_Backup
example.run
Object.send(:remove_const, :MiniRacer)
else
skip 'mini_racer not available; skipping prerendering test'
end
end
config.filter_run_including focus: true
config.filter_run_excluding opal: true
config.run_all_when_everything_filtered = true
# Fail tests on JavaScript errors in Chrome Headless
class JavaScriptError < StandardError; end
config.after(:each, js: true) do
logs = page.driver.browser.logs.get(:browser)
errors = logs.select { |e| e.level == "SEVERE" && e.message.present? }
.map { |m| m.message.gsub(/\\n/, "\n") }.to_a
if client_options[:deprecation_warnings] == :on
warnings = logs.select { |e| e.level == "WARNING" && e.message.present? }
.map { |m| m.message.gsub(/\\n/, "\n") }.to_a
puts "\033[0;33;1m\nJavascript client console warnings:\n\n" + warnings.join("\n\n") + "\033[0;30;21m" if warnings.present?
end
unless client_options[:raise_on_js_errors] == :off
raise JavaScriptError, errors.join("\n\n") if errors.present?
end
end
HyperSpec::Helpers.alias_method :on_client, :before_mount
end
# Stubbing the React calls so we can test outside of Opal
# module React
# class State
# class << self
# def reset!
# @states = nil
# end
#
# def get_state(from, key)
# states[from] ||= {}
# states[from][key.to_s]
# end
#
# def set_state(from, key, value)
# states[from] ||= {}
# states[from][key.to_s] = value
# end
#
# def states
# @states ||= {}
# end
# end
# end
# end