Module: Acop
- Defined in:
- lib/acop.rb,
lib/acop/version.rb,
lib/acop/rspec_writer.rb,
lib/acop/accessibility.rb
Defined Under Namespace
Classes: Enforcer, Helpers, RSpecWriter
Constant Summary
collapse
- VERSION =
"1.0.2"
Class Method Summary
collapse
Class Method Details
.expected_test_type?(test_type) ⇒ Boolean
68
69
70
|
# File 'lib/acop.rb', line 68
def self.expected_test_type?(test_type)
return true if(test_type == "rspec")
end
|
.file_exists?(file) ⇒ Boolean
59
60
61
|
# File 'lib/acop.rb', line 59
def self.file_exists?(file)
return File.exists?(file)
end
|
.file_has_urls?(file) ⇒ Boolean
63
64
65
66
|
# File 'lib/acop.rb', line 63
def self.file_has_urls?(file)
urls = File.readlines(file, 'r')
return urls.size > 0
end
|
.run(*args) ⇒ Object
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
|
# File 'lib/acop.rb', line 6
def self.run(*args)
options = {}
option_parser = OptionParser.new do |opts|
opts.banner = 'Usage: acop [options] [values]'
opts.on('-u', '--url URL', 'Url to be accessibility tested') do |tag|
options[:url] = tag
options[:url] = "http://" + options[:url] unless options[:url].include?("http")
end
opts.on('-f', '--file FILEPATH', "File with a list of urls' to be accessibility tested") do |tag|
options[:file] = tag
end
opts.on('-g', '--generate TEST_TYPE', "Generate tests of the specified type from the list of urls") do |tag|
options[:tests] = tag
end
end
begin
option_parser.parse!
raise OptionParser::MissingArgument, "Either Url or FilePath should be provided!" if options.keys.empty?
raise OptionParser::InvalidArgument, "Both Url and FilePath cannot be specified!" if(options[:url]!=nil and options[:file]!=nil)
raise OptionParser::MissingArgument, "Url or file with list of urls should be specified to generate tests" unless(options[:url] or options[:file])
if(options[:url]!=nil)
raise OptionParser::InvalidArgument, "Url cannot be resolved!" unless valid_url?(options[:url])
end
if(options[:file]!=nil)
raise OptionParser::InvalidArgument, "File does not exist or empty!" unless (file_exists?(options[:file]) and file_has_urls?(options[:file]))
end
if(options[:tests]!=nil)
raise OptionParser::InvalidArgument, "Invalid test type! Currently supports 'rspec'" unless expected_test_type?(options[:tests])
end
rescue OptionParser::ParseError => e
puts e.message
puts
puts option_parser
exit -1
end
Enforcer.new(options).accessibility_checks
end
|
.valid_url?(url) ⇒ Boolean
50
51
52
53
54
55
56
57
|
# File 'lib/acop.rb', line 50
def self.valid_url?(url)
begin
contents = open(url)
return true
rescue Exception => e
return false
end
end
|