-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_controller_spec.rb
107 lines (84 loc) · 2.81 KB
/
main_controller_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'spec_helper'
describe Launchpad::MainController do
let(:patcher) { double 'patcher' }
let(:stage) { double 'stage', on_shown: true }
let(:status) { double 'status', set_text: nil }
before do
allow(Launchpad::Patcher).to receive(:new).and_return patcher
allow(subject).to receive(:status).and_return status
end
describe '#initialize' do
before { subject }
it 'sets up an patcher' do
expect(subject.patcher).to be patcher
end
it 'sets up the on_shown hook' do
expect(stage).to have_received :on_shown
end
end
describe '#scan' do
before do
allow(Launchpad::Patcher).to receive(:new).and_return patcher
subject.scan
end
context 'when files are in sync' do
let(:patcher) { double :patcher, in_sync?: true }
it 'displays a message that files are synced' do
expect(subject.status).to have_received(:set_text).with 'Ready'
end
end
context 'when files are out of sync' do
let(:patcher) { double :patcher, in_sync?: false }
it 'displays a message that there are files that need syncing' do
expect(subject.status)
.to have_received(:set_text).with 'Update required...'
end
end
end
describe '#show_options' do
let(:options_stage) { double 'stage' }
let(:stage_class) { described_class::Stage }
let(:messages) do
[:title=, :always_on_top=, :resizable=, :fxml=, :show, :x=, :y=]
end
before do
allow(stage_class).to receive(:new).and_return options_stage
messages.each { |message| allow(options_stage).to receive message }
[:x, :y].each do |axis|
allow(Launchpad::Application)
.to receive_message_chain(:main_stage, axis)
.and_return 5
end
subject.show_options
end
it 'assigns a new options stage' do
expect(subject.instance_variable_get :@options).to be options_stage
end
it 'uses the options controller for the stage' do
expect(options_stage).to have_received(:fxml=)
.with Launchpad::OptionsController
end
it 'sets the options stage attributes' do
options = { :title= => 'Options',
:always_on_top= => true,
:resizable= => false,
:x= => 25,
:y= => 45 }
options.each do |option, setting|
expect(options_stage).to have_received(option).with setting
end
end
it 'shows the options stage' do
expect(options_stage).to have_received :show
end
context 'when called more than once' do
before { subject.show_options }
it 'does not create a new stage every time' do
expect(stage_class).to have_received(:new).once
end
it 'calls show every time' do
expect(options_stage).to have_received(:show).twice
end
end
end
end