Class: RSpec::Core::Metadata
- Inherits:
-
Hash
- Object
- Hash
- RSpec::Core::Metadata
show all
- Defined in:
- lib/rspec/core/metadata.rb
Defined Under Namespace
Modules: GroupMetadataHash, MetadataHash
Instance Method Summary
collapse
Constructor Details
#initialize(parent_group_metadata = nil) {|_self| ... } ⇒ Metadata
Returns a new instance of Metadata.
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/rspec/core/metadata.rb', line 97
def initialize(parent_group_metadata=nil)
if parent_group_metadata
update(parent_group_metadata)
store(:example_group, {:example_group => parent_group_metadata[:example_group]}.extend(GroupMetadataHash))
else
store(:example_group, {}.extend(GroupMetadataHash))
end
yield self if block_given?
end
|
Instance Method Details
#all_apply?(filters) ⇒ Boolean
126
127
128
|
# File 'lib/rspec/core/metadata.rb', line 126
def all_apply?(filters)
filters.all? {|k,v| filter_applies?(k,v)}
end
|
#any_apply?(filters) ⇒ Boolean
122
123
124
|
# File 'lib/rspec/core/metadata.rb', line 122
def any_apply?(filters)
filters.any? {|k,v| filter_applies?(k,v)}
end
|
#filter_applies?(key, value, metadata = self) ⇒ Boolean
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/rspec/core/metadata.rb', line 130
def filter_applies?(key, value, metadata=self)
case value
when Hash
if key == :locations
file_path = (self[:example_group] || {})[:file_path]
expanded_path = file_path && File.expand_path( file_path )
if expanded_path && line_numbers = value[expanded_path]
filter_applies?(:line_numbers, line_numbers)
else
true
end
else
value.all? { |k, v| filter_applies?(k, v, metadata[key]) }
end
when Regexp
metadata[key] =~ value
when Proc
if value.arity == 2
value.call(metadata[key], metadata) rescue false
else
value.call(metadata[key]) rescue false
end
when String
metadata[key].to_s == value.to_s
when Enumerable
if key == :line_numbers
preceding_declaration_lines = value.map{|v| world.preceding_declaration_line(v)}
!(relevant_line_numbers(metadata) & preceding_declaration_lines).empty?
else
metadata[key] == value
end
else
metadata[key].to_s == value.to_s
end
end
|
#for_example(description, user_metadata) ⇒ Object
118
119
120
|
# File 'lib/rspec/core/metadata.rb', line 118
def for_example(description, user_metadata)
dup.extend(MetadataHash).configure_for_example(description, user_metadata)
end
|
#process(*args) ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'lib/rspec/core/metadata.rb', line 108
def process(*args)
user_metadata = args.last.is_a?(Hash) ? args.pop : {}
ensure_valid_keys(user_metadata)
self[:example_group].store(:description_args, args)
self[:example_group].store(:caller, user_metadata.delete(:caller) || caller)
update(user_metadata)
end
|