Sha256: 9c2674c5c77c5c5423e9d5f4908a50eebba3af1227a69595c6ca34e0ec59839c

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

describe Date do

  describe '#in_time_zone' do

    subject { Date.new }

    before do
      stub_const('Date', Class.new)
      Date.any_instance.stub(:to_time_in_current_zone)
    end

    context 'when #in_time_zone is already defined' do
      before do
        Date.any_instance.should_receive(:in_time_zone)
      end

      context 'when ByStar::Kernel::Date included' do
        before do
          ::Date.__send__(:include, ByStar::Kernel::Date)
        end

        it 'should not be aliased to #to_time_in_current_zone' do
          subject.should_not_receive(:to_time_in_current_zone)
          subject.in_time_zone
        end
      end

      context 'when ByStar::Kernel::Date not included' do

        it 'should not be aliased to #to_time_in_current_zone' do
          subject.should_not_receive(:to_time_in_current_zone)
          subject.in_time_zone
        end
      end
    end

    context 'when #in_time_zone is not defined' do

      context 'when ByStar::Kernel::Date included' do
        before do
          ::Date.__send__(:include, ByStar::Kernel::Date)
        end

        it 'should be aliased to #to_time_in_current_zone' do
          subject.should_receive(:to_time_in_current_zone)
          subject.in_time_zone
        end
      end

      context 'when ByStar::Kernel::Date not included' do

        it 'should raise NoMethodError' do
          ->{ subject.in_time_zone }.should raise_error(NoMethodError)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
by_star-2.2.1 spec/unit/kernel_date_spec.rb