Sha256: 5d655639fbd199de284f43045b3f2930c51db1aab32e9f497bf12ea0558e4ac0

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require "spec_helper"

describe YahooFinance::Historical do
  let(:ticker)     { "AAPL" }
  let(:start_date) { Date.new(2011, 11, 11) }
  let(:end_date)   { Date.new(2011, 11, 21) }

  shared_examples_for "a valid instance" do
    its(:ticker)     { should == ticker }
    its(:start_date) { should == start_date }
    its(:end_date)   { should == end_date }
    its(:group)      { should_not be_nil }
  end

  describe ".daily" do
    subject { described_class.daily ticker, :from => start_date, :to => end_date }
    it_behaves_like "a valid instance"
    its(:group) { should == YahooFinance::Historical::GROUPS[:daily] }
  end

  describe ".weekly" do
    subject { described_class.weekly ticker, :from => start_date, :to => end_date }
    it_behaves_like "a valid instance"
    its(:group) { should == YahooFinance::Historical::GROUPS[:weekly] }
  end

  describe ".monthly" do
    subject { described_class.monthly ticker, :from => start_date, :to => end_date }
    it_behaves_like "a valid instance"
    its(:group) { should == YahooFinance::Historical::GROUPS[:monthly] }
  end

  describe "#each" do
    subject { described_class.daily ticker, :from => start_date, :to => end_date }

    it "iterates by ascending date order" do
      subject.to_a.first.date.should < subject.to_a.last.date
    end

    context "when a period is specified" do
      it "returns only records after the start date" do
        subject.all? { |data| data.date >= start_date }.should be_true
      end

      it "returns only records until the end date" do
        subject.all? { |data| data.date <= end_date }.should be_true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yahoo_finance-0.0.1 spec/historical_spec.rb