/
configuration_spec.rb
220 lines (166 loc) · 6.78 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
require 'spec_helper'
describe Rspec::Core::Configuration do
context "setting the mock framework" do
it "requires and includes the rspec adapter when the mock_framework is :rspec" do
config = Rspec::Core::Configuration.new
config.should_receive(:require).with('rspec/core/mocking/with_rspec')
Rspec::Core::ExampleGroup.should_receive(:send)
config.mock_framework = :rspec
end
it "supports mock_with for backward compatibility with rspec-1.x" do
config = Rspec::Core::Configuration.new
config.stub!(:require)
Rspec::Core::ExampleGroup.stub!(:send)
config.mock_with :rspec
end
it "includes the null adapter when the mock_framework is not :rspec, :mocha, or :rr" do
config = Rspec::Core::Configuration.new
Rspec::Core::ExampleGroup.should_receive(:send).with(:include, Rspec::Core::Mocking::WithAbsolutelyNothing)
config.mock_framework = :crazy_new_mocking_framework_ive_not_yet_heard_of
end
pending "includes the rspec adapter when the mock_framework is not set" do
config = Rspec::Core::Configuration.new
Rspec::Core::ExampleGroup.stub!(:send)
config.mock_framework.should == :rspec
end
end
context "setting the files to run" do
before do
@config = Rspec::Core::Configuration.new
end
it "should load files not following pattern if named explicitly" do
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_bar.rb")
@config.files_or_directories_to_run = file
@config.files_to_run.should include(file)
end
describe "with default --pattern" do
it "should load files named _spec.rb" do
dir = File.expand_path(File.dirname(__FILE__) + "/resources/")
@config.files_or_directories_to_run = dir
@config.files_to_run.should == ["#{dir}/a_spec.rb"]
end
end
describe "with explicit pattern (single)" do
before do
@config.filename_pattern = "**/*_foo.rb"
end
it "should load files following pattern" do
file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
@config.files_or_directories_to_run = file
@config.files_to_run.should include(file)
end
it "should load files in directories following pattern" do
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
@config.files_or_directories_to_run = dir
@config.files_to_run.should include("#{dir}/a_foo.rb")
end
it "should not load files in directories not following pattern" do
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
@config.files_or_directories_to_run = dir
@config.files_to_run.should_not include("#{dir}/a_bar.rb")
end
end
context "with explicit pattern (comma,separated,values)" do
before do
@config.filename_pattern = "**/*_foo.rb,**/*_bar.rb"
end
it "should support comma separated values" do
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
@config.files_or_directories_to_run = dir
@config.files_to_run.should include("#{dir}/a_foo.rb")
@config.files_to_run.should include("#{dir}/a_bar.rb")
end
it "should support comma separated values with spaces" do
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
@config.files_or_directories_to_run = dir
@config.files_to_run.should include("#{dir}/a_foo.rb")
@config.files_to_run.should include("#{dir}/a_bar.rb")
end
end
context "with line number" do
it "assigns the line number as the filter" do
@config.files_or_directories_to_run = "path/to/a_spec.rb:37"
@config.filter.should == {:line_number => 37}
end
end
context "with full_description" do
it "assigns the example name as the filter on description" do
@config.full_description = "foo"
@config.filter.should == {:full_description => /foo/}
end
end
end
describe "include" do
module InstanceLevelMethods
def you_call_this_a_blt?
"egad man, where's the mayo?!?!?"
end
end
it "should include the given module into each matching example group" do
Rspec::Core.configuration.include(InstanceLevelMethods, :magic_key => :include)
group = Rspec::Core::ExampleGroup.create('does like, stuff and junk', :magic_key => :include) { }
group.should_not respond_to(:you_call_this_a_blt?)
group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
end
end
describe "extend" do
module ThatThingISentYou
def that_thing
end
end
it "should extend the given module into each matching example group" do
Rspec::Core.configuration.extend(ThatThingISentYou, :magic_key => :extend)
group = Rspec::Core::ExampleGroup.create(ThatThingISentYou, :magic_key => :extend) { }
group.should respond_to(:that_thing)
end
end
describe "run_all_when_everything_filtered" do
it "defaults to false" do
Rspec::Core::Configuration.new.run_all_when_everything_filtered.should == false
end
it "can be queried with question method" do
config = Rspec::Core::Configuration.new
config.run_all_when_everything_filtered = true
config.run_all_when_everything_filtered?.should == true
end
end
describe 'formatter=' do
it "sets formatter_to_use based on name" do
config = Rspec::Core::Configuration.new
config.formatter = :documentation
config.formatter.should be_an_instance_of(Rspec::Core::Formatters::DocumentationFormatter)
config.formatter = 'documentation'
config.formatter.should be_an_instance_of(Rspec::Core::Formatters::DocumentationFormatter)
end
it "raises ArgumentError if formatter is unknown" do
config = Rspec::Core::Configuration.new
lambda { config.formatter = :progresss }.should raise_error(ArgumentError)
end
end
describe "line_number=" do
it "sets the line number" do
config = Rspec::Core::Configuration.new
config.line_number = '37'
config.filter.should == {:line_number => 37}
end
it "overrides :focused" do
config = Rspec::Core::Configuration.new
config.filter_run :focused => true
config.line_number = '37'
config.filter.should == {:line_number => 37}
end
it "prevents :focused" do
config = Rspec::Core::Configuration.new
config.line_number = '37'
config.filter_run :focused => true
config.filter.should == {:line_number => 37}
end
end
describe "full_backtrace=" do
it "clears the backtrace clean patterns" do
config = Rspec::Core::Configuration.new
config.full_backtrace = true
config.options[:backtrace_clean_patterns].should == []
end
end
end