Class: RSpec::Core::ExampleGroup
- Inherits:
-
Object
- Object
- RSpec::Core::ExampleGroup
- Extended by:
- Hooks, MemoizedHelpers::ClassMethods, SharedExampleGroup
- Includes:
- MemoizedHelpers, Pending
- Defined in:
- lib/rspec/core/example_group.rb
Overview
ExampleGroup and Example are the main structural elements of rspec-core. Consider this example:
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.
Constant Summary
Metadata (collapse)
-
+ (String) description
The current example group description.
-
+ (void) metadata
The Metadata object associated with this group.
-
- (void) described_class
Returns the class or module passed to the
describe
method (or alias).
Defining Examples (collapse)
-
+ (void) example {|Example| ... }
Defines an example within a group.
-
+ (void) fexample {|Example| ... }
Shortcut to define an example with
:focus => true
. -
+ (void) fit {|Example| ... }
Shortcut to define an example with
:focus => true
. -
+ (void) focus {|Example| ... }
Shortcut to define an example with
:focus => true
. -
+ (void) fspecify {|Example| ... }
Shortcut to define an example with
:focus => true
. -
+ (void) it {|Example| ... }
Defines an example within a group.
-
+ (void) pending {|Example| ... }
Shortcut to define an example with
:pending => true
. -
+ (void) skip {|Example| ... }
Shortcut to define an example with
:skip => true
. -
+ (void) specify {|Example| ... }
Defines an example within a group.
-
+ (void) xexample {|Example| ... }
Shortcut to define an example with
:skip => 'Temporarily skipped with xexample'
. -
+ (void) xit {|Example| ... }
Shortcut to define an example with
:skip => 'Temporarily skipped with xit'
. -
+ (void) xspecify {|Example| ... }
Shortcut to define an example with
:skip => 'Temporarily skipped with xspecify'
.
Defining Example Groups (collapse)
-
+ (void) context { ... }
An alias of
example_group
. -
+ (void) describe { ... }
An alias of
example_group
. -
+ (void) example_group { ... }
Generates a subclass of this example group which inherits everything except the examples themselves.
-
+ (void) fcontext { ... }
Shortcut to define an example group with
:focus => true
. -
+ (void) fdescribe { ... }
Shortcut to define an example group with
:focus => true
. -
+ (void) xcontext { ... }
Shortcut to temporarily make an example group skipped.
-
+ (void) xdescribe { ... }
Shortcut to temporarily make an example group skipped.
Including Shared Example Groups (collapse)
-
+ (void) include_context(name, *args, &block)
Includes shared content mapped to
name
directly in the group in which it is declared, as opposed toit_behaves_like
, which creates a nested group. -
+ (void) include_examples(name, *args, &block)
Includes shared content mapped to
name
directly in the group in which it is declared, as opposed toit_behaves_like
, which creates a nested group. -
+ (void) it_behaves_like
Generates a nested example group and includes the shared content mapped to
name
in the nested group. -
+ (void) it_should_behave_like
Generates a nested example group and includes the shared content mapped to
name
in the nested group.
Class Method Summary (collapse)
-
+ (void) run(reporter)
Runs all the examples in this group.
Methods included from SharedExampleGroup
Methods included from MemoizedHelpers::ClassMethods
Methods included from Hooks
after, append_after, around, before, prepend_before
Methods included from Pending
Methods included from MemoizedHelpers
#is_expected, #should, #should_not, #subject
Class Method Details
+ (void) context { ... }
An alias of example_group
. Generally used when grouping examples
contextually (e.g. "with xyz", "when xyz" or "if xyz").
Generates a subclass of this example group which inherits
everything except the examples themselves.
241 |
# File 'lib/rspec/core/example_group.rb', line 241 define_example_group_method :context |
+ (void) describe { ... }
An alias of example_group
. Generally used when grouping
examples by a thing you are describing (e.g. an object, class or method).
Generates a subclass of this example group which inherits
everything except the examples themselves.
236 |
# File 'lib/rspec/core/example_group.rb', line 236 define_example_group_method :describe |
+ (String) description
Returns the current example group description
66 67 68 69 |
# File 'lib/rspec/core/example_group.rb', line 66 def self.description description = [:description] RSpec.configuration.format_docstrings_block.call(description) end |
+ (void) example {|Example| ... }
Defines an example within a group.
123 |
# File 'lib/rspec/core/example_group.rb', line 123 define_example_method :example |
+ (void) example_group { ... }
Generates a subclass of this example group which inherits everything except the examples themselves.
231 |
# File 'lib/rspec/core/example_group.rb', line 231 define_example_group_method :example_group |
+ (void) fcontext { ... }
Shortcut to define an example group with :focus => true
.
Generates a subclass of this example group which inherits
everything except the examples themselves.
257 |
# File 'lib/rspec/core/example_group.rb', line 257 define_example_group_method :fcontext, :focus => true |
+ (void) fdescribe { ... }
Shortcut to define an example group with :focus => true
.
Generates a subclass of this example group which inherits
everything except the examples themselves.
253 |
# File 'lib/rspec/core/example_group.rb', line 253 define_example_group_method :fdescribe, :focus => true |
+ (void) fexample {|Example| ... }
Shortcut to define an example with :focus => true
142 |
# File 'lib/rspec/core/example_group.rb', line 142 define_example_method :fexample, :focus => true |
+ (void) fit {|Example| ... }
Shortcut to define an example with :focus => true
145 |
# File 'lib/rspec/core/example_group.rb', line 145 define_example_method :fit, :focus => true |
+ (void) focus {|Example| ... }
Shortcut to define an example with :focus => true
139 |
# File 'lib/rspec/core/example_group.rb', line 139 define_example_method :focus, :focus => true |
+ (void) fspecify {|Example| ... }
Shortcut to define an example with :focus => true
148 |
# File 'lib/rspec/core/example_group.rb', line 148 define_example_method :fspecify, :focus => true |
+ (void) include_context(name, *args, &block)
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.
293 294 295 |
# File 'lib/rspec/core/example_group.rb', line 293 def self.include_context(name, *args, &block) find_and_eval_shared("context", name, *args, &block) end |
+ (void) include_examples(name, *args, &block)
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.
302 303 304 |
# File 'lib/rspec/core/example_group.rb', line 302 def self.include_examples(name, *args, &block) find_and_eval_shared("examples", name, *args, &block) end |
+ (void) it {|Example| ... }
Defines an example within a group. This is the primary API to define a code example.
126 |
# File 'lib/rspec/core/example_group.rb', line 126 define_example_method :it |
+ (void) it_behaves_like
Generates a nested example group and includes the shared content
mapped to name
in the nested group.
283 |
# File 'lib/rspec/core/example_group.rb', line 283 define_nested_shared_group_method :it_behaves_like, "behaves like" |
+ (void) it_should_behave_like
Generates a nested example group and includes the shared content
mapped to name
in the nested group.
286 |
# File 'lib/rspec/core/example_group.rb', line 286 define_nested_shared_group_method :it_should_behave_like |
+ (void) metadata
The Metadata object associated with this group.
46 47 48 |
# File 'lib/rspec/core/example_group.rb', line 46 def self. @metadata if defined?(@metadata) end |
+ (void) pending {|Example| ... }
Shortcut to define an example with :pending => true
163 |
# File 'lib/rspec/core/example_group.rb', line 163 define_example_method :pending, :pending => true |
+ (void) run(reporter)
Runs all the examples in this group
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/rspec/core/example_group.rb', line 444 def self.run(reporter) if RSpec.world.wants_to_quit RSpec.world.clear_remaining_example_groups if top_level? return end reporter.example_group_started(self) begin run_before_context_hooks(new) 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) } rescue Exception => ex RSpec.world.wants_to_quit = true if fail_fast? for_filtered_examples(reporter) { |example| example.fail_with_exception(reporter, ex) } ensure run_after_context_hooks(new) before_context_ivars.clear reporter.example_group_finished(self) end end |
+ (void) skip {|Example| ... }
Shortcut to define an example with :skip => true
160 |
# File 'lib/rspec/core/example_group.rb', line 160 define_example_method :skip, :skip => true |
+ (void) specify {|Example| ... }
Defines an example within a group.
Useful for when your docstring does not read well off of it
.
135 |
# File 'lib/rspec/core/example_group.rb', line 135 define_example_method :specify |
+ (void) xcontext { ... }
Shortcut to temporarily make an example group skipped. Generates a subclass of this example group which inherits everything except the examples themselves.
249 |
# File 'lib/rspec/core/example_group.rb', line 249 define_example_group_method :xcontext, :skip => "Temporarily skipped with xcontext" |
+ (void) xdescribe { ... }
Shortcut to temporarily make an example group skipped. Generates a subclass of this example group which inherits everything except the examples themselves.
245 |
# File 'lib/rspec/core/example_group.rb', line 245 define_example_group_method :xdescribe, :skip => "Temporarily skipped with xdescribe" |
+ (void) xexample {|Example| ... }
Shortcut to define an example with :skip => 'Temporarily skipped with xexample'
151 |
# File 'lib/rspec/core/example_group.rb', line 151 define_example_method :xexample, :skip => 'Temporarily skipped with xexample' |
+ (void) xit {|Example| ... }
Shortcut to define an example with :skip => 'Temporarily skipped with xit'
154 |
# File 'lib/rspec/core/example_group.rb', line 154 define_example_method :xit, :skip => 'Temporarily skipped with xit' |
+ (void) xspecify {|Example| ... }
Shortcut to define an example with :skip => 'Temporarily skipped with xspecify'
157 |
# File 'lib/rspec/core/example_group.rb', line 157 define_example_method :xspecify, :skip => 'Temporarily skipped with xspecify' |
Instance Method Details
- (void) described_class
Returns the class or module passed to the describe
method (or alias).
Returns nil if the subject is not a class or module.
81 82 83 |
# File 'lib/rspec/core/example_group.rb', line 81 def described_class self.class.described_class end |