- Defined in:
#shared_context_metadata_behavior ⇒ :trigger_inclusion, :apply_to_host_groups #shared_context_metadata_behavior=(value) ⇒ void
Configures how RSpec treats metadata passed as part of a shared example group definition. For example, given this shared example group definition:
.shared_context "uses DB", :db => true do around(:example) do |ex| MyORM.transaction(:rollback => true, &ex) end end
...there are two ways RSpec can treat the
:db => true metadata, each
of which has a corresponding config option:
:trigger_inclusion: this shared context will be implicitly included in any groups (or examples) that have
:db => truemetadata.
:apply_to_host_groups: the metadata will be inherited by the metadata hash of all host groups and examples.
:trigger_inclusion is the legacy behavior from before RSpec 3.5 but should
be considered deprecated. Instead, you can explicitly include a group with
.describe "My model" do include_context "uses DB" end
...or you can configure RSpec to include the context based on matching metadata using an API that mirrors configured module inclusion:
. do |rspec| rspec.include_context "uses DB", :db => true end
:apply_to_host_groups is a new feature of RSpec 3.5 and will be the only
supported behavior in RSpec 4.
# File 'lib/rspec/core/configuration.rb', line 432 define_reader :shared_context_metadata_behavior