-
-
Notifications
You must be signed in to change notification settings - Fork 633
/
Copy pathconfiguration_spec.rb
151 lines (129 loc) · 4.71 KB
/
configuration_spec.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# frozen_string_literal: true
require_relative "spec_helper"
module ReactOnRails
RSpec.describe Configuration do
let(:existing_path) { Pathname.new(Dir.mktmpdir) }
let(:not_existing_path) { "/path/to/#{SecureRandom.hex(4)}" }
let(:using_webpacker) { false }
after do
ReactOnRails.instance_variable_set(:@configuration, nil)
end
before do
allow(ReactOnRails::WebpackerUtils).to receive(:using_webpacker?).and_return(using_webpacker)
end
unless using_rails32?
describe "generated_assets_dir" do
let(:using_webpacker) { true }
let(:webpacker_public_output_path) do
File.expand_path(File.join(Rails.root, "public/webpack/dev"))
end
before do
allow(Rails).to receive(:root).and_return(File.expand_path("."))
allow(Webpacker).to receive_message_chain("config.public_output_path")
.and_return(webpacker_public_output_path)
end
it "does not throw if the generated assets dir is blank with webpacker" do
expect do
ReactOnRails.configure do |config|
config.generated_assets_dir = ""
end
end.not_to raise_error
end
it "does not throw if the webpacker_public_output_path does match the generated assets dir" do
expect do
ReactOnRails.configure do |config|
config.generated_assets_dir = "public/webpack/dev"
end
end.not_to raise_error
end
it "does throw if the webpacker_public_output_path does not match the generated assets dir" do
expect do
ReactOnRails.configure do |config|
config.generated_assets_dir = "public/webpack/other"
end
end.to raise_error(ReactOnRails::Error, /does not match the value for public_output_path/)
end
end
end
describe ".server_render_method" do
it "does not throw if the server render method is blank" do
expect do
ReactOnRails.configure do |config|
config.server_render_method = ""
end
end.not_to raise_error
end
it "throws if the server render method is node" do
expect do
ReactOnRails.configure do |config|
config.server_render_method = "node"
end
end.to raise_error(ReactOnRails::Error, /invalid value for `config.server_render_method`/)
end
end
describe ".i18n_dir" do
let(:i18n_dir) { existing_path }
it "passes if directory exists" do
expect do
ReactOnRails.configure do |config|
config.i18n_dir = i18n_dir
end
end.not_to raise_error
end
it "fails with empty string value" do
expect do
ReactOnRails.configure do |config|
config.i18n_dir = ""
end
end.to raise_error(ReactOnRails::Error, /invalid value for `config\.i18n_dir`/)
end
it "fails with not existing directory" do
expect do
ReactOnRails.configure do |config|
config.i18n_dir = not_existing_path
end
end.to raise_error(ReactOnRails::Error, /invalid value for `config\.i18n_dir`/)
end
end
describe ".i18n_yml_dir" do
let(:i18n_yml_dir) { existing_path }
it "passes if directory exists" do
expect do
ReactOnRails.configure do |config|
config.i18n_yml_dir = i18n_yml_dir
end
end.not_to raise_error
end
it "fails with empty string value" do
expect do
ReactOnRails.configure do |config|
config.i18n_yml_dir = ""
end
end.to raise_error(ReactOnRails::Error, /invalid value for `config\.i18n_yml_dir`/)
end
it "fails with not existing directory" do
expect do
ReactOnRails.configure do |config|
config.i18n_yml_dir = not_existing_path
end
end.to raise_error(ReactOnRails::Error, /invalid value for `config\.i18n_yml_dir`/)
end
end
it "be able to config default configuration of the gem" do
ReactOnRails.configure do |config|
config.server_bundle_js_file = "server.js"
config.prerender = false
end
expect(ReactOnRails.configuration.server_bundle_js_file).to eq("server.js")
expect(ReactOnRails.configuration.prerender).to eq(false)
end
it "be able to config default configuration of the gem" do
ReactOnRails.configure do |config|
config.server_bundle_js_file = "something.js"
config.prerender = true
end
expect(ReactOnRails.configuration.server_bundle_js_file).to eq("something.js")
expect(ReactOnRails.configuration.prerender).to eq(true)
end
end
end