global 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Global, 'generate js in Rails' do
6
- before do
7
- evaljs('var window = this;', true)
8
- jscontext[:log] = ->(_context, value) { puts value.inspect }
9
-
10
- described_class.configure do |config|
11
- config.environment = 'test'
12
- config.config_directory = File.join(Dir.pwd, 'spec/files')
13
- end
14
-
15
- end
16
-
17
- context 'simple generate' do
18
- before do
19
- described_class.configure do |config|
20
- config.namespace = 'Global'
21
- config.except = :all
22
- config.only = :all
23
- end
24
- evaljs(described_class.generate_js)
25
- end
26
-
27
- it 'should generate valid global config' do
28
- expect(evaljs('Global.rspec_config.default_value')).to eq('default value')
29
- end
30
-
31
- it 'should generate valid global config for array' do
32
- expect(evaljs('Global.nested_config.some_array_value.length')).to eq(3)
33
- end
34
-
35
- it 'should generate valid global config for array, first element' do
36
- expect(evaljs('Global.nested_config.some_array_value[0]')).to eq('First')
37
- end
38
-
39
- it 'should generate valid global config for array, last element' do
40
- expect(evaljs('Global.nested_config.some_array_value[2]')).to eq('Third')
41
- end
42
-
43
- end
44
-
45
- context 'custom namespace' do
46
- before do
47
- described_class.configure do |config|
48
- config.namespace = 'CustomGlobal'
49
- config.except = :all
50
- config.only = :all
51
- end
52
- evaljs(described_class.generate_js)
53
- end
54
-
55
- it 'should generate valid global config' do
56
- expect(evaljs('CustomGlobal.rspec_config.default_value')).to eq('default value')
57
- end
58
-
59
- end
60
-
61
- context 'custom namespace from function' do
62
- before do
63
- evaljs(described_class.generate_js(namespace: 'CustomGlobalNamespace', only: :all))
64
- end
65
-
66
- it 'should generate valid global config' do
67
- expect(evaljs('CustomGlobalNamespace.rspec_config.default_value')).to eq('default value')
68
- end
69
-
70
- end
71
-
72
- context 'only select' do
73
- before do
74
- described_class.configure do |config|
75
- config.namespace = 'Global'
76
- config.except = :all
77
- config.only = [:bool_config]
78
- end
79
-
80
- evaljs(described_class.generate_js)
81
- end
82
-
83
- it 'should generate visible global config' do
84
- expect(evaljs('Global.bool_config.works')).to eq(true)
85
- end
86
-
87
- it 'should have not some keys in js' do
88
- expect(evaljs('Global.nested_config')).to be_nil
89
- end
90
-
91
- end
92
-
93
- context 'except select' do
94
- before do
95
- described_class.configure do |config|
96
- config.namespace = 'Global'
97
- config.except = [:nested_config]
98
- config.only = []
99
- end
100
- evaljs(described_class.generate_js)
101
- end
102
-
103
- it 'should generate visible global config with bool_config' do
104
- expect(evaljs('Global.bool_config.works')).to eq(true)
105
- end
106
-
107
- it 'should generate visible global config with rspec_config' do
108
- expect(evaljs('Global.rspec_config.default_value')).to eq('default value')
109
- end
110
-
111
- it 'should have not some keys in js' do
112
- expect(evaljs('Global.nested_config')).to be_nil
113
- end
114
-
115
- end
116
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if defined?(JRUBY_VERSION)
4
- require 'rhino'
5
- JS_LIB_CLASS = Rhino
6
- else
7
- require 'v8'
8
- JS_LIB_CLASS = V8
9
- end
10
-
11
- module JavascriptHelper
12
-
13
- def evaljs(string, force = false)
14
- jscontext(force).eval(string)
15
- end
16
-
17
- private
18
-
19
- def jscontext(force = false)
20
- if force
21
- @jscontext = JS_LIB_CLASS::Context.new
22
- else
23
- @jscontext ||= JS_LIB_CLASS::Context.new
24
- end
25
- end
26
-
27
- end