Class: Acop::RSpecWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/acop/rspec_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ RSpecWriter

Returns a new instance of RSpecWriter.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/acop/rspec_writer.rb', line 6

def initialize(url)
	@url = url
	Dir.mkdir("./spec") unless File.exists?("./spec")
	if File.exists?("./spec/acop_spec.rb")
		@file = File.open("./spec/acop_accessibility_spec.rb", 'a')
		append_file(@url)
	else
		@file = File.open("./spec/acop_accessibility_spec.rb", 'w')
		write_file(@url)
	end
	close_file
end

Instance Attribute Details

#file=(value) ⇒ Object (writeonly)

Sets the attribute file

Parameters:

  • value

    the value to set the attribute file to.



3
4
5
# File 'lib/acop/rspec_writer.rb', line 3

def file=(value)
  @file = value
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/acop/rspec_writer.rb', line 4

def url
  @url
end

Instance Method Details

#append_file(url) ⇒ Object



19
20
21
# File 'lib/acop/rspec_writer.rb', line 19

def append_file(url)
	write_rspec(url)
end

#close_fileObject



45
46
47
# File 'lib/acop/rspec_writer.rb', line 45

def close_file
	@file.close
end

#write_file(url) ⇒ Object



23
24
25
26
# File 'lib/acop/rspec_writer.rb', line 23

def write_file(url)
	write_requires
	write_rspec(url)
end

#write_requiresObject



28
29
30
# File 'lib/acop/rspec_writer.rb', line 28

def write_requires
	@file.puts "require 'rspec/expectations'"
end

#write_rspec(url) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/acop/rspec_writer.rb', line 32

def write_rspec(url)
	@file.puts "describe '#{url.chomp}' do"
	@file.puts "  it 'should pass accessibility tests' do"
	@file.puts "    output = `acop -u #{url.chomp}`"
	@file.puts "    output = output.split(\"\\n\").reject! {|line| line[0] == '='}"
	@file.puts "    puts '== ACCESSIBILITY ISSUES =='"
	@file.puts "    puts output"
	@file.puts "    output.should be_empty"
	@file.puts "  end"
	@file.puts "end"
	@file.puts
end