Class: RSpec::Core::ExampleGroup
- Extended by:
- Hooks, MemoizedHelpers::ClassMethods, SharedExampleGroup
- Includes:
- MemoizedHelpers, Pending
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb
Overview
ExampleGroup and Example are the main structural elements of rspec-core. Consider this example:
RSpec.describe Thing do
it "does something" do
end
end
The object returned by ‘describe Thing` is a subclass of ExampleGroup. The object returned by `it “does something”` is an instance of Example, which serves as a wrapper for an instance of the ExampleGroup in which it is declared.
Example group bodies (e.g. ‘describe` or `context` blocks) are evaluated in the context of a new subclass of ExampleGroup. Individual examples are evaluated in the context of an instance of the specific ExampleGroup subclass to which they belong.
Besides the class methods defined here, there are other interesting macros defined in Hooks, MemoizedHelpers::ClassMethods and SharedExampleGroup. There are additional instance methods available to your examples defined in MemoizedHelpers and Pending.
Direct Known Subclasses
Constant Summary collapse
- INSTANCE_VARIABLE_TO_IGNORE =
:@__inspect_output
- WrongScopeError =
Raised when an RSpec API is called in the wrong scope, such as ‘before` being called from within an example rather than from within an example group block.
Class.new(NoMethodError)
Constants included from Pending
Pending::NOT_YET_IMPLEMENTED, Pending::NO_REASON_GIVEN
Metadata collapse
- .delegate_to_metadata(*names) ⇒ Object
-
.description ⇒ String
The current example group description.
-
.metadata ⇒ Object
The [Metadata](Metadata) object associated with this group.
-
.superclass_metadata ⇒ Metadata
Belonging to the parent of a nested ExampleGroup.
-
.with_replaced_metadata(meta) ⇒ Object
Temporarily replace the provided metadata.
-
#described_class ⇒ Object
Returns the class or module passed to the ‘describe` method (or alias).
Defining Examples collapse
-
.define_example_method(name, extra_options = {}) ⇒ Object
@example $1 “does something”, :slow, :load_factor => 100 do end.
-
.example {|Example| ... } ⇒ Object
Defines an example within a group.
-
.fexample {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:focus => true`.
-
.fit {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:focus => true`.
-
.focus {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:focus => true`.
-
.fspecify {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:focus => true`.
-
.it {|Example| ... } ⇒ Object
Defines an example within a group.
-
.pending {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:pending => true`.
-
.skip {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:skip => true`.
-
.specify {|Example| ... } ⇒ Object
Defines an example within a group.
-
.xexample {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:skip => ’Temporarily skipped with xexample’‘.
-
.xit {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:skip => ’Temporarily skipped with xit’‘.
-
.xspecify {|Example| ... } ⇒ Object
Shortcut to define an example with ‘:skip => ’Temporarily skipped with xspecify’‘.
Defining Example Groups collapse
Including Shared Example Groups collapse
-
.add_example(example) ⇒ Object
Adds an example to the example group.
- .define_nested_shared_group_method(new_name, report_label = "it should behave like") ⇒ Object
- .find_and_eval_shared(label, name, inclusion_location, *args, &customization_block) ⇒ Object
-
.include_context(name, *args, &block) ⇒ Object
Includes shared content mapped to ‘name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group.
-
.include_examples(name, *args, &block) ⇒ Object
Includes shared content mapped to ‘name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group.
-
.remove_example(example) ⇒ Object
Removes an example from the example group.
-
.reset_memoized ⇒ Object
Clear memoized values when adding/removing examples.
Class Method Summary collapse
- .before_context_ivars ⇒ Object
- .children ⇒ Object
-
.currently_executing_a_context_hook? ⇒ Boolean
Returns true if a ‘before(:context)` or `after(:context)` hook is currently executing.
- .declaration_locations ⇒ Object
- .descendant_filtered_examples ⇒ Object
- .descendants ⇒ Object
- .each_instance_variable_for_example(group) ⇒ Object
- .ensure_example_groups_are_configured ⇒ Object
- .examples ⇒ Object
- .filtered_examples ⇒ Object
- .for_filtered_examples(reporter, &block) ⇒ Object
-
.id ⇒ String
The unique id of this example group.
-
.idempotently_define_singleton_method(name, &definition) ⇒ Object
Define a singleton method for the singleton class (remove the method if it’s already been defined).
- .initialize(inspect_output = nil) ⇒ Object
- .inspect ⇒ Object
- .next_runnable_index_for(file) ⇒ Object
- .ordering_strategy ⇒ Object
- .parent_groups ⇒ Object
-
.run(reporter = RSpec::Core::NullReporter) ⇒ Object
Runs all the examples in this group.
- .run_after_context_hooks(example_group_instance) ⇒ Object
- .run_before_context_hooks(example_group_instance) ⇒ Object
- .run_examples(reporter) ⇒ Object
- .set_it_up(description, args, registration_collection, &example_group_block) ⇒ Object
- .set_ivars(instance, ivars) ⇒ Object
- .store_before_context_ivars(example_group_instance) ⇒ Object
- .subclass(parent, description, args, registration_collection, &example_group_block) ⇒ Object
-
.superclass_before_context_ivars ⇒ Object
:nocov:.
- .top_level? ⇒ Boolean
- .top_level_description ⇒ Object
-
.traverse_tree_until(&block) ⇒ Object
Traverses the tree of groups, starting with ‘self`, then the children, recursively.
- .update_inherited_metadata(updates) ⇒ Object
Instance Method Summary collapse
-
#singleton_class ⇒ Object
:nocov:.
Methods included from Hooks
after, append_after, around, before, hooks, prepend_before
Methods included from MemoizedHelpers::ClassMethods
Methods included from SharedExampleGroup
Methods included from Pending
mark_fixed!, mark_pending!, mark_skipped!, #pending, #skip
Methods included from MemoizedHelpers
#is_expected, #should, #should_not, #subject
Class Method Details
.add_example(example) ⇒ Object
Adds an example to the example group
367 368 369 370 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 367 def self.add_example(example) reset_memoized examples << example end |
.before_context_ivars ⇒ Object
529 530 531 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 529 def self.before_context_ivars @before_context_ivars ||= {} end |
.children ⇒ Object
466 467 468 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 466 def self.children @children ||= [] end |
.currently_executing_a_context_hook? ⇒ Boolean
Returns true if a ‘before(:context)` or `after(:context)` hook is currently executing.
542 543 544 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 542 def self.currently_executing_a_context_hook? @currently_executing_a_context_hook end |
.declaration_locations ⇒ Object
667 668 669 670 671 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 667 def self.declaration_locations @declaration_locations ||= [Metadata.location_tuple_from()] + examples.map { |e| Metadata.location_tuple_from(e.) } + FlatMap.flat_map(children, &:declaration_locations) end |
.define_example_group_method(name, metadata = {}) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 246 def self.define_example_group_method(name, ={}) idempotently_define_singleton_method(name) do |*args, &example_group_block| thread_data = RSpec::Support.thread_local_data top_level = self == ExampleGroup registration_collection = if top_level if thread_data[:in_example_group] raise "Creating an isolated context from within a context is " \ "not allowed. Change `RSpec.#{name}` to `#{name}` or " \ "move this to a top-level scope." end thread_data[:in_example_group] = true RSpec.world.example_groups else children end begin description = args.shift = .dup .merge!(args.pop) if args.last.is_a? Hash args << subclass(self, description, args, registration_collection, &example_group_block) ensure thread_data.delete(:in_example_group) if top_level end end RSpec::Core::DSL.expose_example_group_alias(name) end |
.define_example_method(name, extra_options = {}) ⇒ Object
@example
$1 "does something", :slow, :load_factor => 100 do
end
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 145 def self.define_example_method(name, ={}) idempotently_define_singleton_method(name) do |*all_args, &block| desc, *args = *all_args = Metadata.build_hash_from(args) .update(:skip => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block .update() RSpec::Core::Example.new(self, desc, , block) end end |
.define_nested_shared_group_method(new_name, report_label = "it should behave like") ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 317 def self.define_nested_shared_group_method(new_name, report_label="it should behave like") idempotently_define_singleton_method(new_name) do |name, *args, &customization_block| # Pass :caller so the :location metadata is set properly. # Otherwise, it'll be set to the next line because that's # the block's source_location. group = example_group("#{report_label} #{name}", :caller => (the_caller = caller)) do find_and_eval_shared("examples", name, the_caller.first, *args, &customization_block) end group.[:shared_group_name] = name group end end |
.delegate_to_metadata(*names) ⇒ Object
76 77 78 79 80 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 76 def self.(*names) names.each do |name| idempotently_define_singleton_method(name) { .fetch(name) } end end |
.descendant_filtered_examples ⇒ Object
460 461 462 463 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 460 def self.descendant_filtered_examples @descendant_filtered_examples ||= filtered_examples + FlatMap.flat_map(children, &:descendant_filtered_examples) end |
.descendants ⇒ Object
503 504 505 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 503 def self.descendants @_descendants ||= [self] + FlatMap.flat_map(children, &:descendants) end |
.description ⇒ String
Returns the current example group description.
85 86 87 88 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 85 def self.description description = [:description] RSpec.configuration.format_docstrings_block.call(description) end |
.each_instance_variable_for_example(group) ⇒ Object
700 701 702 703 704 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 700 def self.each_instance_variable_for_example(group) group.instance_variables.each do |ivar| yield ivar unless ivar == INSTANCE_VARIABLE_TO_IGNORE end end |
.ensure_example_groups_are_configured ⇒ Object
518 519 520 521 522 523 524 525 526 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 518 def self.ensure_example_groups_are_configured unless defined?(@@example_groups_configured) RSpec.configuration.configure_mock_framework RSpec.configuration.configure_expectation_framework # rubocop:disable Style/ClassVars @@example_groups_configured = true # rubocop:enable Style/ClassVars end end |
.example ⇒ Object .example(&example_implementation) ⇒ Object .example(doc_string, *metadata) ⇒ Object .example(doc_string, *metadata, &example_implementation) ⇒ Object
Defines an example within a group.
158 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 158 define_example_method :example |
.examples ⇒ Object
450 451 452 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 450 def self.examples @examples ||= [] end |
.fexample ⇒ Object .fexample(&example_implementation) ⇒ Object .fexample(doc_string, *metadata) ⇒ Object .fexample(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:focus => true`.
177 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 177 define_example_method :fexample, :focus => true |
.filtered_examples ⇒ Object
455 456 457 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 455 def self.filtered_examples RSpec.world.filtered_examples[self] end |
.find_and_eval_shared(label, name, inclusion_location, *args, &customization_block) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 379 def self.find_and_eval_shared(label, name, inclusion_location, *args, &customization_block) shared_module = RSpec.world.shared_example_group_registry.find(parent_groups, name) unless shared_module raise ArgumentError, "Could not find shared #{label} #{name.inspect}" end shared_module.include_in( self, Metadata.relative_path(inclusion_location), args, customization_block ) end |
.fit ⇒ Object .fit(&example_implementation) ⇒ Object .fit(doc_string, *metadata) ⇒ Object .fit(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:focus => true`.
180 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 180 define_example_method :fit, :focus => true |
.focus ⇒ Object .focus(&example_implementation) ⇒ Object .focus(doc_string, *metadata) ⇒ Object .focus(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:focus => true`.
174 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 174 define_example_method :focus, :focus => true |
.for_filtered_examples(reporter, &block) ⇒ Object
655 656 657 658 659 660 661 662 663 664 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 655 def self.for_filtered_examples(reporter, &block) filtered_examples.each(&block) children.each do |child| reporter.example_group_started(child) child.for_filtered_examples(reporter, &block) reporter.example_group_finished(child) end false end |
.fspecify ⇒ Object .fspecify(&example_implementation) ⇒ Object .fspecify(doc_string, *metadata) ⇒ Object .fspecify(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:focus => true`.
183 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 183 define_example_method :fspecify, :focus => true |
.id ⇒ String
Returns the unique id of this example group. Pass this at the command line to re-run this exact example group.
675 676 677 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 675 def self.id Metadata.id_from() end |
.idempotently_define_singleton_method(name, &definition) ⇒ Object
Define a singleton method for the singleton class (remove the method if it’s already been defined).
40 41 42 43 44 45 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 40 def self.idempotently_define_singleton_method(name, &definition) (class << self; self; end).module_exec do remove_method(name) if method_defined?(name) && instance_method(name).owner == self define_method(name, &definition) end end |
.include_context(name, *args, &block) ⇒ Object
Includes shared content mapped to ‘name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group. If given a block, that block is also eval’d in the current context.
343 344 345 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 343 def self.include_context(name, *args, &block) find_and_eval_shared("context", name, caller.first, *args, &block) end |
.include_examples(name, *args, &block) ⇒ Object
Includes shared content mapped to ‘name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group. If given a block, that block is also eval’d in the current context.
353 354 355 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 353 def self.include_examples(name, *args, &block) find_and_eval_shared("examples", name, caller.first, *args, &block) end |
.initialize(inspect_output = nil) ⇒ Object
707 708 709 710 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 707 def initialize(inspect_output=nil) @__inspect_output = inspect_output || '(no description provided)' super() # no args get passed end |
.inspect ⇒ Object
713 714 715 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 713 def inspect "#<#{self.class} #{@__inspect_output}>" end |
.it ⇒ Object .it(&example_implementation) ⇒ Object .it(doc_string, *metadata) ⇒ Object .it(doc_string, *metadata, &example_implementation) ⇒ Object
Defines an example within a group. This is the primary API to define a code example.
161 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 161 define_example_method :it |
.metadata ⇒ Object
The [Metadata](Metadata) object associated with this group.
51 52 53 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 51 def self. @metadata ||= nil end |
.next_runnable_index_for(file) ⇒ Object
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 485 def self.next_runnable_index_for(file) if self == ExampleGroup # We add 1 so the ids start at 1 instead of 0. This is # necessary for this branch (but not for the other one) # because we register examples and groups with the # `children` and `examples` collection BEFORE this # method is called as part of metadata hash creation, # but the example group is recorded with # `RSpec.world.example_group_counts_by_spec_file` AFTER # the metadata hash is created and the group is returned # to the caller. RSpec.world.num_example_groups_defined_in(file) + 1 else children.count + examples.count end end |
.ordering_strategy ⇒ Object
625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 625 def self.ordering_strategy order = .fetch(:order, :global) registry = RSpec.configuration.ordering_registry registry.fetch(order) do warn <<-WARNING.gsub(/^ +\|/, '') |WARNING: Ignoring unknown ordering specified using `:order => #{order.inspect}` metadata. | Falling back to configured global ordering. | Unrecognized ordering specified at: #{location} WARNING registry.fetch(:global) end end |
.parent_groups ⇒ Object
508 509 510 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 508 def self.parent_groups @parent_groups ||= ancestors.select { |a| a < RSpec::Core::ExampleGroup } end |
.pending ⇒ Object .pending(&example_implementation) ⇒ Object .pending(doc_string, *metadata) ⇒ Object .pending(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:pending => true`
198 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 198 define_example_method :pending, :pending => true |
.remove_example(example) ⇒ Object
Removes an example from the example group
373 374 375 376 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 373 def self.remove_example(example) reset_memoized examples.delete example end |
.reset_memoized ⇒ Object
Clear memoized values when adding/removing examples
359 360 361 362 363 364 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 359 def self.reset_memoized @descendant_filtered_examples = nil @_descendants = nil @parent_groups = nil @declaration_locations = nil end |
.run(reporter = RSpec::Core::NullReporter) ⇒ Object
Runs all the examples in this group.
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 599 def self.run(reporter=RSpec::Core::NullReporter) return if RSpec.world.wants_to_quit reporter.example_group_started(self) should_run_context_hooks = descendant_filtered_examples.any? begin RSpec.current_scope = :before_context_hook run_before_context_hooks(new('before(:context) hook')) if should_run_context_hooks result_for_this_group = run_examples(reporter) results_for_descendants = ordering_strategy.order(children).map { |child| child.run(reporter) }.all? result_for_this_group && results_for_descendants rescue Pending::SkipDeclaredInExample => ex for_filtered_examples(reporter) { |example| example.skip_with_exception(reporter, ex) } true rescue Support::AllExceptionsExceptOnesWeMustNotRescue => ex for_filtered_examples(reporter) { |example| example.fail_with_exception(reporter, ex) } RSpec.world.wants_to_quit = true if reporter.fail_fast_limit_met? false ensure RSpec.current_scope = :after_context_hook run_after_context_hooks(new('after(:context) hook')) if should_run_context_hooks reporter.example_group_finished(self) end end |
.run_after_context_hooks(example_group_instance) ⇒ Object
585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 585 def self.run_after_context_hooks(example_group_instance) set_ivars(example_group_instance, before_context_ivars) @currently_executing_a_context_hook = true ContextHookMemoized::After.isolate_for_context_hook(example_group_instance) do hooks.run(:after, :context, example_group_instance) end ensure before_context_ivars.clear @currently_executing_a_context_hook = false end |
.run_before_context_hooks(example_group_instance) ⇒ Object
547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 547 def self.run_before_context_hooks(example_group_instance) set_ivars(example_group_instance, superclass_before_context_ivars) @currently_executing_a_context_hook = true ContextHookMemoized::Before.isolate_for_context_hook(example_group_instance) do hooks.run(:before, :context, example_group_instance) end ensure store_before_context_ivars(example_group_instance) @currently_executing_a_context_hook = false end |
.run_examples(reporter) ⇒ Object
641 642 643 644 645 646 647 648 649 650 651 652 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 641 def self.run_examples(reporter) ordering_strategy.order(filtered_examples).map do |example| next if RSpec.world.wants_to_quit instance = new(example.inspect_output) set_ivars(instance, before_context_ivars) succeeded = example.run(instance, reporter) if !succeeded && reporter.fail_fast_limit_met? RSpec.world.wants_to_quit = true end succeeded end.all? end |
.set_it_up(description, args, registration_collection, &example_group_block) ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 410 def self.set_it_up(description, args, registration_collection, &example_group_block) # Ruby 1.9 has a bug that can lead to infinite recursion and a # SystemStackError if you include a module in a superclass after # including it in a subclass: https://gist.github.com/845896 # To prevent this, we must include any modules in # RSpec::Core::ExampleGroup before users create example groups and have # a chance to include the same module in a subclass of # RSpec::Core::ExampleGroup. So we need to configure example groups # here. ensure_example_groups_are_configured # Register the example with the group before creating the metadata hash. # This is necessary since creating the metadata hash triggers # `when_first_matching_example_defined` callbacks, in which users can # load RSpec support code which defines hooks. For that to work, the # examples and example groups must be registered at the time the # support code is called or be defined afterwards. # Begin defined beforehand but registered afterwards causes hooks to # not be applied where they should. registration_collection << self @user_metadata = Metadata.build_hash_from(args) @metadata = Metadata::ExampleGroupHash.create( , @user_metadata, superclass.method(:next_runnable_index_for), description, *args, &example_group_block ) config = RSpec.configuration config.(@metadata) ExampleGroups.assign_const(self) @currently_executing_a_context_hook = false config.configure_group(self) end |
.set_ivars(instance, ivars) ⇒ Object
685 686 687 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 685 def self.set_ivars(instance, ivars) ivars.each { |name, value| instance.instance_variable_set(name, value) } end |
.skip ⇒ Object .skip(&example_implementation) ⇒ Object .skip(doc_string, *metadata) ⇒ Object .skip(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:skip => true`
195 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 195 define_example_method :skip, :skip => true |
.specify ⇒ Object .specify(&example_implementation) ⇒ Object .specify(doc_string, *metadata) ⇒ Object .specify(doc_string, *metadata, &example_implementation) ⇒ Object
Defines an example within a group. Useful for when your docstring does not read well off of ‘it`.
170 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 170 define_example_method :specify |
.store_before_context_ivars(example_group_instance) ⇒ Object
534 535 536 537 538 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 534 def self.store_before_context_ivars(example_group_instance) each_instance_variable_for_example(example_group_instance) do |ivar| before_context_ivars[ivar] = example_group_instance.instance_variable_get(ivar) end end |
.subclass(parent, description, args, registration_collection, &example_group_block) ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 395 def self.subclass(parent, description, args, registration_collection, &example_group_block) subclass = Class.new(parent) subclass.set_it_up(description, args, registration_collection, &example_group_block) subclass.module_exec(&example_group_block) if example_group_block # The LetDefinitions module must be included _after_ other modules # to ensure that it takes precedence when there are name collisions. # Thus, we delay including it until after the example group block # has been eval'd. MemoizedHelpers.define_helpers_on(subclass) subclass end |
.superclass_before_context_ivars ⇒ Object
:nocov:
562 563 564 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 562 def self.superclass_before_context_ivars superclass.before_context_ivars end |
.superclass_metadata ⇒ Metadata
Returns belonging to the parent of a nested RSpec::Core::ExampleGroup.
71 72 73 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 71 def self. @superclass_metadata ||= superclass.respond_to?(:metadata) ? superclass. : nil end |
.top_level? ⇒ Boolean
513 514 515 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 513 def self.top_level? superclass == ExampleGroup end |
.top_level_description ⇒ Object
680 681 682 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 680 def self.top_level_description parent_groups.last.description end |
.traverse_tree_until(&block) ⇒ Object
Traverses the tree of groups, starting with ‘self`, then the children, recursively. Halts the traversal of a branch of the tree as soon as the passed block returns true. Note that siblings groups and their sub-trees will continue to be explored. This is intended to make it easy to find the top-most group that satisfies some condition.
476 477 478 479 480 481 482 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 476 def self.traverse_tree_until(&block) return if yield self children.each do |child| child.traverse_tree_until(&block) end end |
.update_inherited_metadata(updates) ⇒ Object
727 728 729 730 731 732 733 734 735 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 727 def self.(updates) .update(updates) do |key, existing_group_value, new_inherited_value| @user_metadata.key?(key) ? existing_group_value : new_inherited_value end RSpec.configuration.configure_group(self) examples.each { |ex| ex.(updates) } children.each { |group| group.(updates) } end |
.with_replaced_metadata(meta) ⇒ Object
Temporarily replace the provided metadata. Intended primarily to allow an example group’s singleton class to return the metadata of the example that it exists for. This is necessary for shared example group inclusion to work properly with singleton example groups.
61 62 63 64 65 66 67 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 61 def self.() = @metadata = yield ensure @metadata = end |
.xexample ⇒ Object .xexample(&example_implementation) ⇒ Object .xexample(doc_string, *metadata) ⇒ Object .xexample(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:skip => ’Temporarily skipped with xexample’‘.
186 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 186 define_example_method :xexample, :skip => 'Temporarily skipped with xexample' |
.xit ⇒ Object .xit(&example_implementation) ⇒ Object .xit(doc_string, *metadata) ⇒ Object .xit(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:skip => ’Temporarily skipped with xit’‘.
189 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 189 define_example_method :xit, :skip => 'Temporarily skipped with xit' |
.xspecify ⇒ Object .xspecify(&example_implementation) ⇒ Object .xspecify(doc_string, *metadata) ⇒ Object .xspecify(doc_string, *metadata, &example_implementation) ⇒ Object
Shortcut to define an example with ‘:skip => ’Temporarily skipped with xspecify’‘.
192 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 192 define_example_method :xspecify, :skip => 'Temporarily skipped with xspecify' |
Instance Method Details
#described_class ⇒ Object
Returns the class or module passed to the ‘describe` method (or alias). Returns nil if the subject is not a class or module.
99 100 101 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 99 def described_class self.class.described_class end |
#singleton_class ⇒ Object
:nocov:
720 721 722 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 720 def singleton_class class << self; self; end end |