Sha256: 7981eb9ea2493be7a317de5c5f296ff44e58d715d520d6080f1f5d74f6a73528

Contents?: true

Size: 2 KB

Versions: 8

Compression:

Stored size: 2 KB

Contents

require "spec_helper"

describe GoogleDistanceMatrix::Places do
  let(:values) { [{address: "one"}, {address: "two"}, {address: "three"}] }
  let(:places) { values.map { |v| GoogleDistanceMatrix::Place.new v } }

  let(:place_4) { GoogleDistanceMatrix::Place.new address: "four" }
  let(:place_5) { GoogleDistanceMatrix::Place.new address: "five" }
  let(:place_6) { GoogleDistanceMatrix::Place.new address: "six" }

  subject { described_class.new places }

  it { should include *places }
  it { should_not include 5 }


  %w[<< push unshift].each do |attr|
    describe "#{attr}" do
      it "adds value" do
        expect {
          subject.public_send attr, place_4
        }.to change { subject.include? place_4 }.to true
      end

      it "keeps uniq values" do
        subject.public_send attr, place_4

        expect {
          subject.public_send attr, place_4
        }.to_not change subject, :length
      end

      it "is chanable" do
        subject.public_send(attr, place_5).public_send(attr, place_6)

        expect(subject).to include place_5, place_6
      end

      it "wraps values in a Place" do
        subject.public_send attr, {address: "four"}

        expect(subject.all? { |place| place.is_a? GoogleDistanceMatrix::Place }).to be true
        expect(subject.any? { |place| place.address == "four" }).to be true
      end
    end
  end

  %w[push unshift].each do |attr|
    describe "#{attr}" do
      it "adds multiple values at once" do
        subject.public_send attr, place_4, place_5
        expect(subject).to include place_4, place_5
      end
    end
  end

  describe "#concat" do
    let(:places_2) { [place_4, place_5, place_6] }

    it "adds the given array" do
      subject.concat places_2
      expect(subject).to include *places_2
    end

    it "keeps values uniq" do
      subject.concat places_2

      expect {
        subject.concat places_2
      }.to_not change subject, :length
    end

    it "returns self" do
      expect(subject.concat places_2).to eq subject
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
google_distance_matrix-0.4.0 spec/lib/google_distance_matrix/places_spec.rb
google_distance_matrix-0.3.0 spec/lib/google_distance_matrix/places_spec.rb
google_distance_matrix-0.2.1 spec/lib/google_distance_matrix/places_spec.rb
google_distance_matrix-0.2.0 spec/lib/google_distance_matrix/places_spec.rb
google_distance_matrix-0.1.3 spec/lib/google_distance_matrix/places_spec.rb
google_distance_matrix-0.1.2 spec/lib/google_distance_matrix/places_spec.rb
google_distance_matrix-0.1.1 spec/lib/google_distance_matrix/places_spec.rb
google_distance_matrix-0.1.0 spec/lib/google_distance_matrix/places_spec.rb