Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lazy_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 92907081867394086f8f94d002d46cc7dcc36543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Lazy do
  let(:dummy) { double(:dummy) }

  context 'when not calling any methods' do
    it 'does not call the supplied block' do
      expect(dummy).not_to receive(:foo)

      described_class.new { dummy.foo }
    end
  end

  context 'when calling a method on the object' do
    it 'lazy loads the value returned by the block' do
      expect(dummy).to receive(:foo).and_return('foo')

      lazy = described_class.new { dummy.foo }

      expect(lazy.to_s).to eq('foo')
    end
  end

  describe '#respond_to?' do
    it 'returns true for a method defined on the wrapped object' do
      lazy = described_class.new { 'foo' }

      expect(lazy).to respond_to(:downcase)
    end

    it 'returns false for a method not defined on the wrapped object' do
      lazy = described_class.new { 'foo' }

      expect(lazy).not_to respond_to(:quack)
    end
  end
end