Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting raise_on_mismatches to base class level for tests #174

Open
mtoygar opened this issue Apr 4, 2022 · 1 comment
Open

Allow setting raise_on_mismatches to base class level for tests #174

mtoygar opened this issue Apr 4, 2022 · 1 comment

Comments

@mtoygar
Copy link

mtoygar commented Apr 4, 2022

We are using a base experiment class to manage our publish logic. All the actual experiments are extending from this base class. However, if we set raise_on_mismatches to this base class the result doesn't take effect as the method is using class instance variables(instead of class variables). In the end, people occasionally forget to use this test helper for their newly created experiments.

It would be great if we can manage this test helper via a base class. To elaborate more on this, this is somewhat our structure;

class BaseExperiment
  include Scientist::Experiment

  def initialize
    # setting up some instance variables mainly needed for publish logic
  end

  def publish(result)
    # some custom logic
  end
end

class WidgetExperiment < BaseExperiment
  def initialize
    # setting up custom variables
    super
  end

  def enabled?
    # custom enabled logic
  end
end

class AnotherExperiment < BaseExperiment
  # similar context with widget experiment
end

What we want is to use BaseExperiment.raise_on_mismatches = true to ensure all child experiments are tested on tests without needed a separate test setup. Would such a need make sense to you?

@TheExacc
Copy link

We are using a base experiment class to manage our publish logic. All the actual experiments are extending from this base class. However, if we set raise_on_mismatches to this base class the result doesn't take effect as the method is using class instance variables(instead of class variables). In the end, people occasionally forget to use this test helper for their newly created experiments.

It would be great if we can manage this test helper via a base class. To elaborate more on this, this is somewhat our structure;

class BaseExperiment
  include Scientist::Experiment

  def initialize
    # setting up some instance variables mainly needed for publish logic
  end

  def publish(result)
    # some custom logic
  end
end

class WidgetExperiment < BaseExperiment
  def initialize
    # setting up custom variables
    super
  end

  def enabled?
    # custom enabled logic
  end
end

class AnotherExperiment < BaseExperiment
  # similar context with widget experiment
end

What we want is to use BaseExperiment.raise_on_mismatches = true to ensure all child experiments are tested on tests without needed a separate test setup. Would such a need make sense to you?

definitely makes sense

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

No branches or pull requests

2 participants