- Notifications
You must be signed in to change notification settings - Fork 34
/
Copy patharduino_installation_spec.rb
115 lines (100 loc) · 3.39 KB
/
arduino_installation_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
108
109
110
111
112
113
114
115
require"spec_helper"
require"pathname"
require"tmpdir"
require"os"
# test function for below, to avoid long lines
defbug_753_cmd(backend,config_file)
[
backend.binary_path.to_s,
"--config-file",
config_file.to_s,
"--verbose",
"config",
"dump"
]
end
defwith_tmp_file(desired_filename=nil)
Dir.mktmpdirdo |tdir|
config_dir=Pathname(tdir)
config_file=config_dir + (desired_filename || ArduinoCI::ArduinoBackend::CONFIG_FILE_NAME)
File.open(config_file,"w"){ |f| f.write("")}
yield(config_dir,config_file)
end
end
defconfig_success_msg(config_file)
config_file_str=OS.windows? ? ArduinoCI::Host.pathname_to_windows(config_file) : config_file
"Using config file: #{config_file_str}"
end
defconfig_fail_msg
"Config file not found, using default values"
end
RSpec.describeArduinoCI::ArduinoInstallationdo
nextifskip_ruby_tests
context"constants"do
it"Exposes desired backend version"do
expect(ArduinoCI::ArduinoInstallation::DESIRED_ARDUINO_CLI_VERSION).toeq("0.29.0")
end
end
context"autolocate"do
it"doesn't fail"do
ArduinoCI::ArduinoInstallation.autolocate
end
end
context"autolocate!"do
backend=ArduinoCI::ArduinoInstallation.autolocate!
it"doesn't fail"do
expect(backend.binary_path).not_tobenil
expect(backend.lib_dir).not_tobenil
end
end
context"force_install"do
it"Can redirect output"do
output=StringIO.new
output.rewind
expect(output.read.empty?).tobetrue
# install a bogus version to save time downloading
backend=ArduinoCI::ArduinoInstallation.force_install(output,"BOGUS VERSION")
output.rewind
expect(output.read.empty?).tobefalse
end
end
context"installed version-specific quirks"do
backend=ArduinoCI::ArduinoInstallation.autolocate!
# https://github.com/arduino/arduino-cli/issues/753
it"suffers from arduino-cli bug 753 - nonstandard filename"do
# foo.yml won't be accepted as a filename
with_tmp_file("foo.yml")do |config_dir,config_file|
expect(config_dir).toexist
expect(config_file).toexist
ret=ArduinoCI::Host.run_and_capture(*bug_753_cmd(backend,config_file))
ifbackend.should_use_config_dir?
expect(ret[:out].lines[0]).toinclude(config_fail_msg)
else
expect(ret[:out].lines[0]).toinclude(config_success_msg(config_file))
end
end
end
it"obeys arduino-cli bug 753 workaround"do
# the standard filename will work
with_tmp_filedo |config_dir,config_file|
expect(config_dir).toexist
expect(config_file).toexist
ret=ArduinoCI::Host.run_and_capture(*bug_753_cmd(backend,config_file))
expect(ret[:out].lines[0]).toinclude(config_success_msg(config_file))
end
end
it"obeys arduino-cli bug 753"do
# the directory alone will work if there is a file with the right name
with_tmp_filedo |config_dir,config_file|
expect(config_dir).toexist
expect(config_file).toexist
ret=ArduinoCI::Host.run_and_capture(*bug_753_cmd(backend,config_dir))
ifbackend.should_use_config_dir?
expect(ret[:out].lines[0]).toinclude(config_success_msg(config_file))
else
expect(ret[:out].lines[0]).toinclude(config_fail_msg)
end
end
end
end
end