Sha256: a7ab81ca2f3a80e9ba322a5708e27353b5d213b6a17fb6d48a934cf147d20e44

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

# coding: utf-8
require 'spec_helper'

RSpec.describe Fest do
  describe '::Volume' do
    before(:each) do
      @fest = Fest.new
      params = YAML.load_file("#{GEM_ROOT}/config/default.yml")
      @step = params['step']
      @current_volume = eval(params['current_volume'].join('; '))
      @max_volume = params['max_volume']
      @min_volume = params['min_volume']
    end

    it '.include? Volume' do
      expect(@fest.class.included_modules.include?(Volume)).to be_truthy
    end

    it 'current volume eq volume?' do
      vol = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
      expect(@current_volume).to eq(vol)
    end

    it '#inputs' do
      inputs =
        `pactl list sink-inputs | grep '№' | grep -o '[0-9]*'`.split("\n")
      expect(@fest.sink_inputs).to match_array(inputs)
    end

    it '#check_optimal_volume' do
      vol = @current_volume - @current_volume / 10 * @step
      expect(@fest.check_optimal_volume).to eq(vol)
    end

    it '#optimize_volume' do
      if @current_volume > @max_volume
        expect(@fest.optimize_volume).to be < @current_volume
      elsif @current_volume < @min_volume
        expect(@fest.optimize_volume).to be > @current_volume
      else
        expect(@fest.optimize_volume).to eq(@current_volume)
      end
    end

    it '#change_volume down' do
      @fest.sink_inputs
      @fest.change_volume(
        @current_volume,
        @fest.check_optimal_volume,
        @step
      )

      current_volume = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
      vol = current_volume - current_volume / 10 * @step
      expect(@fest.check_optimal_volume).to eq(vol)
    end

    it '#change_volume up' do
      @fest.sink_inputs
      @fest.change_volume(
        @fest.check_optimal_volume,
        @current_volume,
        @step
      )

      current_volume = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
      vol = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
      expect(current_volume).to eq(vol)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fest-1.3.12 spec/volume_spec.rb
fest-1.3.11 spec/volume_spec.rb