Sha256: 51580e2538fd3c445bfbd5ae8fb004030a323db379ba1f05f52dcbb6160ab56d

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe Notu::Track do

  let(:track) { Notu::Track.new(artist: 'Serial Killaz', title: 'Good Enough') }

  describe '#artist' do

    it 'is value set at initialization' do
      expect(track.artist).to eq('Serial Killaz')
    end

    it 'is squished' do
      expect(Notu::Track.new(artist: 'Serial  Killaz  ', title: 'Good Enough').artist).to eq('Serial Killaz')
    end

    it 'raise an error if blank' do
      expect {
        Notu::Track.new(artist: ' ', title: 'Good Enough')
      }.to raise_error(Notu::Error, 'Notu::Track#artist must be specified, " " given')
    end

  end

  describe '#plays_count' do

    it 'is nil by default' do
      expect(track.plays_count).to be_nil
    end

    it 'can be specified' do
      expect(Notu::Track.new(artist: 'Serial Killaz', plays_count: 42, title: 'Good Enough').plays_count).to eq(42)
    end

    it 'can be specified (as string)' do
      expect(Notu::Track.new(artist: 'Serial Killaz', plays_count: '42', title: 'Good Enough').plays_count).to eq(42)
    end

    it 'is nil if invalid' do
      expect(Notu::Track.new(artist: 'Serial Killaz', plays_count: 'foo', title: 'Good Enough').plays_count).to be_nil
    end

    it 'is 0 if negatve' do
      expect(Notu::Track.new(artist: 'Serial Killaz', plays_count: -1, title: 'Good Enough').plays_count).to eq(0)
    end

  end

  describe '#title' do

    it 'is value set at initialization' do
      expect(track.title).to eq('Good Enough')
    end

    it 'is squished' do
      expect(Notu::Track.new(artist: 'Serial Killaz', title: '  Good  Enough').title).to eq('Good Enough')
    end

    it 'raise an error if blank' do
      expect {
        Notu::Track.new(artist: 'Serial Killaz', title: ' ')
      }.to raise_error(Notu::Error, 'Notu::Track#title must be specified, " " given')
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notu-0.1.1 spec/notu/track_spec.rb
notu-0.1.0 spec/notu/track_spec.rb