Sha256: c68e7570785b970dcda186a3e27f87348a30c19a74cca6cae64b7501d7c9f7ed

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

require 'test_helper'
require 'json'

class ConversionTest < Minitest::Test

  def setup
    @experiment = Verdict::Experiment.new('conversion test') do
      groups { group :all, 100 }
    end
  end

  def test_subject_lookup
    conversion = Verdict::Conversion.new(@experiment, 'test_subject_id', :test_goal)
    assert_raises(NotImplementedError) { conversion.subject }

    @experiment.expects(:fetch_subject).with('test_subject_id').returns(subject = mock('subject'))
    conversion = Verdict::Conversion.new(@experiment, 'test_subject_id', :test_goal)
    assert_equal subject, conversion.subject
  end

  def test_assignment_lookup
    @experiment.subject_storage.expects(:retrieve_assignment).with(@experiment, 'test_subject_id')
    conversion = Verdict::Conversion.new(@experiment, 'test_subject_id', :test_goal)
    conversion.assignment
  end

  def test_json_representation
    conversion = Verdict::Conversion.new(@experiment, 'test_subject_id', :test_goal, Time.new(2013, 1, 1, 4, 5, 6, '+00:00'))
    json = JSON.parse(conversion.to_json)

    assert_equal 'conversion test',      json['experiment']
    assert_equal 'test_subject_id',      json['subject']
    assert_equal 'test_goal',            json['goal']
    assert_equal 'test_goal',            json['goal']
    assert_equal '2013-01-01T04:05:06Z', json['created_at']
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
verdict-0.3.2 test/conversion_test.rb
verdict-0.3.1 test/conversion_test.rb
verdict-0.3.0 test/conversion_test.rb
verdict-0.2.1 test/conversion_test.rb