Class: Qualspec::RSpec::EvaluationResult
- Inherits:
-
Object
- Object
- Qualspec::RSpec::EvaluationResult
- Defined in:
- lib/qualspec/rspec/evaluation_result.rb
Overview
Wrapper around Qualspec::Evaluation with RSpec-friendly interface Provides clean methods and good failure message formatting
Instance Attribute Summary collapse
-
#criterion ⇒ Object
readonly
Returns the value of attribute criterion.
-
#evaluation ⇒ Object
readonly
Returns the value of attribute evaluation.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #error ⇒ Object
- #error? ⇒ Boolean
- #failing? ⇒ Boolean
-
#failure_message ⇒ Object
RSpec failure message formatting.
- #failure_message_when_negated ⇒ Object
-
#initialize(evaluation, criterion:, response:, threshold: nil) ⇒ EvaluationResult
constructor
A new instance of EvaluationResult.
-
#inspect ⇒ Object
Nice output for RSpec failure messages.
-
#passing? ⇒ Boolean
Core result methods.
- #reasoning ⇒ Object
- #score ⇒ Object
- #tie? ⇒ Boolean
-
#winner? ⇒ Boolean
Comparison support.
Constructor Details
#initialize(evaluation, criterion:, response:, threshold: nil) ⇒ EvaluationResult
Returns a new instance of EvaluationResult.
10 11 12 13 14 15 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 10 def initialize(evaluation, criterion:, response:, threshold: nil) @evaluation = evaluation @criterion = criterion @response = response @threshold = threshold || Qualspec::RSpec.configuration.default_threshold end |
Instance Attribute Details
#criterion ⇒ Object (readonly)
Returns the value of attribute criterion.
8 9 10 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 8 def criterion @criterion end |
#evaluation ⇒ Object (readonly)
Returns the value of attribute evaluation.
8 9 10 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 8 def evaluation @evaluation end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 8 def response @response end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
8 9 10 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 8 def threshold @threshold end |
Instance Method Details
#error ⇒ Object
38 39 40 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 38 def error evaluation.error end |
#error? ⇒ Boolean
34 35 36 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 34 def error? !evaluation.error.nil? end |
#failing? ⇒ Boolean
22 23 24 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 22 def failing? !passing? end |
#failure_message ⇒ Object
RSpec failure message formatting
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 66 def <<~MSG Expected response to pass qualspec evaluation, but it failed. Criterion: #{criterion} Score: #{score}/10 (needed #{threshold} to pass) Reasoning: #{reasoning} #{"Error: #{error}" if error?} Response preview: #{response.to_s[0, 300]}#{'...' if response.to_s.length > 300} MSG end |
#failure_message_when_negated ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 78 def <<~MSG Expected response to fail qualspec evaluation, but it passed. Criterion: #{criterion} Score: #{score}/10 (threshold: #{threshold}) Reasoning: #{reasoning} MSG end |
#inspect ⇒ Object
Nice output for RSpec failure messages
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 52 def inspect status = passing? ? 'PASS' : 'FAIL' lines = [ "#<Qualspec::RSpec::EvaluationResult #{status}>", " Criterion: #{criterion}", " Score: #{score}/10 (threshold: #{threshold})", " Reasoning: #{reasoning}" ] lines << " Error: #{error}" if error? lines << " Response (first 200 chars): #{response.to_s[0, 200]}..." lines.join("\n") end |
#passing? ⇒ Boolean
Core result methods
18 19 20 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 18 def passing? evaluation.pass? end |
#reasoning ⇒ Object
30 31 32 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 30 def reasoning evaluation.reasoning end |
#score ⇒ Object
26 27 28 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 26 def score evaluation.score end |
#tie? ⇒ Boolean
47 48 49 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 47 def tie? evaluation.scenario_winner == :tie end |
#winner? ⇒ Boolean
Comparison support
43 44 45 |
# File 'lib/qualspec/rspec/evaluation_result.rb', line 43 def winner? evaluation.scenario_winner == true end |