Skip to content

Inherit raise_on_mismatches from the superclass - #319

Open
afurm wants to merge 1 commit into
github:mainfrom
afurm:inherit-raise-on-mismatches
Open

afurm wants to merge 1 commit into
github:mainfrom
afurm:inherit-raise-on-mismatches

Conversation

@afurm

@afurm afurm commented Oct 16, 2026

Copy link
Copy Markdown

Fixes #174.

raise_on_mismatches is stored in a class instance variable, so setting it on a shared base experiment class didn't apply to its subclasses:

class BaseExperiment
  include Scientist::Experiment
end

class WidgetExperiment < BaseExperiment; end

BaseExperiment.raise_on_mismatches = true
WidgetExperiment.raise_on_mismatches? # => nil, mismatches are silently published

This makes raise_on_mismatches? fall back to the superclass when the class hasn't set its own value. A subclass can still opt out with raise_on_mismatches = false.

I added tests for both cases and a line to the README. The full suite passes locally except includes the backtrace when an observation raises, which also fails on main under Ruby 3.4+ because of the new backtrace quote style.

Setting raise_on_mismatches on a base experiment class had no effect on
its subclasses, because the flag lives in a class instance variable.
Fall back to the superclass when a class hasn't set its own value.

Fixes github#174
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting raise_on_mismatches to base class level for tests

1 participant