-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_controller_spec.rb
64 lines (52 loc) · 1.56 KB
/
options_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
require 'spec_helper'
describe Launchpad::OptionsController do
let(:options) do
[:install, :local_index_path, :remote_index_uri, :login_server, :port]
end
let(:text_fields) do
options.reduce({}) do |options, option|
option_double = double(
option.to_s.capitalize,
get_characters: "#{option} value",
set_text: nil)
options.merge(option => option_double)
end
end
before do
described_class::OPTIONS.each do |option|
allow(subject).to receive(option).and_return text_fields[option]
end
allow(Launchpad::Settings).tap do |settings|
settings.to receive(:read).and_return 'value'
settings.to receive(:update).and_return true
settings.to receive(:save).and_return true
end
end
describe '#accept' do
before { subject.accept }
it 'closes the stage' do
expect(stage).to have_received :close
end
it 'updates all settings with values from the form' do
options.each do |option|
expect(Launchpad::Settings).to have_received(:update)
.with(option, "#{option} value")
end
expect(Launchpad::Settings).to have_received :save
end
end
describe '#cancel' do
before { subject.cancel }
it 'closes the stage' do
expect(stage).to have_received :close
end
end
describe '#display_values' do
before { subject.display_values }
it 'fills in the ui fields with current setting values' do
options.each do |option|
expect(text_fields[option]).to have_received(:set_text).with 'value'
end
end
end
end