require "spec_helper"

describe Cribbage::Scoring::Strategies::Flush do
  describe "#score" do
    context "with a hand" do
      let(:hand) { double 'hand', cards: cards, crib?: false }
      subject { described_class.new(hand, start_card) }

      context "when the four cards in the hand are the same suit" do
        let(:cards) do
          [
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?H)
          ]
        end

        context "when the start card is a different suit" do
          let(:start_card) { build(:card, suit: ?D) }

          it "returns 4" do
            expect(subject.score).to eq(4)
          end
        end

        context "when the start card is also the same suit" do
          let(:start_card) { build(:card, suit: ?H) }

          it "returns 5" do
            expect(subject.score).to eq(5)
          end
        end
      end

      context "when there are not four cards in the hand with the same suit" do
        let(:cards) do
          [
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?D)
          ]
        end
        let(:start_card) { build(:card) }

        it "returns 0" do
          expect(subject.score).to eq(0)
        end
      end
    end

    context "with a crib" do
      let(:crib) { double 'crib', cards: cards, crib?: true }
      subject { described_class.new(crib, start_card) }

      context "when the four cards in the hand are the same suit" do
        let(:cards) do
          [
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?H)
          ]
        end

        context "when the start card is a different suit" do
          let(:start_card) { build(:card, suit: ?D) }

          it "returns 4" do
            expect(subject.score).to eq(0)
          end
        end

        context "when the start card is also the same suit" do
          let(:start_card) { build(:card, suit: ?H) }

          it "returns 5" do
            expect(subject.score).to eq(5)
          end
        end
      end

      context "when there are not four cards in the hand with the same suit" do
        let(:cards) do
          [
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?H),
            build(:card, suit: ?D)
          ]
        end
        let(:start_card) { build(:card) }

        it "returns 0" do
          expect(subject.score).to eq(0)
        end
      end
    end
  end
end
