spout 0.12.1 → 0.13.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +5 -5
- data/Rakefile +4 -4
- data/bin/spout +1 -1
- data/lib/spout/commands/coverage.rb +18 -18
- data/lib/spout/commands/deploy.rb +89 -89
- data/lib/spout/commands/exporter.rb +16 -16
- data/lib/spout/commands/graphs.rb +37 -37
- data/lib/spout/commands/help.rb +1 -1
- data/lib/spout/commands/importer.rb +59 -57
- data/lib/spout/commands/outliers.rb +17 -17
- data/lib/spout/commands/project_generator.rb +25 -25
- data/lib/spout/commands/update.rb +38 -38
- data/lib/spout/helpers/array_statistics.rb +7 -7
- data/lib/spout/helpers/chart_types.rb +2 -2
- data/lib/spout/helpers/config_reader.rb +21 -20
- data/lib/spout/helpers/framework.rb +11 -11
- data/lib/spout/helpers/iterators.rb +1 -3
- data/lib/spout/helpers/json_loader.rb +2 -4
- data/lib/spout/helpers/json_request.rb +11 -11
- data/lib/spout/helpers/number_helper.rb +1 -1
- data/lib/spout/helpers/quietly.rb +1 -1
- data/lib/spout/helpers/semantic.rb +1 -1
- data/lib/spout/helpers/send_file.rb +14 -14
- data/lib/spout/helpers/subject_loader.rb +24 -24
- data/lib/spout/helpers/table_formatting.rb +12 -12
- data/lib/spout/models/coverage_result.rb +8 -8
- data/lib/spout/models/dictionary.rb +10 -10
- data/lib/spout/models/domain.rb +7 -7
- data/lib/spout/models/empty.rb +1 -1
- data/lib/spout/models/form.rb +6 -6
- data/lib/spout/models/graphables/choices_vs_choices.rb +3 -5
- data/lib/spout/models/graphables/choices_vs_numeric.rb +4 -6
- data/lib/spout/models/graphables/default.rb +6 -6
- data/lib/spout/models/graphables/histogram.rb +4 -4
- data/lib/spout/models/graphables/numeric_vs_choices.rb +1 -1
- data/lib/spout/models/graphables/numeric_vs_numeric.rb +6 -6
- data/lib/spout/models/graphables.rb +14 -14
- data/lib/spout/models/outlier_result.rb +16 -18
- data/lib/spout/models/record.rb +3 -3
- data/lib/spout/models/tables/choices_vs_choices.rb +11 -11
- data/lib/spout/models/tables/choices_vs_numeric.rb +8 -8
- data/lib/spout/models/tables/default.rb +5 -5
- data/lib/spout/models/tables/numeric_vs_choices.rb +7 -7
- data/lib/spout/models/tables/numeric_vs_numeric.rb +7 -7
- data/lib/spout/models/tables.rb +11 -11
- data/lib/spout/models/variable.rb +14 -14
- data/lib/spout/tasks/engine.rake +4 -4
- data/lib/spout/templates/CHANGELOG.md.erb +1 -1
- data/lib/spout/templates/Gemfile +2 -2
- data/lib/spout/templates/Rakefile +1 -1
- data/lib/spout/templates/test/dictionary_test.rb +3 -3
- data/lib/spout/templates/test/test_helper.rb +1 -1
- data/lib/spout/tests/domain_existence_validation.rb +6 -6
- data/lib/spout/tests/domain_format.rb +1 -1
- data/lib/spout/tests/domain_name_format.rb +3 -3
- data/lib/spout/tests/domain_name_uniqueness.rb +2 -2
- data/lib/spout/tests/domain_specified.rb +1 -3
- data/lib/spout/tests/form_existence_validation.rb +2 -4
- data/lib/spout/tests/form_name_format.rb +3 -3
- data/lib/spout/tests/form_name_match.rb +1 -1
- data/lib/spout/tests/json_helper.rb +1 -1
- data/lib/spout/tests/json_validation.rb +0 -2
- data/lib/spout/tests/variable_name_format.rb +3 -3
- data/lib/spout/tests/variable_name_match.rb +1 -3
- data/lib/spout/tests/variable_name_uniqueness.rb +2 -2
- data/lib/spout/tests/variable_type_validation.rb +2 -2
- data/lib/spout/tests.rb +30 -30
- data/lib/spout/version.rb +4 -4
- data/lib/spout/views/index.html.erb +15 -15
- data/lib/spout/views/outliers.html.erb +8 -8
- data/lib/spout.rb +26 -26
- data/spout.gemspec +22 -22
- metadata +5 -5
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spout/models/tables/default"
|
4
|
+
require "spout/helpers/array_statistics"
|
5
5
|
|
6
6
|
module Spout
|
7
7
|
module Models
|
@@ -18,16 +18,16 @@ module Spout
|
|
18
18
|
"#{bucket.min} to #{bucket.max} #{@chart_variable.units}"
|
19
19
|
end
|
20
20
|
|
21
|
-
[[
|
21
|
+
[[""] + categories + ["Total"]]
|
22
22
|
end
|
23
23
|
|
24
24
|
def footers
|
25
25
|
total_values = [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile|
|
26
|
-
{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.send(quartile).count, :count), style:
|
26
|
+
{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.send(quartile).count, :count), style: "font-weight:bold" }
|
27
27
|
end
|
28
28
|
|
29
29
|
[
|
30
|
-
[{ text:
|
30
|
+
[{ text: "Total", style: "font-weight:bold" }] + total_values + [{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.count, :count), style: "font-weight:bold" }]
|
31
31
|
]
|
32
32
|
end
|
33
33
|
|
@@ -40,15 +40,15 @@ module Spout
|
|
40
40
|
Spout::Helpers::TableFormatting.format_number(count, :count)
|
41
41
|
end
|
42
42
|
|
43
|
-
[option.display_name] + data + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style:
|
43
|
+
[option.display_name] + data + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style: "font-weight:bold" }]
|
44
44
|
end
|
45
45
|
|
46
46
|
if @filtered_subjects.count { |s| s.send(@variable.id).is_a?(Spout::Models::Empty) } > 0
|
47
47
|
unknown_values = [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile|
|
48
48
|
count = @filtered_subjects.send(quartile).count { |s| s.send(@variable.id).is_a?(Spout::Models::Empty) }
|
49
|
-
{ text: Spout::Helpers::TableFormatting.format_number(count, :count), class:
|
49
|
+
{ text: Spout::Helpers::TableFormatting.format_number(count, :count), class: "text-muted" }
|
50
50
|
end
|
51
|
-
rows_result << [{ text:
|
51
|
+
rows_result << [{ text: "Unknown", class: "text-muted"}] + unknown_values + [{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.count { |s| s.send(@variable.id).is_a?(Spout::Models::Empty) }, :count), style: "font-weight:bold", class: "text-muted" }]
|
52
52
|
end
|
53
53
|
rows_result
|
54
54
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spout/models/variable"
|
4
|
+
require "spout/helpers/table_formatting"
|
5
5
|
|
6
6
|
module Spout
|
7
7
|
module Models
|
@@ -34,9 +34,9 @@ module Spout
|
|
34
34
|
def valid?
|
35
35
|
if @variable.nil? || @chart_variable.nil? || @values_unique == []
|
36
36
|
false
|
37
|
-
elsif @variable.type ==
|
37
|
+
elsif @variable.type == "choices" && @variable.domain.options == []
|
38
38
|
false
|
39
|
-
elsif @chart_variable.type ==
|
39
|
+
elsif @chart_variable.type == "choices" && @chart_variable.domain.options == []
|
40
40
|
false
|
41
41
|
else
|
42
42
|
true
|
@@ -44,7 +44,7 @@ module Spout
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def title
|
47
|
-
|
47
|
+
""
|
48
48
|
end
|
49
49
|
|
50
50
|
def headers
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spout/models/tables/default"
|
4
|
+
require "spout/helpers/array_statistics"
|
5
5
|
|
6
6
|
module Spout
|
7
7
|
module Models
|
@@ -12,18 +12,18 @@ module Spout
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def headers
|
15
|
-
[[
|
15
|
+
[[""] + Spout::Helpers::ArrayStatistics.calculations.collect(&:first) + ["Total"]]
|
16
16
|
end
|
17
17
|
|
18
18
|
def footers
|
19
19
|
return [] unless @totals
|
20
20
|
total_values = Spout::Helpers::ArrayStatistics.calculations.collect do |_calculation_label, calculation_method, calculation_type, calculation_format|
|
21
21
|
total_count = @filtered_subjects.collect(&@variable.id.to_sym).send(calculation_method)
|
22
|
-
{ text: Spout::Helpers::TableFormatting.format_number(total_count, calculation_type, calculation_format), style:
|
22
|
+
{ text: Spout::Helpers::TableFormatting.format_number(total_count, calculation_type, calculation_format), style: "font-weight:bold" }
|
23
23
|
end
|
24
24
|
|
25
25
|
[
|
26
|
-
[{ text:
|
26
|
+
[{ text: "Total", style: "font-weight:bold" }] + total_values + [{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.count, :count), style: "font-weight:bold" }]
|
27
27
|
]
|
28
28
|
end
|
29
29
|
|
@@ -33,10 +33,10 @@ module Spout
|
|
33
33
|
|
34
34
|
row_cells = Spout::Helpers::ArrayStatistics.calculations.collect do |_calculation_label, calculation_method, calculation_type, calculation_format|
|
35
35
|
count = row_subjects.collect(&@variable.id.to_sym).send(calculation_method)
|
36
|
-
(count == 0 && calculation_method == :count) ? { text:
|
36
|
+
(count == 0 && calculation_method == :count) ? { text: "-", class: "text-muted" } : Spout::Helpers::TableFormatting.format_number(count, calculation_type, calculation_format)
|
37
37
|
end
|
38
38
|
|
39
|
-
[option.display_name] + row_cells + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style:
|
39
|
+
[option.display_name] + row_cells + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style: "font-weight:bold" }]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spout/models/tables/default"
|
4
|
+
require "spout/helpers/array_statistics"
|
5
5
|
|
6
6
|
module Spout
|
7
7
|
module Models
|
@@ -12,17 +12,17 @@ module Spout
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def headers
|
15
|
-
[[
|
15
|
+
[[""] + Spout::Helpers::ArrayStatistics.calculations.collect(&:first) + ["Total"]]
|
16
16
|
end
|
17
17
|
|
18
18
|
def footers
|
19
19
|
total_values = Spout::Helpers::ArrayStatistics.calculations.collect do |_calculation_label, calculation_method, calculation_type, calculation_format|
|
20
20
|
total_count = @filtered_subjects.collect(&@variable.id.to_sym).send(calculation_method)
|
21
|
-
{ text: Spout::Helpers::TableFormatting.format_number(total_count, calculation_type, calculation_format), style:
|
21
|
+
{ text: Spout::Helpers::TableFormatting.format_number(total_count, calculation_type, calculation_format), style: "font-weight:bold" }
|
22
22
|
end
|
23
23
|
|
24
24
|
[
|
25
|
-
[{ text:
|
25
|
+
[{ text: "Total", style: "font-weight:bold" }] + total_values + [{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.count, :count), style: "font-weight:bold" }]
|
26
26
|
]
|
27
27
|
end
|
28
28
|
|
@@ -36,7 +36,7 @@ module Spout
|
|
36
36
|
|
37
37
|
row_name = get_row_name(quartile, bucket, row_subjects)
|
38
38
|
|
39
|
-
[row_name] + data + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style:
|
39
|
+
[row_name] + data + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style: "font-weight:bold" }]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -44,7 +44,7 @@ module Spout
|
|
44
44
|
|
45
45
|
def get_row_name(quartile, bucket, row_subjects)
|
46
46
|
if row_subjects.size == 0
|
47
|
-
quartile.to_s.capitalize.gsub(
|
47
|
+
quartile.to_s.capitalize.gsub("_one", " One").gsub("_two", " Two").gsub("_three", " Three").gsub("_four", " Four")
|
48
48
|
else
|
49
49
|
"#{bucket.collect(&@chart_variable.id.to_sym).min} to #{bucket.collect(&@chart_variable.id.to_sym).max} #{@chart_variable.units}"
|
50
50
|
end
|
data/lib/spout/models/tables.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "spout/models/tables/default"
|
4
|
+
require "spout/models/tables/numeric_vs_choices"
|
5
|
+
require "spout/models/tables/choices_vs_choices"
|
6
|
+
require "spout/models/tables/numeric_vs_numeric"
|
7
|
+
require "spout/models/tables/choices_vs_numeric"
|
8
8
|
|
9
9
|
module Spout
|
10
10
|
module Models
|
11
11
|
module Tables
|
12
12
|
DEFAULT_CLASS = Spout::Models::Tables::Default
|
13
13
|
GRAPHABLE_CLASSES = {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
"numeric_vs_choices" => Spout::Models::Tables::NumericVsChoices,
|
15
|
+
"choices_vs_choices" => Spout::Models::Tables::ChoicesVsChoices,
|
16
|
+
"numeric_vs_numeric" => Spout::Models::Tables::NumericVsNumeric,
|
17
|
+
"choices_vs_numeric" => Spout::Models::Tables::ChoicesVsNumeric
|
18
18
|
}
|
19
19
|
|
20
20
|
def self.for(variable, chart_variable, subjects, subtitle, totals: true)
|
@@ -30,8 +30,8 @@ module Spout
|
|
30
30
|
def self.variable_to_table_type(variable)
|
31
31
|
variable_type = (variable ? variable.type : nil)
|
32
32
|
case variable_type
|
33
|
-
when
|
34
|
-
|
33
|
+
when "numeric", "integer"
|
34
|
+
"numeric"
|
35
35
|
else
|
36
36
|
variable_type
|
37
37
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "json"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require "spout/models/record"
|
6
|
+
require "spout/models/domain"
|
7
|
+
require "spout/models/form"
|
8
8
|
|
9
9
|
|
10
10
|
module Spout
|
11
11
|
module Models
|
12
12
|
class Variable < Spout::Models::Record
|
13
|
-
# VARIABLE_TYPES = [
|
13
|
+
# VARIABLE_TYPES = ["choices", "numeric", "integer"]
|
14
14
|
|
15
15
|
attr_accessor :id, :folder, :display_name, :description, :type, :units, :labels, :commonly_used, :calculation
|
16
16
|
attr_accessor :domain_name, :form_names
|
@@ -20,8 +20,8 @@ module Spout
|
|
20
20
|
|
21
21
|
def initialize(file_name, dictionary_root)
|
22
22
|
@errors = []
|
23
|
-
@id = file_name.to_s.gsub(%r{^(.*)/|\.json$},
|
24
|
-
@folder = file_name.to_s.gsub(%r{^#{dictionary_root}/variables/|#{@id}\.json$},
|
23
|
+
@id = file_name.to_s.gsub(%r{^(.*)/|\.json$}, "").downcase
|
24
|
+
@folder = file_name.to_s.gsub(%r{^#{dictionary_root}/variables/|#{@id}\.json$}, "")
|
25
25
|
@form_names = []
|
26
26
|
@domain_name = nil
|
27
27
|
|
@@ -37,10 +37,10 @@ module Spout
|
|
37
37
|
instance_variable_set("@#{method}", json[method])
|
38
38
|
end
|
39
39
|
@commonly_used = false if @commonly_used.nil?
|
40
|
-
@errors << "'id': #{json['id'].inspect} does not match filename #{@id.inspect}" if @id != json[
|
41
|
-
@domain_name = json[
|
42
|
-
@labels = (json[
|
43
|
-
@form_names = (json[
|
40
|
+
@errors << "'id': #{json['id'].inspect} does not match filename #{@id.inspect}" if @id != json["id"]
|
41
|
+
@domain_name = json["domain"] # Spout::Models::Domain.new(json["domain"], dictionary_root)
|
42
|
+
@labels = (json["labels"] || [])
|
43
|
+
@form_names = (json["forms"] || []).collect do |form_name|
|
44
44
|
form_name
|
45
45
|
end
|
46
46
|
elsif json
|
@@ -58,10 +58,10 @@ module Spout
|
|
58
58
|
def known_issues
|
59
59
|
line_found = false
|
60
60
|
lines = []
|
61
|
-
known_issues_file =
|
61
|
+
known_issues_file = "KNOWNISSUES.md"
|
62
62
|
if File.exist?(known_issues_file) && File.file?(known_issues_file)
|
63
63
|
IO.foreach(known_issues_file) do |line|
|
64
|
-
if line_found && Variable.starts_with?(line,
|
64
|
+
if line_found && Variable.starts_with?(line, " - ")
|
65
65
|
lines << line
|
66
66
|
elsif Variable.partial_match?(line, "\\[#{id}\\]")
|
67
67
|
line_found = true
|
@@ -84,7 +84,7 @@ module Spout
|
|
84
84
|
|
85
85
|
def deploy_params
|
86
86
|
{ name: id, display_name: display_name, variable_type: type,
|
87
|
-
folder: folder.to_s.gsub(%r{/$},
|
87
|
+
folder: folder.to_s.gsub(%r{/$}, ""), description: description,
|
88
88
|
units: units, calculation: calculation, commonly_used: commonly_used,
|
89
89
|
labels: labels,
|
90
90
|
stats_n: n, stats_mean: mean, stats_stddev: stddev,
|
data/lib/spout/tasks/engine.rake
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rake/testtask"
|
4
|
+
require "colorize"
|
5
5
|
|
6
6
|
Rake::TestTask.new do |t|
|
7
|
-
t.libs <<
|
8
|
-
t.test_files = FileList[
|
7
|
+
t.libs << "test"
|
8
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
9
9
|
t.warning = false
|
10
10
|
t.verbose = false
|
11
11
|
end
|
data/lib/spout/templates/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
# Launches default Spout tests and custom tests for specific to this dictionary.
|
6
6
|
class DictionaryTest < Minitest::Test
|
@@ -14,12 +14,12 @@ class DictionaryTest < Minitest::Test
|
|
14
14
|
# Example 1: Create custom tests to show that `integer` and `numeric`
|
15
15
|
# variables have a valid unit type.
|
16
16
|
# Add your own valid units to this array.
|
17
|
-
# VALID_UNITS = [
|
17
|
+
# VALID_UNITS = ["minutes", "hours"]
|
18
18
|
# @variables.select { |v| %w(numeric integer).include?(v.type) }.each do |variable|
|
19
19
|
# define_method("test_units: #{variable.path}") do
|
20
20
|
# message = "\"#{variable.units}\"".colorize(:red) + " invalid units.\n" +
|
21
21
|
# " Valid types: " +
|
22
|
-
# VALID_UNITS.sort_by(&:to_s).collect { |u| u.inspect.colorize(:white) }.join(
|
22
|
+
# VALID_UNITS.sort_by(&:to_s).collect { |u| u.inspect.colorize(:white) }.join(", ")
|
23
23
|
# assert VALID_UNITS.include?(variable.units), message
|
24
24
|
# end
|
25
25
|
# end
|
@@ -6,22 +6,22 @@ module Spout
|
|
6
6
|
# defined.
|
7
7
|
module DomainExistenceValidation
|
8
8
|
def assert_domain_existence(item)
|
9
|
-
domain_names = Dir.glob(
|
10
|
-
file.split(
|
9
|
+
domain_names = Dir.glob("domains/**/*.json").collect do |file|
|
10
|
+
file.split("/").last.to_s.downcase.split(".json").first
|
11
11
|
end
|
12
12
|
result = begin
|
13
|
-
domain_name = JSON.parse(File.read(item))[
|
13
|
+
domain_name = JSON.parse(File.read(item))["domain"]
|
14
14
|
domain_names.include?(domain_name)
|
15
15
|
rescue JSON::ParserError
|
16
|
-
domain_name =
|
16
|
+
domain_name = ""
|
17
17
|
false
|
18
18
|
end
|
19
19
|
message = "The domain #{domain_name} referenced by #{item} does not exist."
|
20
20
|
assert result, message
|
21
21
|
end
|
22
22
|
|
23
|
-
Dir.glob(
|
24
|
-
if (not [nil,
|
23
|
+
Dir.glob("variables/**/*.json").each do |file|
|
24
|
+
if (not [nil, ""].include?(JSON.parse(File.read(file))["domain"]) rescue false)
|
25
25
|
define_method("test_domain_exists: #{file}") do
|
26
26
|
assert_domain_existence file
|
27
27
|
end
|
@@ -5,10 +5,10 @@ module Spout
|
|
5
5
|
# Tests to assure that the domain name starts with a lowercase letter
|
6
6
|
# followed by lowercase letters, numbers, or underscores
|
7
7
|
module DomainNameFormat
|
8
|
-
Dir.glob(
|
8
|
+
Dir.glob("domains/**/*.json").each do |file|
|
9
9
|
define_method("test_domain_name_format: #{file}") do
|
10
|
-
message =
|
11
|
-
name = File.basename(file).gsub(/\.json$/,
|
10
|
+
message = "Domain name format error. Name must start with a lowercase letter and be followed by lowercase letters, numbers, or underscores"
|
11
|
+
name = File.basename(file).gsub(/\.json$/, "") rescue name = nil
|
12
12
|
assert_match(/^[a-z]\w*$/, name, message)
|
13
13
|
end
|
14
14
|
end
|
@@ -4,8 +4,8 @@ module Spout
|
|
4
4
|
module Tests
|
5
5
|
module DomainNameUniqueness
|
6
6
|
def test_domain_name_uniqueness
|
7
|
-
files = Dir.glob("domains/**/*.json").collect{|file| file.split(
|
8
|
-
assert_equal [], files.select{ |f| files.count(f) > 1 }.uniq
|
7
|
+
files = Dir.glob("domains/**/*.json").collect { |file| file.split("/").last.downcase }
|
8
|
+
assert_equal [], files.select { |f| files.count(f) > 1 }.uniq
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spout/tests/json_helper"
|
4
4
|
|
5
5
|
module Spout
|
6
6
|
module Tests
|
7
7
|
module DomainSpecified
|
8
|
-
|
9
8
|
Dir.glob("variables/**/*.json").each do |file|
|
10
9
|
if json_value(file, :type) == "choices"
|
11
10
|
define_method("test_domain_specified:"+file) do
|
@@ -14,7 +13,6 @@ module Spout
|
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
module Spout
|
4
4
|
module Tests
|
5
5
|
module FormExistenceValidation
|
6
|
-
|
7
6
|
def assert_form_existence(item)
|
8
|
-
form_names = Dir.glob("forms/**/*.json").collect{|file| file.split(
|
7
|
+
form_names = Dir.glob("forms/**/*.json").collect{|file| file.split("/").last.to_s.downcase.split(".json").first}
|
9
8
|
|
10
9
|
result = begin
|
11
10
|
(form_names | JSON.parse(File.read(item))["forms"]).size == form_names.size
|
@@ -19,13 +18,12 @@ module Spout
|
|
19
18
|
end
|
20
19
|
|
21
20
|
Dir.glob("variables/**/*.json").each do |file|
|
22
|
-
if (not [nil,
|
21
|
+
if (not [nil, ""].include?(JSON.parse(File.read(file))["forms"]) rescue false)
|
23
22
|
define_method("test_form_exists: "+file) do
|
24
23
|
assert_form_existence file
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
@@ -5,10 +5,10 @@ module Spout
|
|
5
5
|
# Tests to assure that the domain name starts with a lowercase letter
|
6
6
|
# followed by lowercase letters, numbers, or underscores
|
7
7
|
module FormNameFormat
|
8
|
-
Dir.glob(
|
8
|
+
Dir.glob("forms/**/*.json").each do |file|
|
9
9
|
define_method("test_form_name_format: #{file}") do
|
10
|
-
message =
|
11
|
-
assert_match(/^[a-z]\w*$/, (begin JSON.parse(File.read(file))[
|
10
|
+
message = "Form name format error. Name must start with a lowercase letter and be followed by lowercase letters, numbers, or underscores"
|
11
|
+
assert_match(/^[a-z]\w*$/, (begin JSON.parse(File.read(file))["id"] rescue nil end), message)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -5,7 +5,7 @@ module Spout
|
|
5
5
|
module FormNameMatch
|
6
6
|
Dir.glob("forms/**/*.json").each do |file|
|
7
7
|
define_method("test_form_name_match: "+file) do
|
8
|
-
assert_equal file.gsub(/^.*\//,
|
8
|
+
assert_equal file.gsub(/^.*\//, "").gsub(".json", "").downcase, (begin JSON.parse(File.read(file))["id"] rescue nil end)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -5,10 +5,10 @@ module Spout
|
|
5
5
|
# Tests to assure that the variable name starts with a lowercase letter
|
6
6
|
# followed by lowercase letters, numbers, or underscores
|
7
7
|
module VariableNameFormat
|
8
|
-
Dir.glob(
|
8
|
+
Dir.glob("variables/**/*.json").each do |file|
|
9
9
|
define_method("test_variable_name_format: #{file}") do
|
10
|
-
message =
|
11
|
-
assert_match(/^[a-z]\w*$/, (begin JSON.parse(File.read(file))[
|
10
|
+
message = "Variable name format error. Name must start with a lowercase letter and be followed by lowercase letters, numbers, or underscores"
|
11
|
+
assert_match(/^[a-z]\w*$/, (begin JSON.parse(File.read(file))["id"] rescue nil end), message)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -3,13 +3,11 @@
|
|
3
3
|
module Spout
|
4
4
|
module Tests
|
5
5
|
module VariableNameMatch
|
6
|
-
|
7
6
|
Dir.glob("variables/**/*.json").each do |file|
|
8
7
|
define_method("test_variable_name_match: "+file) do
|
9
|
-
assert_equal file.gsub(/^.*\//,
|
8
|
+
assert_equal file.gsub(/^.*\//, "").gsub(".json", "").downcase, (begin JSON.parse(File.read(file))["id"] rescue nil end)
|
10
9
|
end
|
11
10
|
end
|
12
|
-
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -4,8 +4,8 @@ module Spout
|
|
4
4
|
module Tests
|
5
5
|
module VariableNameUniqueness
|
6
6
|
def test_variable_name_uniqueness
|
7
|
-
files = Dir.glob("variables/**/*.json").collect{|file| file.split(
|
8
|
-
assert_equal [], files.select{ |f| files.count(f) > 1 }.uniq
|
7
|
+
files = Dir.glob("variables/**/*.json").collect { |file| file.split("/").last.downcase }
|
8
|
+
assert_equal [], files.select { |f| files.count(f) > 1 }.uniq
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -10,9 +10,9 @@ module Spout
|
|
10
10
|
assert VALID_VARIABLE_TYPES.include?(item), message
|
11
11
|
end
|
12
12
|
|
13
|
-
Dir.glob(
|
13
|
+
Dir.glob("variables/**/*.json").each do |file|
|
14
14
|
define_method("test_variable_type: #{file}") do
|
15
|
-
assert_variable_type begin JSON.parse(File.read(file))[
|
15
|
+
assert_variable_type begin JSON.parse(File.read(file))["type"] rescue nil end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|