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
171
172
173
174
175
176
|
# File 'lib/rspec/enriched_json/expectation_helper_wrapper.rb', line 139
def capture_test_values(actual, initial_matcher, negated: false)
return unless initial_matcher && RSpec.current_example
begin
if initial_matcher.is_a?(RSpec::Matchers::BuiltIn::BePredicate) || initial_matcher.is_a?(RSpec::Matchers::BuiltIn::Has)
expected_value = !negated
if negated && initial_matcher.respond_to?(:does_not_match?)
initial_matcher.does_not_match?(actual)
else
initial_matcher.matches?(actual)
end
actual_value = if initial_matcher.instance_variable_defined?(:@predicate_result)
initial_matcher.instance_variable_get(:@predicate_result)
end
else
expected_value = initial_matcher.respond_to?(:expected) ? initial_matcher.expected : nil
actual_value = actual
end
key = RSpec.current_example.id
RSpec::EnrichedJson.all_test_values[key] = {
expected: ExpectationHelperWrapper::Serializer.serialize_value(expected_value),
actual: ExpectationHelperWrapper::Serializer.serialize_value(actual_value),
matcher_name: initial_matcher.class.name,
passed: nil
}
RSpec::EnrichedJson.all_test_values[key][:negated] = true if negated
rescue => e
if defined?(RSpec.configuration) && RSpec.configuration.reporter
RSpec.configuration.reporter.message("Warning: Error capturing test values: #{e.message}")
elsif ENV["DEBUG"]
puts "Error capturing test values: #{e.message}"
end
end
end
|