Sha256: ca49be58aaf8577f93a7530673fa278ca226238f7d8ca37154d5ca39bebfc4e5

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe Alephant::Preview::FixtureLoader do
  let (:fixtures_base) { File.join(File.dirname(__FILE__), 'fixtures') }
  let (:base_path) { File.join(fixtures_base, 'components', 'bar') }
  subject { described_class.new(base_path) }

  describe ".new" do

    context 'using valid parameters' do
      let (:expected) { described_class }

      specify { expect(subject).to be_a expected }
    end
  end

  describe "#get" do
    let (:uri) { '/test/uri' }

    context 'with a single fixture' do
      let (:fixture_data) { File.open(File.join(fixtures_base, 'components', 'bar', 'fixtures', 'bar.json')).read }
      specify { expect(subject.get(uri).body).to eq fixture_data}
    end

    context 'with multiple fixtures' do
      let (:base_path) { File.join(fixtures_base, 'components', 'baz') }
      let (:fixture_data) do
        fixtures = Dir.glob(File.join(fixtures_base, 'components', 'baz', 'fixtures', '*'))
        fixtures.map { |fixture| File.open(fixture).read }
      end

      context 'using a valid amount of fixtures' do

        it "should return each fixture on subsequent calls" do
          (0..2).each do |index|
            expect(subject.get(uri).body).to eq fixture_data[index]
          end
        end
      end

      context 'using incorrect amount of fixtures' do
        it "should raise an exception" do
          (0..2).each { |index| subject.get(uri).body }
          expect{ subject.get(uri).body }.to raise_error
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
alephant-preview-0.3.6 spec/fixture_loader_spec.rb
alephant-preview-0.3.5 spec/fixture_loader_spec.rb
alephant-preview-0.3.4 spec/fixture_loader_spec.rb
alephant-preview-0.3.3 spec/fixture_loader_spec.rb
alephant-preview-0.3.2 spec/fixture_loader_spec.rb
alephant-preview-0.3.1 spec/fixture_loader_spec.rb
alephant-preview-0.3.0 spec/fixture_loader_spec.rb