/
dsl_spec.rb
85 lines (71 loc) · 2.33 KB
/
dsl_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
require 'spec_helper'
require 'rspec/support/spec/in_sub_process'
main = self
RSpec.describe "The RSpec DSL" do
include RSpec::Support::InSubProcess
shared_examples_for "dsl methods" do |*method_names|
context "when expose_dsl_globally is enabled" do
def enable
in_sub_process do
changing_expose_dsl_globally do
RSpec.configuration.expose_dsl_globally = true
expect(RSpec.configuration.expose_dsl_globally?).to eq true
end
yield
end
end
it 'makes them only available off of `RSpec`, `main` and modules' do
enable do
expect(::RSpec).to respond_to(*method_names)
expect(main).to respond_to(*method_names)
expect(Module.new).to respond_to(*method_names)
expect(Object.new).not_to respond_to(*method_names)
end
end
end
context "when expose_dsl_globally is disabled" do
def disable
in_sub_process do
changing_expose_dsl_globally do
RSpec.configuration.expose_dsl_globally = false
expect(RSpec.configuration.expose_dsl_globally?).to eq false
end
yield
end
end
it 'makes them only available off of `RSpec`' do
disable do
expect(::RSpec).to respond_to(*method_names)
expect(main).not_to respond_to(*method_names)
expect(Module.new).not_to respond_to(*method_names)
expect(Object.new).not_to respond_to(*method_names)
end
end
end
end
describe "built in DSL methods" do
include_examples "dsl methods", :describe, :context, :shared_examples, :shared_examples_for, :shared_context do
def changing_expose_dsl_globally
yield
end
end
end
describe "custom example group aliases" do
context "when adding aliases before exposing the DSL globally" do
include_examples "dsl methods", :detail do
def changing_expose_dsl_globally
RSpec.configuration.alias_example_group_to(:detail)
yield
end
end
end
context "when adding aliases after exposing the DSL globally" do
include_examples "dsl methods", :detail do
def changing_expose_dsl_globally
yield
RSpec.configuration.alias_example_group_to(:detail)
end
end
end
end
end