vatsim_online_redux 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +120 -0
- data/CONTRIBUTING.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE +23 -0
- data/README.md +478 -0
- data/Rakefile +7 -0
- data/lib/vatsim_online/callsign_parser.rb +54 -0
- data/lib/vatsim_online/data_downloader.rb +134 -0
- data/lib/vatsim_online/station.rb +92 -0
- data/lib/vatsim_online/station_parser.rb +77 -0
- data/lib/vatsim_online/version.rb +3 -0
- data/lib/vatsim_online.rb +24 -0
- data/spec/callsign_parser_spec.rb +29 -0
- data/spec/callsign_parser_spec_helper.rb +10 -0
- data/spec/data_downloader_spec.rb +105 -0
- data/spec/data_downloader_spec_helper.rb +8 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/station_parser_spec.rb +161 -0
- data/spec/station_parser_spec_helper.rb +10 -0
- data/spec/vatsim_data.txt +515 -0
- data/spec/vatsim_online_spec.rb +157 -0
- data/spec/vatsim_online_spec_helper.rb +10 -0
- data/vatsim_online_redux.gemspec +25 -0
- metadata +172 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
module VatsimTools
|
2
|
+
|
3
|
+
class CallsignParser
|
4
|
+
|
5
|
+
%w{tmpdir csv}.each { |lib| require lib }
|
6
|
+
require_relative "data_downloader"
|
7
|
+
require_relative "station"
|
8
|
+
|
9
|
+
attributes = %w{role callsign gcmap_width gcmap_height}
|
10
|
+
attributes.each {|attribute| attr_accessor attribute.to_sym }
|
11
|
+
|
12
|
+
LOCAL_DATA = "#{Dir.tmpdir}/vatsim_online/vatsim_data.txt"
|
13
|
+
|
14
|
+
def initialize(callsign, args = nil)
|
15
|
+
VatsimTools::DataDownloader.new
|
16
|
+
# args.class == Hash ? @role = determine_role(args) : @role = "all"
|
17
|
+
@callsign = callsign.upcase.split(',').each {|s| s.strip!}
|
18
|
+
# @excluded = args[:exclude].upcase if args && args[:exclude]
|
19
|
+
@gcmap_width = args[:gcmap_width] if args && args[:gcmap_width]
|
20
|
+
@gcmap_height = args[:gcmap_height] if args && args[:gcmap_height]
|
21
|
+
end
|
22
|
+
|
23
|
+
# def determine_role(args)
|
24
|
+
# args[:atc] == false ? role = "pilot" : role = "all"
|
25
|
+
# args[:pilots] == false ? role = "atc" : role = role
|
26
|
+
# role = "all" if args[:pilots] == false && args[:atc] == false
|
27
|
+
# role
|
28
|
+
# end
|
29
|
+
|
30
|
+
|
31
|
+
def stations
|
32
|
+
stations = []
|
33
|
+
CSV.foreach(LOCAL_DATA, :col_sep =>':') do |row|
|
34
|
+
callsign, origin, destination, client = row[0].to_s, row[11].to_s, row[13].to_s, row[3].to_s
|
35
|
+
for cs in @callsign
|
36
|
+
stations << row if callsign[0...cs.length] == cs # && client == "ATC") unless @role == "pilot"
|
37
|
+
# stations << row if (origin[0...icao.length] == icao || destination[0...icao.length] == icao) unless @role == "atc"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
stations
|
41
|
+
end
|
42
|
+
|
43
|
+
def station_objects
|
44
|
+
station_objects= []
|
45
|
+
args = {}
|
46
|
+
args[:gcmap_width] = @gcmap_width if @gcmap_width
|
47
|
+
args[:gcmap_height] = @gcmap_height if @gcmap_height
|
48
|
+
stations.each {|station| station_objects << VatsimTools::Station.new(station, args) }
|
49
|
+
station_objects
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
module VatsimTools
|
2
|
+
require 'tempfile'
|
3
|
+
require 'time_diff'
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'net/http'
|
6
|
+
require 'fileutils'
|
7
|
+
class DataDownloader
|
8
|
+
|
9
|
+
STATUS_URL = "http://status.vatsim.net/status.txt"
|
10
|
+
TEMP_DIR = "#{Dir.tmpdir}/vatsim_online"
|
11
|
+
LOCAL_STATUS = "#{Dir.tmpdir}/vatsim_online/vatsim_status.txt"
|
12
|
+
LOCAL_STATUS_BAK = "#{Dir.tmpdir}/vatsim_online/vatsim_status_bak.txt"
|
13
|
+
LOCAL_DATA = "#{Dir.tmpdir}/vatsim_online/vatsim_data.txt"
|
14
|
+
LOCAL_DATA_BAK = "#{Dir.tmpdir}/vatsim_online/vatsim_data_bak.txt"
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
FileUtils.mkdir(TEMP_DIR) unless File.exist? TEMP_DIR
|
18
|
+
data_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_status_tempfile
|
22
|
+
uri = URI(STATUS_URL)
|
23
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
24
|
+
request = Net::HTTP::Get.new(uri.path)
|
25
|
+
data = http.request(request).body.gsub("\n", '')
|
26
|
+
create_status_backup if File.exists?(LOCAL_STATUS)
|
27
|
+
status = Tempfile.new('vatsim_status')
|
28
|
+
status.close
|
29
|
+
File.rename status.path, LOCAL_STATUS
|
30
|
+
File.write(LOCAL_STATUS, data)
|
31
|
+
File.chmod(0777, LOCAL_STATUS)
|
32
|
+
dummy_status if data.include? "<html><head>"
|
33
|
+
rescue Exception => e
|
34
|
+
dummy_status
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_status_backup
|
38
|
+
source = LOCAL_STATUS
|
39
|
+
target = LOCAL_STATUS_BAK
|
40
|
+
FileUtils.cp_r source, target
|
41
|
+
File.chmod(0777, LOCAL_STATUS_BAK)
|
42
|
+
end
|
43
|
+
|
44
|
+
def read_status_tempfile
|
45
|
+
status = File.open(LOCAL_STATUS)
|
46
|
+
difference = Time.diff(status.ctime, Time.now)[:hour]
|
47
|
+
if difference > 3
|
48
|
+
data = create_status_tempfile
|
49
|
+
else
|
50
|
+
data = status.read
|
51
|
+
end
|
52
|
+
status.close
|
53
|
+
data
|
54
|
+
end
|
55
|
+
|
56
|
+
def status_file
|
57
|
+
File.exists?(LOCAL_STATUS) ? read_status_tempfile : create_status_tempfile
|
58
|
+
LOCAL_STATUS
|
59
|
+
end
|
60
|
+
|
61
|
+
def servers
|
62
|
+
urls = []
|
63
|
+
CSV.foreach(status_file, :col_sep =>'=') do |row|
|
64
|
+
urls << row[1] if row[0] == "url0"
|
65
|
+
end
|
66
|
+
urls
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_local_data_file
|
70
|
+
uri = URI(servers.sample)
|
71
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
72
|
+
request = Net::HTTP::Get.new(uri.path)
|
73
|
+
req_data = http.request(request).body
|
74
|
+
create_data_backup if File.exists?(LOCAL_DATA)
|
75
|
+
data = Tempfile.new('vatsim_data', :encoding => 'utf-8')
|
76
|
+
data.close
|
77
|
+
File.rename data.path, LOCAL_DATA
|
78
|
+
data = req_data.gsub(/["]/, '\s').encode!('UTF-16', 'UTF-8', :invalid => :replace, :replace => '').encode!('UTF-8', 'UTF-16')
|
79
|
+
data = data.slice(0..(data.index('!PREFILE:')))
|
80
|
+
File.open(LOCAL_DATA, "w+") {|f| f.write(data)}
|
81
|
+
File.chmod(0777, LOCAL_DATA)
|
82
|
+
gem_data_file if req_data.include? "<html><head>"
|
83
|
+
file = File.open(LOCAL_DATA)
|
84
|
+
gem_data_file if file.size == 0
|
85
|
+
file.close
|
86
|
+
rescue Exception => e
|
87
|
+
gem_data_file
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_data_backup
|
91
|
+
source = LOCAL_DATA
|
92
|
+
target = LOCAL_DATA_BAK
|
93
|
+
FileUtils.cp_r source, target
|
94
|
+
File.chmod(0777, LOCAL_DATA_BAK)
|
95
|
+
end
|
96
|
+
|
97
|
+
def read_local_datafile
|
98
|
+
data = File.open(LOCAL_DATA)
|
99
|
+
difference = Time.diff(data.ctime, Time.now)[:minute]
|
100
|
+
difference > 2 ? create_local_data_file : data.read
|
101
|
+
if difference > 2
|
102
|
+
d = create_local_data_file
|
103
|
+
else
|
104
|
+
d = data.read
|
105
|
+
end
|
106
|
+
data.close
|
107
|
+
d
|
108
|
+
end
|
109
|
+
|
110
|
+
def data_file
|
111
|
+
File.exists?(LOCAL_DATA) ? read_local_datafile : create_local_data_file
|
112
|
+
LOCAL_DATA
|
113
|
+
end
|
114
|
+
|
115
|
+
def gem_data_file
|
116
|
+
source = LOCAL_DATA_BAK
|
117
|
+
target = LOCAL_DATA
|
118
|
+
FileUtils.cp_r source, target
|
119
|
+
File.chmod(0777, LOCAL_DATA)
|
120
|
+
end
|
121
|
+
|
122
|
+
def dummy_status
|
123
|
+
source = LOCAL_STATUS_BAK
|
124
|
+
target = LOCAL_STATUS
|
125
|
+
FileUtils.cp_r source, target
|
126
|
+
File.chmod(0777, LOCAL_STATUS)
|
127
|
+
end
|
128
|
+
def get_data(url)
|
129
|
+
uri = URI(url)
|
130
|
+
Net::HTTP.get(uri)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module VatsimTools
|
3
|
+
class Station
|
4
|
+
require "gcmapper"
|
5
|
+
|
6
|
+
attributes = %w{callsign name role frequency altitude groundspeed aircraft
|
7
|
+
origin destination rating facility remarks route atis logon latitude longitude
|
8
|
+
planned_altitude transponder heading qnh_in qnh_mb flight_type cid gcmap
|
9
|
+
latitude_humanized longitude_humanized online_since gcmap_width gcmap_height
|
10
|
+
atis_message}
|
11
|
+
attributes.each {|attribute| attr_accessor attribute.to_sym }
|
12
|
+
|
13
|
+
def initialize(station, args = nil)
|
14
|
+
|
15
|
+
@callsign, @cid, @name, @role, @frequency, @latitude, @longitude, @altitude, @groundspeed, @aircraft, @origin,
|
16
|
+
@planned_altitude, @destination, @transponder, @facility, @flight_type, @remarks, @route, @logon, @heading,
|
17
|
+
@qnh_in, @qnh_mb = station[0], station[1], station[2], station[3], station[4], station[5], station[6], station[7],
|
18
|
+
station[8], station[9], station[11], station[12], station[13], station[17], station[18], station[21], station[29],
|
19
|
+
station[30], station[37], station[38], station[39], station[40]
|
20
|
+
|
21
|
+
@atis = atis_cleaner(station[35]) if station[35]
|
22
|
+
@rating = humanized_rating(station[16])
|
23
|
+
@latitude_humanized = latitude_parser(station[5].to_f)
|
24
|
+
@longitude_humanized = longitude_parser(station[6].to_f)
|
25
|
+
@online_since = utc_logon_time if @logon
|
26
|
+
@gcmap_width = args[:gcmap_width].to_i if args && args[:gcmap_width]
|
27
|
+
@gcmap_height = args[:gcmap_height].to_i if args && args[:gcmap_height]
|
28
|
+
@gcmap = gcmap_generator
|
29
|
+
@atis_message = construct_atis_message(station[35]) if station[35]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def gcmap_generator
|
35
|
+
return "No map for ATC stations" if @role != "PILOT"
|
36
|
+
construct_gcmap_url.gcmap(:width => @gcmap_width, :height => @gcmap_height)
|
37
|
+
end
|
38
|
+
|
39
|
+
def construct_gcmap_url
|
40
|
+
if @origin && @latitude_humanized && @longitude_humanized && @destination
|
41
|
+
route = @origin.to_s + "-" + @latitude_humanized.to_s + "+" + @longitude_humanized.to_s + "-" + @destination.to_s
|
42
|
+
route += "%2C+\"" + @callsign.to_s + "%5Cn" + @altitude.to_s + "+ft%5Cn" + @groundspeed.to_s + "+kts"
|
43
|
+
route += "\"%2B%40" + @latitude_humanized.to_s + "+" + @longitude_humanized.to_s
|
44
|
+
else
|
45
|
+
route = "Position undetermined"
|
46
|
+
end
|
47
|
+
route
|
48
|
+
end
|
49
|
+
|
50
|
+
def latitude_parser(lat)
|
51
|
+
lat > 0 ? hemisphere = "N" : hemisphere = "S"
|
52
|
+
hemisphere + lat.abs.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def longitude_parser(lon)
|
56
|
+
lon > 0 ? hemisphere = "E" : hemisphere = "W"
|
57
|
+
hemisphere + lon.abs.to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
def atis_cleaner(raw_atis)
|
61
|
+
raw_atis.gsub(/[\^]/, '. ')
|
62
|
+
end
|
63
|
+
|
64
|
+
def utc_logon_time
|
65
|
+
Time.parse ("#{@logon[0...4]}-#{@logon[4...6]}-#{@logon[6...8]} #{@logon[8...10]}:#{@logon[10...12]}:#{@logon[12...14]} UTC")
|
66
|
+
end
|
67
|
+
|
68
|
+
def humanized_rating(rating_number)
|
69
|
+
case rating_number
|
70
|
+
when "0" then "Suspended"
|
71
|
+
when "1" then "OBS"
|
72
|
+
when "2" then "S1"
|
73
|
+
when "3" then "S2"
|
74
|
+
when "4" then "S3"
|
75
|
+
when "5" then "C1"
|
76
|
+
when "7" then "C3"
|
77
|
+
when "8" then "INS"
|
78
|
+
when "10" then "INS+"
|
79
|
+
when "11" then "Supervisor"
|
80
|
+
when "12" then "Administrator"
|
81
|
+
else
|
82
|
+
"UNK"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def construct_atis_message(raw_atis)
|
87
|
+
message = raw_atis.gsub(/[\^]/, '<br />')
|
88
|
+
message.index('>') ? message = message[message.index('>')+1...message.length] : message = "No published remark"
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module VatsimTools
|
2
|
+
|
3
|
+
class StationParser
|
4
|
+
|
5
|
+
%w{tmpdir csv}.each { |lib| require lib }
|
6
|
+
require_relative "data_downloader"
|
7
|
+
require_relative "station"
|
8
|
+
|
9
|
+
attributes = %w{role icao excluded gcmap_width gcmap_height}
|
10
|
+
attributes.each {|attribute| attr_accessor attribute.to_sym }
|
11
|
+
|
12
|
+
LOCAL_DATA = "#{Dir.tmpdir}/vatsim_online/vatsim_data.txt"
|
13
|
+
|
14
|
+
def initialize(icao, args = nil)
|
15
|
+
VatsimTools::DataDownloader.new
|
16
|
+
args.class == Hash ? @role = determine_role(args) : @role = "all"
|
17
|
+
if icao == "ALL"
|
18
|
+
@icao = nil
|
19
|
+
else
|
20
|
+
@icao = icao.upcase.split(',').each {|s| s.strip!}
|
21
|
+
end
|
22
|
+
@excluded = args[:exclude].upcase if args && args[:exclude]
|
23
|
+
@gcmap_width = args[:gcmap_width] if args && args[:gcmap_width]
|
24
|
+
@gcmap_height = args[:gcmap_height] if args && args[:gcmap_height]
|
25
|
+
end
|
26
|
+
|
27
|
+
def determine_role(args)
|
28
|
+
args[:atc] == false ? role = "pilot" : role = "all"
|
29
|
+
args[:pilots] == false ? role = "atc" : role = role
|
30
|
+
role = "all" if args[:pilots] == false && args[:atc] == false
|
31
|
+
role
|
32
|
+
end
|
33
|
+
|
34
|
+
def stations
|
35
|
+
stations = []
|
36
|
+
CSV.foreach(LOCAL_DATA, :col_sep =>':') do |row|
|
37
|
+
callsign, origin, destination, client = row[0].to_s, row[11].to_s, row[13].to_s, row[3].to_s
|
38
|
+
unless @icao
|
39
|
+
stations << row if (client == "ATC") unless @role == "pilot"
|
40
|
+
stations << row if (client == "PILOT") unless @role == "atc"
|
41
|
+
else
|
42
|
+
for icao in @icao
|
43
|
+
stations << row if (callsign[0...icao.length] == icao && client == "ATC") unless @role == "pilot"
|
44
|
+
stations << row if (origin[0...icao.length] == icao || destination[0...icao.length] == icao) unless @role == "atc"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
stations
|
49
|
+
end
|
50
|
+
|
51
|
+
def station_objects
|
52
|
+
station_objects= []
|
53
|
+
args = {}
|
54
|
+
args[:gcmap_width] = @gcmap_width if @gcmap_width
|
55
|
+
args[:gcmap_height] = @gcmap_height if @gcmap_height
|
56
|
+
stations.each {|station| station_objects << VatsimTools::Station.new(station, args) }
|
57
|
+
station_objects
|
58
|
+
end
|
59
|
+
|
60
|
+
def sorted_station_objects
|
61
|
+
atc = []; pilots = []; arrivals = []; departures = []
|
62
|
+
station_objects.each {|sobj| sobj.role == "ATC" ? atc << sobj : pilots << sobj}
|
63
|
+
if @icao
|
64
|
+
for icao in @icao
|
65
|
+
for pilot in pilots
|
66
|
+
departures << pilot if pilot.origin[0...icao.length] == icao
|
67
|
+
arrivals << pilot if pilot.destination[0...icao.length] == icao
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
atc.delete_if {|a| @excluded && a.callsign[0...@excluded.length] == @excluded }
|
72
|
+
{:atc => atc, :pilots => pilots, :arrivals => arrivals, :departures => departures}
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
%w{vatsim_online/version vatsim_online/station vatsim_online/data_downloader
|
2
|
+
vatsim_online/station_parser vatsim_online/callsign_parser}.each { |lib| require lib }
|
3
|
+
|
4
|
+
class String
|
5
|
+
def vatsim_online(args={})
|
6
|
+
VatsimOnline.vatsim_online(self, args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def vatsim_callsign(args={})
|
10
|
+
VatsimOnline.vatsim_callsign(self, args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module VatsimOnline
|
15
|
+
|
16
|
+
def self.vatsim_online(icao, args)
|
17
|
+
VatsimTools::StationParser.new(icao,args).sorted_station_objects
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.vatsim_callsign(callsign, args)
|
21
|
+
VatsimTools::CallsignParser.new(callsign,args).station_objects
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'vatsim_online'
|
2
|
+
require 'callsign_parser_spec_helper.rb'
|
3
|
+
|
4
|
+
describe VatsimTools::CallsignParser do
|
5
|
+
|
6
|
+
target = VatsimTools::CallsignParser
|
7
|
+
|
8
|
+
describe "stations" do
|
9
|
+
it "should return an expected result" do
|
10
|
+
gem_data_file
|
11
|
+
callsign = "WMKK"
|
12
|
+
target.new(callsign).stations.first[0].should eq("WMKK_APP")
|
13
|
+
target.new(callsign).stations.class.should eq(Array)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "station_objects" do
|
18
|
+
it "should return an array of Station objects" do
|
19
|
+
gem_data_file
|
20
|
+
callsign = "LO"
|
21
|
+
target.new(callsign).station_objects.class.should eq(Array)
|
22
|
+
target.new(callsign).station_objects.size.should eq(2)
|
23
|
+
target.new(callsign).station_objects.first.class.should eq(VatsimTools::Station)
|
24
|
+
target.new(callsign).station_objects.first.callsign.should eq("LOT282")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
def gem_data_file
|
2
|
+
path = File.realpath("spec/vatsim_data.txt")
|
3
|
+
data_file = File.open(path, :encoding => 'iso-8859-15')
|
4
|
+
gem_data = data_file.read
|
5
|
+
data_file.close
|
6
|
+
data = Tempfile.new('vatsim_data', :encoding => 'iso-8859-15')
|
7
|
+
data.write(gem_data.gsub(/["]/, '\s').force_encoding('iso-8859-15'))
|
8
|
+
data.close
|
9
|
+
File.rename data.path, "#{Dir.tmpdir}/vatsim_data.txt"
|
10
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
require 'data_downloader_spec_helper.rb'
|
3
|
+
|
4
|
+
describe VatsimTools::DataDownloader do
|
5
|
+
|
6
|
+
target = VatsimTools::DataDownloader
|
7
|
+
LOCAL_STATUS = "#{Dir.tmpdir}/vatsim_status.txt"
|
8
|
+
LOCAL_DATA = "#{Dir.tmpdir}/vatsim_data.txt"
|
9
|
+
|
10
|
+
describe "create_status_tempfile" do
|
11
|
+
it "should create a file" do
|
12
|
+
delete_local_files
|
13
|
+
File.exists?(LOCAL_STATUS).should be false
|
14
|
+
target.new.create_status_tempfile
|
15
|
+
File.exists?(LOCAL_STATUS).should be true
|
16
|
+
status = File.open(LOCAL_STATUS)
|
17
|
+
status.path.should eq("#{Dir.tmpdir}/vatsim_status.txt")
|
18
|
+
status.size.should be > 100
|
19
|
+
status.close
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "read_status_tempfile" do
|
24
|
+
it "should confirm a file exists" do
|
25
|
+
target.new.read_status_tempfile
|
26
|
+
File.exists?(LOCAL_STATUS).should be true
|
27
|
+
status = File.open(LOCAL_STATUS)
|
28
|
+
status.size.should be > 100
|
29
|
+
status.close
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "status_file" do
|
34
|
+
it "should return status.txt path" do
|
35
|
+
delete_local_files
|
36
|
+
File.exists?(LOCAL_STATUS).should be false
|
37
|
+
target.new.status_file.class.should eq(String)
|
38
|
+
target.new.status_file.should include("vatsim_status.txt")
|
39
|
+
target.new.status_file.should eq(LOCAL_STATUS)
|
40
|
+
target.new.status_file.should eq("#{Dir.tmpdir}/vatsim_status.txt")
|
41
|
+
File.exists?(LOCAL_STATUS).should be true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "servers" do
|
46
|
+
it "should contain an array of server URLs" do
|
47
|
+
File.exists?(LOCAL_STATUS).should be true
|
48
|
+
target.new.servers.class.should eq(Array)
|
49
|
+
target.new.servers.size.should eq(5)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "create_local_data_file" do
|
54
|
+
it "should confirm a file exists" do
|
55
|
+
delete_local_files
|
56
|
+
File.exists?(LOCAL_DATA).should be false
|
57
|
+
target.new.create_local_data_file
|
58
|
+
File.exists?(LOCAL_DATA).should be true
|
59
|
+
data = File.open(LOCAL_DATA)
|
60
|
+
data.path.should eq("#{Dir.tmpdir}/vatsim_data.txt")
|
61
|
+
data.size.should be > 100
|
62
|
+
data.close
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "read_local_datafile" do
|
67
|
+
it "should confirm a file exists" do
|
68
|
+
target.new.read_local_datafile
|
69
|
+
File.exists?(LOCAL_DATA).should be true
|
70
|
+
data = File.open(LOCAL_DATA)
|
71
|
+
data.size.should be > 100
|
72
|
+
data.close
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "data_file" do
|
77
|
+
it "should contain file path" do
|
78
|
+
delete_local_files
|
79
|
+
File.exists?(LOCAL_DATA).should be false
|
80
|
+
target.new.data_file.class.should eq(String)
|
81
|
+
target.new.data_file.should include("vatsim_data.txt")
|
82
|
+
target.new.data_file.should eq(LOCAL_DATA)
|
83
|
+
target.new.data_file.should eq("#{Dir.tmpdir}/vatsim_data.txt")
|
84
|
+
File.exists?(LOCAL_DATA).should be true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "new" do
|
89
|
+
it "should return" do
|
90
|
+
delete_local_files
|
91
|
+
File.exists?(LOCAL_DATA).should be false
|
92
|
+
File.exists?(LOCAL_STATUS).should be false
|
93
|
+
target.new
|
94
|
+
File.exists?(LOCAL_DATA).should be true
|
95
|
+
File.exists?(LOCAL_STATUS).should be true
|
96
|
+
data = File.open(LOCAL_DATA)
|
97
|
+
status = File.open(LOCAL_DATA)
|
98
|
+
data.size.should be > 100
|
99
|
+
status.size.should be > 100
|
100
|
+
status.close
|
101
|
+
data.close
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'vatsim_online'
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
8
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
9
|
+
# files.
|
10
|
+
#
|
11
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
12
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
13
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
14
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
15
|
+
# a separate helper file that requires the additional dependencies and performs
|
16
|
+
# the additional setup, and require it from the spec files that actually need
|
17
|
+
# it.
|
18
|
+
#
|
19
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
20
|
+
RSpec.configure do |config|
|
21
|
+
# rspec-expectations config goes here. You can use an alternate
|
22
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
23
|
+
# assertions if you prefer.
|
24
|
+
config.expect_with :rspec do |expectations|
|
25
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
26
|
+
# and `failure_message` of custom matchers include text for helper methods
|
27
|
+
# defined using `chain`, e.g.:
|
28
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
29
|
+
# # => "be bigger than 2 and smaller than 4"
|
30
|
+
# ...rather than:
|
31
|
+
# # => "be bigger than 2"
|
32
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
36
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
37
|
+
config.mock_with :rspec do |mocks|
|
38
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
39
|
+
# a real object. This is generally recommended, and will default to
|
40
|
+
# `true` in RSpec 4.
|
41
|
+
mocks.verify_partial_doubles = true
|
42
|
+
end
|
43
|
+
|
44
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
45
|
+
# have no way to turn it off -- the option exists only for backwards
|
46
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
47
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
48
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
49
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
50
|
+
|
51
|
+
# The settings below are suggested to provide a good initial experience
|
52
|
+
# with RSpec, but feel free to customize to your heart's content.
|
53
|
+
=begin
|
54
|
+
# This allows you to limit a spec run to individual examples or groups
|
55
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
56
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
57
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
58
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
59
|
+
config.filter_run_when_matching :focus
|
60
|
+
|
61
|
+
# Allows RSpec to persist some state between runs in order to support
|
62
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
63
|
+
# you configure your source control system to ignore this file.
|
64
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
65
|
+
|
66
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
67
|
+
# recommended. For more details, see:
|
68
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
69
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
70
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
71
|
+
config.disable_monkey_patching!
|
72
|
+
|
73
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
74
|
+
# be too noisy due to issues in dependencies.
|
75
|
+
config.warnings = true
|
76
|
+
|
77
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
78
|
+
# file, and it's useful to allow more verbose output when running an
|
79
|
+
# individual spec file.
|
80
|
+
if config.files_to_run.one?
|
81
|
+
# Use the documentation formatter for detailed output,
|
82
|
+
# unless a formatter has already been configured
|
83
|
+
# (e.g. via a command-line flag).
|
84
|
+
config.default_formatter = "doc"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Print the 10 slowest examples and example groups at the
|
88
|
+
# end of the spec run, to help surface which specs are running
|
89
|
+
# particularly slow.
|
90
|
+
config.profile_examples = 10
|
91
|
+
|
92
|
+
# Run specs in random order to surface order dependencies. If you find an
|
93
|
+
# order dependency and want to debug it, you can fix the order by providing
|
94
|
+
# the seed, which is printed after each run.
|
95
|
+
# --seed 1234
|
96
|
+
config.order = :random
|
97
|
+
|
98
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
99
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
100
|
+
# test failures related to randomization by passing the same `--seed` value
|
101
|
+
# as the one that triggered the failure.
|
102
|
+
Kernel.srand config.seed
|
103
|
+
=end
|
104
|
+
end
|