Class: Slightish::TestSuite

Inherits:
Object
  • Object
show all
Defined in:
lib/slightish/test_suite.rb

Defined Under Namespace

Classes: ParseState

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, contents, sandbox_template_dir: nil) ⇒ TestSuite

Returns a new instance of TestSuite.



12
13
14
15
16
17
18
# File 'lib/slightish/test_suite.rb', line 12

def initialize(path, contents, sandbox_template_dir: nil)
  @path = path
  @name = File.basename(path)
  @sandbox_template_dir = sandbox_template_dir

  parse(path, contents)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/slightish/test_suite.rb', line 5

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/slightish/test_suite.rb', line 5

def path
  @path
end

#sandbox_template_dirObject (readonly)

Returns the value of attribute sandbox_template_dir.



6
7
8
# File 'lib/slightish/test_suite.rb', line 6

def sandbox_template_dir
  @sandbox_template_dir
end

#test_casesObject (readonly)

Returns the value of attribute test_cases.



5
6
7
# File 'lib/slightish/test_suite.rb', line 5

def test_cases
  @test_cases
end

Class Method Details

.from_file(path, sandbox_template_dir: nil) ⇒ Object



8
9
10
# File 'lib/slightish/test_suite.rb', line 8

def self.from_file(path, sandbox_template_dir: nil)
  new(path, File.read(path), sandbox_template_dir: sandbox_template_dir)
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/slightish/test_suite.rb', line 44

def failed?
  @test_cases.any?(&:failed?)
end

#failed_countObject



52
53
54
# File 'lib/slightish/test_suite.rb', line 52

def failed_count
  @test_cases.count(&:failed?)
end

#failure_descriptionObject



30
31
32
33
34
35
36
37
38
# File 'lib/slightish/test_suite.rb', line 30

def failure_description
  res = ''
  @test_cases.select(&:failed?).each do |test|
    res += "#{test.source_description}\n".bold
    res += test.failure_description + "\n\n"
  end

  res
end

#passed?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/slightish/test_suite.rb', line 40

def passed?
  @test_cases.all?(&:passed?)
end

#passed_countObject



48
49
50
# File 'lib/slightish/test_suite.rb', line 48

def passed_count
  @test_cases.count(&:passed?)
end

#runObject



20
21
22
23
24
25
26
27
28
# File 'lib/slightish/test_suite.rb', line 20

def run
  sandbox = Slightish::Sandbox.new(template_dir: @sandbox_template_dir)

  begin
    @test_cases.each { |test| test.run(sandbox) }
  ensure
    sandbox.delete
  end
end