Scientist::Experiment.new creates Scientist::Default instance even when it should have been overridden
- 主要语言
- Ruby
- 星标
- 7.8k
- 派生
- 505
- PR 合并指标
- 30 天内没有已合并 PR
描述
Hi friends! Thank you for your great work with this gem :sparkles:
I am having a problem in Rails apps where Scientist::Experiment defaults to the original `Default` object until the custom one is called - leading to some head-scratching about why the `try` block is not running even when `enabled?` is set to `true`.
I'm unsure whether this is a problem with the Rails load order because of how I've arranged my files, whether the examples in the README could be a little better, or whether there's genuinely a bug here.
```
$ bundle exec rails console
Loading development environment (Rails 5.1.6)
irb(main):001:0> Scientist::Experiment.new "something"
=> #
irb(main):002:0> LdapExperiment.new(name: "something")
=> #
irb(main):003:0> Scientist::Experiment.new "something"
=> #
```
I've followed the instructions in the README, which are delightful and comprehensive.
```ruby
# app/experiments/ldap_experiment.rb
require "scientist/experiment"
class LdapExperiment
include Scientist::Experiment
attr_accessor :name
def initialize(name:)
@name = name
end
def enabled?
# ...
end
def publish(result)
# ...
end
end
module Scientist::Experiment
def self.new(name)
LdapExperiment.new(name: name)
end
end
```
```ruby
# app/models/whatever.rb
class Whatever
include Scientist
def do_something
science "role lookup" do |e|
e.use { do_one_thing }
e.try { do_some_other_thing }
end
end
end
```
This is occurring in Rails 3.2.x and Rails 5.1.x applications, with version 1.2.0 of the gem.
贡献指南
调研方向
使用 app/experiments/ldap_experiment.rb 和 issue 中所示的 Scientist::Experiment.new 调用,从 Rails 控制台复现该行为。阅读 scientist/experiment 和所引用的 README 示例,以确定这是加载顺序行为、实现 bug,还是文档歧义;当预期的覆盖行为得到确立,并由适当的修复或说明加以覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- rails, ruby
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100