This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
/
console_spec.rb
56 lines (46 loc) · 1.49 KB
/
console_spec.rb
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
require_relative '../../spec_helper'
require 'cli/console'
describe Cli::Console do
let(:subject) { Cli::Console.new }
before :each, 'setup spies' do
allow(subject).to receive(:print_warning)
allow(subject).to receive(:rebuild_cache)
allow(subject).to receive(:puts)
end
describe '#start' do
before :each, 'setup mocks' do
allow(subject).to receive(:prompt_for_input).and_return('exit')
allow(subject).to receive(:check_cache)
end
it 'should check the module cache' do
subject.start
expect(subject).to have_received(:check_cache).exactly(1).times
end
end
describe '#check_cache' do
context 'if the module cache is not valid' do
before(:each) do
allow(subject).to receive(:cache_valid?).and_return(false)
end
it 'should refresh the module cache' do
subject.check_cache
expect(subject).to have_received(:rebuild_cache).exactly(1).times
end
it 'should warn the user the cache is being refreshed' do
subject.check_cache
expect(subject).to have_received(:print_warning)
.with('Refreshing the module cache...')
end
end
context 'if the module cache is valid' do
before(:each) do
allow(subject).to receive(:cache_valid?).and_return(true)
end
it 'should not refresh the cache' do
subject.check_cache
expect(subject).to have_received(:rebuild_cache).exactly(0).times
end
end
end
end