Skip to content

Commit

Permalink
accept and clean "false" results
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcinnes committed Oct 25, 2016
1 parent 774e949 commit fe90da1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/scientist/observation.rb
Expand Up @@ -38,9 +38,7 @@ def initialize(name, experiment, &block)
# Return a cleaned value suitable for publishing. Uses the experiment's
# defined cleaner block to clean the observed value.
def cleaned_value
if value
experiment.clean_value value
end
experiment.clean_value value unless value.nil?
end

# Is this observation equivalent to another?
Expand Down
12 changes: 12 additions & 0 deletions test/scientist/observation_test.rb
Expand Up @@ -88,6 +88,18 @@
a = Scientist::Observation.new("test", @experiment) { "test" }
assert_equal "TEST", a.cleaned_value
end

it "doesn't clean nil values" do
@experiment.clean { |value| "foo" }
a = Scientist::Observation.new("test", @experiment) { nil }
assert_nil a.cleaned_value
end

it "cleans false values" do
@experiment.clean { |value| value.to_s.upcase }
a = Scientist::Observation.new("test", @experiment) { false }
assert_equal "FALSE", a.cleaned_value
end
end

end

0 comments on commit fe90da1

Please sign in to comment.