Skip to content
This repository
Newer
Older
100644 443 lines (380 sloc) 14.577 kb
bcb1dfa6 » dchelimsky
2010-05-16 change top-level module from Rspec to RSpec
1 module RSpec
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
2 module Core
480f4190 » dchelimsky
2011-11-07 rename ClassMethods/InstanceMethods to ExampleGroupMethods/ExampleMet…
3 # ExampleGroup and Example are the main structural elements of rspec-core.
4 # Consider this example:
5 #
6 # describe Thing do
7 # it "does something" do
8 # end
9 # end
10 #
11 # The object returned by `describe Thing` is a subclass of ExampleGroup.
12 # The object returned by `it "does something"` is an instance of Example,
13 # which serves as a wrapper for an instance of the ExampleGroup in which it
14 # is declared.
6cbbaa7a » spicycode
2009-07-02 Renamed spec/core/behaviour -> spec/core/example_group
15 class ExampleGroup
17782b0d » dchelimsky
2011-05-11 easier on the eyes
16 extend MetadataHashBuilder::WithDeprecationWarning
f882e74f » dchelimsky
2010-08-05 organize some files
17 extend Extensions::ModuleEvalWithArgs
480f4190 » dchelimsky
2011-11-07 rename ClassMethods/InstanceMethods to ExampleGroupMethods/ExampleMet…
18 extend Subject::ExampleGroupMethods
17782b0d » dchelimsky
2011-05-11 easier on the eyes
19 extend Hooks
20
21 include Extensions::InstanceEvalWithArgs
480f4190 » dchelimsky
2011-11-07 rename ClassMethods/InstanceMethods to ExampleGroupMethods/ExampleMet…
22 include Subject::ExampleMethods
9415f865 » dchelimsky
2010-04-26 add group.top_level_description
23 include Pending
17782b0d » dchelimsky
2011-05-11 easier on the eyes
24 include Let
e9f95561 » spicycode
2010-01-09 Initial metadata reorg, still needs cleanup
25
84cb5f2e » dchelimsky
2011-12-03 rdoc
26 # @private
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
27 def self.world
bcb1dfa6 » dchelimsky
2010-05-16 change top-level module from Rspec to RSpec
28 RSpec.world
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
29 end
30
84cb5f2e » dchelimsky
2011-12-03 rdoc
31 # @private
3b016d25 » dchelimsky
2010-11-06 Explicitly register an example group from describe()
32 def self.register
33 world.register(self)
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
34 end
e9f95561 » spicycode
2010-01-09 Initial metadata reorg, still needs cleanup
35
9415f865 » dchelimsky
2010-04-26 add group.top_level_description
36 class << self
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
37 # @private
9415f865 » dchelimsky
2010-04-26 add group.top_level_description
38 def self.delegate_to_metadata(*names)
39 names.each do |name|
40 define_method name do
41 metadata[:example_group][name]
42 end
43 end
44 end
45
5a2157b3 » dchelimsky
2011-11-07 use described_class instead of deprecated describes (but keep support…
46 delegate_to_metadata :description, :described_class, :file_path
9415f865 » dchelimsky
2010-04-26 add group.top_level_description
47 alias_method :display_name, :description
84cb5f2e » dchelimsky
2011-12-03 rdoc
48 # @private
5a2157b3 » dchelimsky
2011-11-07 use described_class instead of deprecated describes (but keep support…
49 alias_method :describes, :described_class
9415f865 » dchelimsky
2010-04-26 add group.top_level_description
50 end
51
84cb5f2e » dchelimsky
2011-12-03 rdoc
52 # @private
921a7445 » dchelimsky
2010-04-15 more refactoring
53 def self.define_example_method(name, extra_options={})
54 module_eval(<<-END_RUBY, __FILE__, __LINE__)
41d11e2d » myronmarston
2011-02-22 Add new treat_symbols_as_metadata_keys_with_true_values option.
55 def self.#{name}(desc=nil, *args, &block)
56 options = build_metadata_hash_from(args)
eb3d26eb » dchelimsky
2011-12-11 :pending => 'message' assigns message (defaults to 'No reason given' …
57 options.update(:pending => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block
921a7445 » dchelimsky
2010-04-15 more refactoring
58 options.update(#{extra_options.inspect})
bcb1dfa6 » dchelimsky
2010-05-16 change top-level module from Rspec to RSpec
59 examples << RSpec::Core::Example.new(self, desc, options, block)
9d044e13 » dchelimsky
2010-04-24 return the generated example (improved dogfood)
60 examples.last
921a7445 » dchelimsky
2010-04-15 more refactoring
61 end
62 END_RUBY
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
63 end
e9f95561 » spicycode
2010-01-09 Initial metadata reorg, still needs cleanup
64
921a7445 » dchelimsky
2010-04-15 more refactoring
65 define_example_method :example
763eaab0 » dchelimsky
2011-12-11 better messages for xit, xspecify, xexample
66 define_example_method :it
67 define_example_method :specify
68
69 define_example_method :focused, :focused => true, :focus => true
70 define_example_method :focus, :focused => true, :focus => true
71
72 define_example_method :pending, :pending => true
73 define_example_method :xexample, :pending => 'Temporarily disabled with xexample'
74 define_example_method :xit, :pending => 'Temporarily disabled with xit'
75 define_example_method :xspecify, :pending => 'Temporarily disabled with xspecify'
921a7445 » dchelimsky
2010-04-15 more refactoring
76
77 class << self
78 alias_method :alias_example_to, :define_example_method
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
79 end
80
84cb5f2e » dchelimsky
2011-12-03 rdoc
81 # @private
d57065d7 » dchelimsky
2011-03-27 Change config.for_groups_matching to shared_context
82 def self.define_nested_shared_group_method(new_name, report_label=nil)
7b0d232d » wincent
2010-07-18 Add alias_it_should_behave_like_to
83 module_eval(<<-END_RUBY, __FILE__, __LINE__)
84303616 » myronmarston
2010-08-01 Pass parameters given to #it_should_behave_like on to the shared exam…
84 def self.#{new_name}(name, *args, &customization_block)
3906559d » justinko
2010-08-02 Display line on which shared group was called when shared example fails.
85 group = describe("#{report_label || "it should behave like"} \#{name}") do
96ef2031 » dchelimsky
2011-11-15 changelog and cleanup for #503
86 find_and_eval_shared("examples", name, *args, &customization_block)
cc721462 » dchelimsky
2010-08-01 simpler block format for nested group generated when invoking a share…
87 end
3906559d » justinko
2010-08-02 Display line on which shared group was called when shared example fails.
88 group.metadata[:shared_group_name] = name
89 group
7b0d232d » wincent
2010-07-18 Add alias_it_should_behave_like_to
90 end
91 END_RUBY
92 end
93
d57065d7 » dchelimsky
2011-03-27 Change config.for_groups_matching to shared_context
94 define_nested_shared_group_method :it_should_behave_like
938ae089 » dchelimsky
2010-07-18 handle shared group methods like example methods
95
96 class << self
d57065d7 » dchelimsky
2011-03-27 Change config.for_groups_matching to shared_context
97 alias_method :alias_it_should_behave_like_to, :define_nested_shared_group_method
938ae089 » dchelimsky
2010-07-18 handle shared group methods like example methods
98 end
99
100 alias_it_should_behave_like_to :it_behaves_like, "behaves like"
101
9e9f8a4c » dchelimsky
2011-11-09 more README
102 # Includes shared content declared with `name`.
103 #
104 # @see SharedExampleGroup
386e3295 » cbascom
2011-11-14 Remove support for passing a block to include_[examples|context]
105 def self.include_context(name, *args)
96ef2031 » dchelimsky
2011-11-15 changelog and cleanup for #503
106 block_given? ? block_not_supported("context") : find_and_eval_shared("context", name, *args)
940f7feb » dchelimsky
2011-08-05 delegate shared content search to single method and align error messages
107 end
108
9e9f8a4c » dchelimsky
2011-11-09 more README
109 # Includes shared content declared with `name`.
110 #
111 # @see SharedExampleGroup
386e3295 » cbascom
2011-11-14 Remove support for passing a block to include_[examples|context]
112 def self.include_examples(name, *args)
96ef2031 » dchelimsky
2011-11-15 changelog and cleanup for #503
113 block_given? ? block_not_supported("examples") : find_and_eval_shared("examples", name, *args)
c78da6cd » cbascom
2011-11-13 Add support for passing parameters and a block to include_context as …
114 end
115
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
116 # @private
26802fb4 » cbascom
2011-11-14 Add a warning if a block is provided to include_[examples|context]
117 def self.block_not_supported(label)
118 warn("Customization blocks not supported for include_#{label}. Use it_behaves_like instead.")
119 end
120
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
121 # @private
96ef2031 » dchelimsky
2011-11-15 changelog and cleanup for #503
122 def self.find_and_eval_shared(label, name, *args, &customization_block)
123 raise ArgumentError, "Could not find shared #{label} #{name.inspect}" unless
124 shared_block = world.shared_example_groups[name]
c78da6cd » cbascom
2011-11-13 Add support for passing parameters and a block to include_context as …
125
71f69114 » cbascom
2011-11-13 Add support for passing parameters and a block through include_examples
126 module_eval_with_args(*args, &shared_block)
127 module_eval(&customization_block) if customization_block
940f7feb » dchelimsky
2011-08-05 delegate shared content search to single method and align error messages
128 end
129
84cb5f2e » dchelimsky
2011-12-03 rdoc
130 # @private
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
131 def self.examples
8c2317a3 » justinko
2011-10-20 Order filtered examples, rather than all the examples.
132 @examples ||= []
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
133 end
480f4190 » dchelimsky
2011-11-07 rename ClassMethods/InstanceMethods to ExampleGroupMethods/ExampleMet…
134
84cb5f2e » dchelimsky
2011-12-03 rdoc
135 # @private
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
136 def self.filtered_examples
ad928162 » justinko
2011-10-20 Extract ordering functionality to module used for extension.
137 world.filtered_examples[self]
4b4ff67a » dchelimsky
2010-05-06 Refactor example group hierarchy into a tree
138 end
139
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
140 # @private
fa42f5b7 » dchelimsky
2010-06-13 it's descendant, silly
141 def self.descendant_filtered_examples
8e550ad0 » dchelimsky
2010-10-12 Perf: get the right collection the first time
142 @descendant_filtered_examples ||= filtered_examples + children.inject([]){|l,c| l + c.descendant_filtered_examples}
5c655e19 » myronmarston
2010-09-25 Fix a bug with before/after(:all) hooks from unfiltered/excluded exam…
143 end
144
84cb5f2e » dchelimsky
2011-12-03 rdoc
145 # The [Metadata](Metadata) object associated with this group.
fc675751 » dchelimsky
2011-11-06 rdoc: hooks, configuration, and more
146 # @see Metadata
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
147 def self.metadata
d2cc5d05 » dchelimsky
2010-07-20 Eliminate some warnings
148 @metadata if defined?(@metadata)
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
149 end
150
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
151 # @private
fc675751 » dchelimsky
2011-11-06 rdoc: hooks, configuration, and more
152 # @return [Metadata] belonging to the parent of a nested [ExampleGroup](ExampleGroup)
11d053f2 » dchelimsky
2010-02-10 add ExampleGroup.create, which decouples creation of an ExampleGroup
153 def self.superclass_metadata
5dc9b185 » dchelimsky
2010-09-17 small optimizations
154 @superclass_metadata ||= self.superclass.respond_to?(:metadata) ? self.superclass.metadata : nil
11d053f2 » dchelimsky
2010-02-10 add ExampleGroup.create, which decouples creation of an ExampleGroup
155 end
156
7a72f38e » dchelimsky
2011-11-19 rdoc
157 # Generates a subclass of this example group which inherits
158 # everything except the examples themselves.
159 #
160 # ## Examples
161 #
162 # describe "something" do # << This describe method is defined in
163 # # << RSpec::Core::DSL, included in the
164 # # << global namespace
165 # before do
166 # do_something_before
167 # end
168 #
169 # let(:thing) { Thing.new }
170 #
171 # describe "attribute (of something)" do
172 # # examples in the group get the before hook
173 # # declared above, and can access `thing`
174 # end
175 # end
176 #
177 # @see DSL#describe
6b1ff00a » dchelimsky
2010-02-03 behaviour to example_group
178 def self.describe(*args, &example_group_block)
11d053f2 » dchelimsky
2010-02-10 add ExampleGroup.create, which decouples creation of an ExampleGroup
179 @_subclass_count ||= 0
180 @_subclass_count += 1
83637074 » dchelimsky
2010-04-23 Add specs to show after(:each) is run
181 args << {} unless args.last.is_a?(Hash)
182 args.last.update(:example_group_block => example_group_block)
4b4ff67a » dchelimsky
2010-05-06 Refactor example group hierarchy into a tree
183
184 # TODO 2010-05-05: Because we don't know if const_set is thread-safe
185 child = const_set(
0aca341a » dchelimsky
2010-04-02 shorten nested group names
186 "Nested_#{@_subclass_count}",
83637074 » dchelimsky
2010-04-23 Add specs to show after(:each) is run
187 subclass(self, args, &example_group_block)
11d053f2 » dchelimsky
2010-02-10 add ExampleGroup.create, which decouples creation of an ExampleGroup
188 )
4b4ff67a » dchelimsky
2010-05-06 Refactor example group hierarchy into a tree
189 children << child
190 child
191 end
192
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
193 class << self
194 alias_method :context, :describe
17a3b5ab » dchelimsky
2010-05-07 small refactorings
195 end
196
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
197 # @private
83637074 » dchelimsky
2010-04-23 Add specs to show after(:each) is run
198 def self.subclass(parent, args, &example_group_block)
199 subclass = Class.new(parent)
65bbb802 » dchelimsky
2010-07-18 Whitespace gone
200 subclass.set_it_up(*args)
83637074 » dchelimsky
2010-04-23 Add specs to show after(:each) is run
201 subclass.module_eval(&example_group_block) if example_group_block
202 subclass
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
203 end
204
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
205 # @private
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
206 def self.children
ad928162 » justinko
2011-10-20 Extract ordering functionality to module used for extension.
207 @children ||= [].extend(Extensions::Ordered)
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
208 end
209
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
210 # @private
fa42f5b7 » dchelimsky
2010-06-13 it's descendant, silly
211 def self.descendants
8e550ad0 » dchelimsky
2010-10-12 Perf: get the right collection the first time
212 @_descendants ||= [self] + children.inject([]) {|list, c| list + c.descendants}
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
213 end
214
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
215 # @private
cbfae9b3 » dchelimsky
2010-04-26 just use ancestors and ancestors.reverse
216 def self.ancestors
bcb1dfa6 » dchelimsky
2010-05-16 change top-level module from Rspec to RSpec
217 @_ancestors ||= super().select {|a| a < RSpec::Core::ExampleGroup}
ff4df6b3 » dchelimsky
2010-04-24 select from Ruby's ancestors instead of building up our own
218 end
219
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
220 # @private
46f430db » leshill
2010-07-18 Fix bug in which before/after(:all) hooks were running too often
221 def self.top_level?
9757c226 » dchelimsky
2010-09-19 cache top_level
222 @top_level ||= superclass == ExampleGroup
46f430db » leshill
2010-07-18 Fix bug in which before/after(:all) hooks were running too often
223 end
224
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
225 # @private
622a4b7a » myronmarston
2011-03-06 Fix how RSpec::Matchers is included in RSpec::Core::Example group to …
226 def self.ensure_example_groups_are_configured
2b2ef40e » dchelimsky
2011-03-08 Change class level instance var to class's class var so the block is
227 unless defined?(@@example_groups_configured)
622a4b7a » myronmarston
2011-03-06 Fix how RSpec::Matchers is included in RSpec::Core::Example group to …
228 RSpec.configuration.configure_mock_framework
229 RSpec.configuration.configure_expectation_framework
2b2ef40e » dchelimsky
2011-03-08 Change class level instance var to class's class var so the block is
230 @@example_groups_configured = true
622a4b7a » myronmarston
2011-03-06 Fix how RSpec::Matchers is included in RSpec::Core::Example group to …
231 end
232 end
233
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
234 # @private
b84371e0 » dchelimsky
2010-05-10 Move filtering examples to world, reducing feature envy
235 def self.set_it_up(*args)
622a4b7a » myronmarston
2011-03-06 Fix how RSpec::Matchers is included in RSpec::Core::Example group to …
236 # Ruby 1.9 has a bug that can lead to infinite recursion and a
237 # SystemStackError if you include a module in a superclass after
238 # including it in a subclass: https://gist.github.com/845896
239 # To prevent this, we must include any modules in RSpec::Core::ExampleGroup
240 # before users create example groups and have a chance to include
241 # the same module in a subclass of RSpec::Core::ExampleGroup.
242 # So we need to configure example groups here.
243 ensure_example_groups_are_configured
244
41d11e2d » myronmarston
2011-02-22 Add new treat_symbols_as_metadata_keys_with_true_values option.
245 symbol_description = args.shift if args.first.is_a?(Symbol)
246 args << build_metadata_hash_from(args)
247 args.unshift(symbol_description) if symbol_description
bcb1dfa6 » dchelimsky
2010-05-16 change top-level module from Rspec to RSpec
248 @metadata = RSpec::Core::Metadata.new(superclass_metadata).process(*args)
91cb8a6f » dchelimsky
2010-08-12 Include or extend each module immediately after processing
249 world.configure_group(self)
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
250 end
251
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
252 # @private
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
253 def self.before_all_ivars
254 @before_all_ivars ||= {}
255 end
256
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
257 # @private
0b747d18 » dchelimsky
2010-07-24 refactoring
258 def self.store_before_all_ivars(example_group_instance)
72c18910 » dchelimsky
2010-10-09 add a couple of perf guards
259 return if example_group_instance.instance_variables.empty?
480f4190 » dchelimsky
2011-11-07 rename ClassMethods/InstanceMethods to ExampleGroupMethods/ExampleMet…
260 example_group_instance.instance_variables.each { |ivar|
0b747d18 » dchelimsky
2010-07-24 refactoring
261 before_all_ivars[ivar] = example_group_instance.instance_variable_get(ivar)
262 }
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
263 end
e9f95561 » spicycode
2010-01-09 Initial metadata reorg, still needs cleanup
264
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
265 # @private
0b747d18 » dchelimsky
2010-07-24 refactoring
266 def self.assign_before_all_ivars(ivars, example_group_instance)
72c18910 » dchelimsky
2010-10-09 add a couple of perf guards
267 return if ivars.empty?
0b747d18 » dchelimsky
2010-07-24 refactoring
268 ivars.each { |ivar, val| example_group_instance.instance_variable_set(ivar, val) }
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
269 end
270
84cb5f2e » dchelimsky
2011-12-03 rdoc
271 # @private
c240059c » dchelimsky
2011-06-18 names
272 def self.run_before_all_hooks(example_group_instance)
8799cc2a » dchelimsky
2010-09-26 Flattent descendant_filtered_examples rather than adding a new method.
273 return if descendant_filtered_examples.empty?
0b747d18 » dchelimsky
2010-07-24 refactoring
274 assign_before_all_ivars(superclass.before_all_ivars, example_group_instance)
234e1b04 » myronmarston
2011-01-11 Allow filtered :all hooks to be applied to nested example groups.
275 world.run_hook_filtered(:before, :all, self, example_group_instance)
0b747d18 » dchelimsky
2010-07-24 refactoring
276 run_hook!(:before, :all, example_group_instance)
277 store_before_all_ivars(example_group_instance)
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
278 end
279
84cb5f2e » dchelimsky
2011-12-03 rdoc
280 # @private
c240059c » dchelimsky
2011-06-18 names
281 def self.run_around_each_hooks(example, initial_procsy)
c9604c2f » dchelimsky
2010-12-28 Fix hook filtering so global hooks can apply to individual examples.
282 example.around_hooks.reverse.inject(initial_procsy) do |procsy, around_hook|
33f49036 » dchelimsky
2011-01-26 Make Procsy a module and extend the generated Procs instead of
283 Example.procsy(procsy.metadata) do
c9604c2f » dchelimsky
2010-12-28 Fix hook filtering so global hooks can apply to individual examples.
284 example.example_group_instance.instance_eval_with_args(procsy, &around_hook)
b6a7897e » dchelimsky
2010-11-19 Expose example.metadata in around hooks
285 end
b1c2ab49 » benarmston
2010-07-08 Move around hook wrapping to ExampleGroup
286 end
287 end
288
84cb5f2e » dchelimsky
2011-12-03 rdoc
289 # @private
c240059c » dchelimsky
2011-06-18 names
290 def self.run_before_each_hooks(example)
c9604c2f » dchelimsky
2010-12-28 Fix hook filtering so global hooks can apply to individual examples.
291 world.run_hook_filtered(:before, :each, self, example.example_group_instance, example)
292 ancestors.reverse.each { |ancestor| ancestor.run_hook(:before, :each, example.example_group_instance) }
b1c2ab49 » benarmston
2010-07-08 Move around hook wrapping to ExampleGroup
293 end
294
84cb5f2e » dchelimsky
2011-12-03 rdoc
295 # @private
c240059c » dchelimsky
2011-06-18 names
296 def self.run_after_each_hooks(example)
c9604c2f » dchelimsky
2010-12-28 Fix hook filtering so global hooks can apply to individual examples.
297 ancestors.each { |ancestor| ancestor.run_hook(:after, :each, example.example_group_instance) }
298 world.run_hook_filtered(:after, :each, self, example.example_group_instance, example)
0b747d18 » dchelimsky
2010-07-24 refactoring
299 end
300
84cb5f2e » dchelimsky
2011-12-03 rdoc
301 # @private
c240059c » dchelimsky
2011-06-18 names
302 def self.run_after_all_hooks(example_group_instance)
8799cc2a » dchelimsky
2010-09-26 Flattent descendant_filtered_examples rather than adding a new method.
303 return if descendant_filtered_examples.empty?
0b747d18 » dchelimsky
2010-07-24 refactoring
304 assign_before_all_ivars(before_all_ivars, example_group_instance)
9e7dcd37 » myronmarston
2010-10-09 Rescue errors in after(:all) and print them out.
305
306 begin
307 run_hook!(:after, :all, example_group_instance)
308 rescue => e
309 # TODO: come up with a better solution for this.
310 RSpec.configuration.reporter.message <<-EOS
311
312 An error occurred in an after(:all) hook.
313 #{e.class}: #{e.message}
314 occurred at #{e.backtrace.first}
315
316 EOS
317 end
318
234e1b04 » myronmarston
2011-01-11 Allow filtered :all hooks to be applied to nested example groups.
319 world.run_hook_filtered(:after, :all, self, example_group_instance)
0b747d18 » dchelimsky
2010-07-24 refactoring
320 end
321
84cb5f2e » dchelimsky
2011-12-03 rdoc
322 # @private
c9604c2f » dchelimsky
2010-12-28 Fix hook filtering so global hooks can apply to individual examples.
323 def self.around_hooks_for(example)
324 world.find_hook(:around, :each, self, example) + ancestors.reverse.inject([]){|l,a| l + a.find_hook(:around, :each, self, example)}
21d6f6bc » dchelimsky
2010-04-17 make sure before/after(:all) gets run even in subclasses
325 end
326
7a72f38e » dchelimsky
2011-11-19 rdoc
327 # Runs all the examples in this group
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
328 def self.run(reporter)
6946d2d9 » dchelimsky
2010-09-11 Improved handling for CTRL-C (runs after(:suite))
329 if RSpec.wants_to_quit
330 RSpec.clear_remaining_example_groups if top_level?
331 return
332 end
f80e68a3 » dchelimsky
2010-07-21 Deprecate add_example_group in formatters
333 reporter.example_group_started(self)
b25fea33 » spicycode
2010-09-03 gh#21 Resolution, 1 remaining pending test
334
20389a49 » dchelimsky
2010-04-20 ensure the things that happen after the return val is set
335 begin
c240059c » dchelimsky
2011-06-18 names
336 run_before_all_hooks(new)
1012613a » dchelimsky
2010-11-14 object per example
337 result_for_this_group = run_examples(reporter)
ad928162 » justinko
2011-10-20 Extract ordering functionality to module used for extension.
338 results_for_descendants = children.ordered.map {|child| child.run(reporter)}.all?
d6964f74 » dchelimsky
2010-06-25 Ensure that child groups are run even when there are failures in parent
339 result_for_this_group && results_for_descendants
b25fea33 » spicycode
2010-09-03 gh#21 Resolution, 1 remaining pending test
340 rescue Exception => ex
cc5e20cf » spicycode
2010-09-06 gh#21 - Let's actually fail the examples fast this time around
341 fail_filtered_examples(ex, reporter)
20389a49 » dchelimsky
2010-04-20 ensure the things that happen after the return val is set
342 ensure
c240059c » dchelimsky
2011-06-18 names
343 run_after_all_hooks(new)
ff18091e » dchelimsky
2011-02-15 clear ivars declared before(:all) after a group is run
344 before_all_ivars.clear
4dc8bfb8 » iromeo
2010-09-02 Add example_group_finished message to reporter/formatters.
345 reporter.example_group_finished(self)
20389a49 » dchelimsky
2010-04-20 ensure the things that happen after the return val is set
346 end
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
347 end
e9f95561 » spicycode
2010-01-09 Initial metadata reorg, still needs cleanup
348
84cb5f2e » dchelimsky
2011-12-03 rdoc
349 # @private
7a72f38e » dchelimsky
2011-11-19 rdoc
350 def self.run_examples(reporter)
351 filtered_examples.ordered.map do |example|
352 next if RSpec.wants_to_quit
353 instance = new
354 set_ivars(instance, before_all_ivars)
355 succeeded = example.run(instance, reporter)
356 RSpec.wants_to_quit = true if fail_fast? && !succeeded
357 succeeded
358 end.all?
359 end
360
84cb5f2e » dchelimsky
2011-12-03 rdoc
361 # @private
cc5e20cf » spicycode
2010-09-06 gh#21 - Let's actually fail the examples fast this time around
362 def self.fail_filtered_examples(exception, reporter)
44716eb8 » dchelimsky
2011-10-24 more rdoc
363 filtered_examples.each { |example| example.fail_with_exception(reporter, exception) }
135009ce » myronmarston
2010-09-25 Fix before(:all) error handling so that it fails examples in nested g…
364
365 children.each do |child|
366 reporter.example_group_started(child)
367 child.fail_filtered_examples(exception, reporter)
368 reporter.example_group_finished(child)
369 end
79273a74 » dnurzynski
2011-02-07 Fix exit_status after Exception raised in before :all hook
370 false
b25fea33 » spicycode
2010-09-03 gh#21 Resolution, 1 remaining pending test
371 end
372
84cb5f2e » dchelimsky
2011-12-03 rdoc
373 # @private
3d8eebf4 » dchelimsky
2010-10-03 Move decision about failing fast from example to group
374 def self.fail_fast?
375 RSpec.configuration.fail_fast?
376 end
377
84cb5f2e » dchelimsky
2011-12-03 rdoc
378 # @private
3d90f008 » dchelimsky
2011-10-01 And, once again: Refactor any/all_apply? in example_group, example, a…
379 def self.any_apply?(filters)
380 metadata.any_apply?(filters)
381 end
382
84cb5f2e » dchelimsky
2011-12-03 rdoc
383 # @private
3d90f008 » dchelimsky
2011-10-01 And, once again: Refactor any/all_apply? in example_group, example, a…
384 def self.all_apply?(filters)
385 metadata.all_apply?(filters)
cdf4be2e » dchelimsky
2010-01-31 push apply_condition to metadata
386 end
387
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
388 # @private
40d471be » dchelimsky
2010-04-14 refactor some names, abstactions, scopes, etc
389 def self.declaration_line_numbers
5dc9b185 » dchelimsky
2010-09-17 small optimizations
390 @declaration_line_numbers ||= [metadata[:example_group][:line_number]] +
4b4ff67a » dchelimsky
2010-05-06 Refactor example group hierarchy into a tree
391 examples.collect {|e| e.metadata[:line_number]} +
8e550ad0 » dchelimsky
2010-10-12 Perf: get the right collection the first time
392 children.inject([]) {|l,c| l + c.declaration_line_numbers}
40d471be » dchelimsky
2010-04-14 refactor some names, abstactions, scopes, etc
393 end
394
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
395 # @private
9415f865 » dchelimsky
2010-04-26 add group.top_level_description
396 def self.top_level_description
397 ancestors.last.description
398 end
399
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
400 # @private
67305059 » dchelimsky
2010-05-10 remove __reset__ from ExampleGroup instance namespace
401 def self.set_ivars(instance, ivars)
402 ivars.each {|name, value| instance.instance_variable_set(name, value)}
403 end
404
480f4190 » dchelimsky
2011-11-07 rename ClassMethods/InstanceMethods to ExampleGroupMethods/ExampleMet…
405 # @attr_reader
406 # Returns the [Example](Example) object that wraps this instance of
407 # `ExampleGroup`
408 attr_accessor :example
409
410 # @deprecated use [example](ExampleGroup#example-instance_method)
411 def running_example
412 RSpec.deprecate("running_example", "example")
413 example
414 end
415
416 # Returns the class or module passed to the `describe` method (or alias).
417 # Returns nil if the subject is not a class or module.
418 # @example
419 # describe Thing do
420 # it "does something" do
421 # described_class == Thing
422 # end
423 # end
424 #
425 #
67305059 » dchelimsky
2010-05-10 remove __reset__ from ExampleGroup instance namespace
426 def described_class
b236a8d8 » dchelimsky
2010-08-03 Expose described_class to example group
427 self.class.described_class
6ddb29d1 » spicycode
2010-01-15 Lets make ivars not so leaky between examples (WIP)
428 end
429
feb5e859 » dchelimsky
2011-11-22 rdoc - use yard's @private tag to hide a lot of noise. More to go, bu…
430 # @private
480f4190 » dchelimsky
2011-11-07 rename ClassMethods/InstanceMethods to ExampleGroupMethods/ExampleMet…
431 # instance_evals the block, capturing and reporting an exception if
432 # raised
e5163293 » dchelimsky
2010-07-22 resolve minor feature envy
433 def instance_eval_with_rescue(&hook)
434 begin
435 instance_eval(&hook)
436 rescue Exception => e
9e7dcd37 » myronmarston
2010-10-09 Rescue errors in after(:all) and print them out.
437 raise unless example
e5163293 » dchelimsky
2010-07-22 resolve minor feature envy
438 example.set_exception(e)
439 end
440 end
afca7282 » spicycode
2009-06-29 Initial migration of Micronaut to Spec/Core
441 end
442 end
98f4077b » spicycode
2009-07-02 Initial shared behaviour work.
443 end
Something went wrong with that request. Please try again.