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
|
# File 'lib/volt/spec/setup.rb', line 5
def spec_setup(app_path = '.')
require 'volt'
ENV['SERVER'] = 'true'
ENV['VOLT_ENV'] = 'test'
require 'volt/boot'
volt_app = Volt.boot(app_path)
unless RUBY_PLATFORM == 'opal'
begin
require 'volt/spec/capybara'
setup_capybara(app_path, volt_app)
rescue LoadError => e
Volt.logger.warn("unable to load capybara, if you wish to use it for tests, be sure it is in the app's Gemfile")
Volt.logger.error(e)
end
end
unless ENV['BROWSER']
RSpec.configuration.filter_run_excluding type: :feature
end
cleanup_db = -> do
volt_app.database.drop_database
volt_app.page.instance_variable_set('@store', nil)
volt_app.reset_query_pool!
end
if RUBY_PLATFORM != 'opal'
cleanup_db.call
end
Thread.current['volt_app'] = volt_app
RSpec.shared_context 'volt collections', {} do
let(:the_page) { Model.new }
let(:store) do
@__store_accessed = true
$page ||= volt_app.page
$page.store
end
let(:volt_app) { volt_app }
let(:params) { volt_app.page.params }
after do
url = volt_app.page.url
if url.instance_variable_get('@params')
url.instance_variable_set('@params', nil)
end
end
if RUBY_PLATFORM != 'opal'
after do |example|
if @__store_accessed || example.metadata[:type] == :feature
cleanup_db.call
end
end
before(:example, {type: :feature}) do
@__store_accessed = true
end
end
end
end
|