Sha256: 8f89927ef8283a5dc420d1e98845c9095a6ef79ae2de01eadb3a402d41a8c9d5

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

require_relative "test_helper"

class IntegrationTest < Minitest::Test
  def setup
    @progress = Progressrus.new(scope: "walrus", total: 20)
  end

  def teardown
    Progressrus.stores.first.flush(@progress.scope)
  end

  def test_create_tick_and_see_status_in_redis
    @progress.tick

    ticks = Progressrus.scope(["walrus"]).values

    assert_equal 1, ticks.length

    tick = ticks.first
    assert_equal 20, tick.total
    assert_equal 1, tick.count
  end

  def test_create_multiple_ticks_and_see_them_in_redis
    @progress.tick

    progress2 = Progressrus.new(scope: ["walrus"], total: 50)
    progress2.tick

    ticks = Progressrus.scope(["walrus"]).values

    assert_equal 2, ticks.length

    assert_equal [20, 50], ticks.map(&:total).sort
    assert_equal [1,1], ticks.map(&:count)
  end

  def test_tick_on_enumerable
    a = (0..10)
    b = a.with_progress(scope: "walrus").map(&:to_i)

    ticks = Progressrus.scope(["walrus"]).values

    assert_equal a.to_a, b
    assert_equal 1, ticks.length
    assert_equal a.size, ticks.first.total
    assert_equal a.size, ticks.first.count
    assert_instance_of Time, ticks.first.completed_at
  end

  def test_tick_on_enumerable_calls_fail_on_exception
    a = (0..10)

    assert_raises ArgumentError do
      a.with_progress(scope: "walrus").each do
        raise ArgumentError
      end
    end

    ticks = Progressrus.scope(["walrus"]).values

    assert_equal 0, ticks.first.count
    assert_instance_of Time, ticks.first.failed_at
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
progressrus-0.1.1 test/integration_test.rb
progressrus-0.1.0 test/integration_test.rb