Sha256: 8f645dff5275dcf2b4de66486e56b03e08ef87d7b636eead1c76a43f04cd037a

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'swt_shoes/spec_helper'

describe Shoes::Swt::Animation do
  include_context 'swt app'
  let(:dsl) { double('dsl', :stopped? => false, :removed? => false,
                     :framerate => 10, :current_frame => nil,
                     :increment_frame => nil, :blk => block) }
  let(:block) { double 'block', call: nil }
  let(:display) { ::Swt.display }
  subject { Shoes::Swt::Animation.new dsl, swt_app }

  before :each do
    display.stub(:timer_exec)
  end

  it "triggers an Swt timer" do
    display.should_receive(:timer_exec)
    subject
  end

  it "gets framerate" do
    expect(dsl).to receive(:framerate)
    subject
  end

  describe "task" do
    let(:task) { subject.task }

    it "calls block" do
      expect(block).to receive(:call)
      task.call
    end

    it "gets framerate" do
      expect(dsl).to receive(:framerate)
      task.call
    end

    it "triggers redraw" do
      with_redraws do
        expect(swt_app).to receive(:flush)
        task.call
      end
    end

    it "counts frames" do
      expect(dsl).to receive(:increment_frame)
      task.call
    end

    describe 'disabled' do
      describe 'stopped?' do
        before :each do
          dsl.stub :stopped? => true
          task.call
        end

        it 'does not call the block' do
          expect(block).to_not have_received :call
        end

        it 'continues calling the task' do
          # one for initialize, one for the call in the task call
          expect(display).to have_received(:timer_exec).exactly(2).times
        end
      end

      describe 'removed?' do
        before :each do
          dsl.stub :removed? => true
          task.call
        end

        it 'does not call the block when removed' do
          expect(block).to_not have_received :call
        end

        it 'does not continue calling itself when removed' do
          # one time is initialize
          expect(display).to have_received(:timer_exec).exactly(1).times
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-4.0.0.pre1 spec/swt_shoes/animation_spec.rb