/usr/share/doc/ruby-rspec-core/features/metadata/user_defined.feature is in ruby-rspec-core 3.5.0c3e0m0s0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | Feature: User-defined metadata
You can attach user-defined metadata to any example group or example. Pass a
hash as the last argument (before the block) to `describe`, `context` or `it`.
RSpec supports many configuration options that apply only to certain examples
or groups based on the metadata.
Metadata defined on an example group is available (and can be overridden) by
any sub-group or from any example in that group or a sub-group.
In addition, you can specify metadata using just symbols. Each symbol passed
as an argument to `describe`, `context` or `it` will be a key in the metadata
hash, with a corresponding value of `true`.
Scenario: Define group metadata using a hash
Given a file named "define_group_metadata_with_hash_spec.rb" with:
"""ruby
RSpec.describe "a group with user-defined metadata", :foo => 17 do
it 'has access to the metadata in the example' do |example|
expect(example.metadata[:foo]).to eq(17)
end
it 'does not have access to metadata defined on sub-groups' do |example|
expect(example.metadata).not_to include(:bar)
end
describe 'a sub-group with user-defined metadata', :bar => 12 do
it 'has access to the sub-group metadata' do |example|
expect(example.metadata[:bar]).to eq(12)
end
it 'also has access to metadata defined on parent groups' do |example|
expect(example.metadata[:foo]).to eq(17)
end
end
end
"""
When I run `rspec define_group_metadata_with_hash_spec.rb`
Then the examples should all pass
Scenario: Define example metadata using a hash
Given a file named "define_example_metadata_with_hash_spec.rb" with:
"""ruby
RSpec.describe "a group with no user-defined metadata" do
it 'has an example with metadata', :foo => 17 do |example|
expect(example.metadata[:foo]).to eq(17)
expect(example.metadata).not_to include(:bar)
end
it 'has another example with metadata', :bar => 12, :bazz => 33 do |example|
expect(example.metadata[:bar]).to eq(12)
expect(example.metadata[:bazz]).to eq(33)
expect(example.metadata).not_to include(:foo)
end
end
"""
When I run `rspec define_example_metadata_with_hash_spec.rb`
Then the examples should all pass
Scenario: Override user-defined metadata
Given a file named "override_metadata_spec.rb" with:
"""ruby
RSpec.describe "a group with user-defined metadata", :foo => 'bar' do
it 'can be overridden by an example', :foo => 'bazz' do |example|
expect(example.metadata[:foo]).to eq('bazz')
end
describe "a sub-group with an override", :foo => 'goo' do
it 'can be overridden by a sub-group' do |example|
expect(example.metadata[:foo]).to eq('goo')
end
end
end
"""
When I run `rspec override_metadata_spec.rb`
Then the examples should all pass
Scenario: Less verbose metadata
Given a file named "less_verbose_metadata_spec.rb" with:
"""ruby
RSpec.describe "a group with simple metadata", :fast, :simple, :bug => 73 do
it 'has `:fast => true` metadata' do |example|
expect(example.metadata[:fast]).to eq(true)
end
it 'has `:simple => true` metadata' do |example|
expect(example.metadata[:simple]).to eq(true)
end
it 'can still use a hash for metadata' do |example|
expect(example.metadata[:bug]).to eq(73)
end
it 'can define simple metadata on an example', :special do |example|
expect(example.metadata[:special]).to eq(true)
end
end
"""
When I run `rspec less_verbose_metadata_spec.rb`
Then the examples should all pass
|