Class: TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/zfben_hanoi/test_case.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, test_directory) ⇒ TestCase

Returns a new instance of TestCase.



4
5
6
# File 'lib/zfben_hanoi/test_case.rb', line 4

def initialize(path, test_directory)
  @path, @test_directory = path, test_directory
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



2
3
4
# File 'lib/zfben_hanoi/test_case.rb', line 2

def path
  @path
end

Instance Method Details

#contentObject



16
17
18
# File 'lib/zfben_hanoi/test_case.rb', line 16

def content
  File.new(@path).read
end

#create_temp_directoryObject



32
33
34
# File 'lib/zfben_hanoi/test_case.rb', line 32

def create_temp_directory
  FileUtils.mkdir_p temp_directory
end

#exist?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/zfben_hanoi/test_case.rb', line 20

def exist?
  File.exist?(path)
end

#html_fixturesObject



40
41
42
43
44
# File 'lib/zfben_hanoi/test_case.rb', line 40

def html_fixtures
  path = File.dirname(File.expand_path(@path).gsub(@test_directory, "#{@test_directory}/fixtures"))
  path = File.expand_path(path + "/#{name.gsub(/(_test|_spec)/, '_fixtures.html')}")
  File.new(path).read rescue ""
end

#nameObject



8
9
10
# File 'lib/zfben_hanoi/test_case.rb', line 8

def name
  @name ||= File.basename(@path, '.js')
end

#relative_pathObject



24
25
26
# File 'lib/zfben_hanoi/test_case.rb', line 24

def relative_path
  @relative_path ||= @path.gsub("#{@test_directory}/", "")
end

#targetObject



12
13
14
# File 'lib/zfben_hanoi/test_case.rb', line 12

def target
  "/javascripts/#{relative_path.gsub(/(_test|_spec)/, '')}"
end

#temp_directoryObject



36
37
38
# File 'lib/zfben_hanoi/test_case.rb', line 36

def temp_directory
  @temp_directory ||= File.dirname(File.expand_path(@path).gsub(@test_directory, "#{@test_directory}/tmp"))
end

#urlObject



28
29
30
# File 'lib/zfben_hanoi/test_case.rb', line 28

def url
  "/test/#{relative_path.gsub('.js', '')}.html"
end