Class: Liltest::Case

Inherits:
Object
  • Object
show all
Defined in:
lib/liltest/case.rb

Class Method Summary collapse

Class Method Details

.context(context_name, &block) ⇒ Object



15
16
17
18
# File 'lib/liltest/case.rb', line 15

def self.context(context_name, &block)
  @current_context = context_name
  block.call
end

.delete(endpoint, body = nil, headers = nil) ⇒ Object



74
75
76
# File 'lib/liltest/case.rb', line 74

def self.delete(endpoint, body = nil, headers = nil)
  @response = Liltest::Request.new(:delete, endpoint, body, headers)
end

.describe(description, &block) ⇒ Object



6
7
8
# File 'lib/liltest/case.rb', line 6

def self.describe(description, &block)
  block.call
end

.executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/liltest/case.rb', line 20

def self.execute
  @tests.each do |test|
    begin
      test[:block].call
      $stdout.write "."
    rescue
      @failed ||= []
      @failed << test
      $stdout.write "F"
    end
  end

  write_failed_tests
  write_failed_expectations
end

.expect(value) ⇒ Object



55
56
57
58
59
60
# File 'lib/liltest/case.rb', line 55

def self.expect(value)
  expectation = Expectation.new(value)
  @expectations ||= []
  @expectations << expectation
  expectation
end

.get(endpoint, body = nil, headers = nil) ⇒ Object



62
63
64
# File 'lib/liltest/case.rb', line 62

def self.get(endpoint, body = nil, headers = nil)
  @response = Liltest::Request.new(:get, endpoint, body, headers)
end

.it(description, &block) ⇒ Object



10
11
12
13
# File 'lib/liltest/case.rb', line 10

def self.it(description, &block)
  @tests ||= []
  @tests << { context: @current_context, description: description, block: block }
end

.post(endpoint, body = nil, headers = nil) ⇒ Object



66
67
68
# File 'lib/liltest/case.rb', line 66

def self.post(endpoint, body = nil, headers = nil)
  @response = Liltest::Request.new(:post, endpoint, body, headers)
end

.put(endpoint, body = nil, headers = nil) ⇒ Object



70
71
72
# File 'lib/liltest/case.rb', line 70

def self.put(endpoint, body = nil, headers = nil)
  @response = Liltest::Request.new(:put, endpoint, body, headers)
end

.responseObject



78
79
80
# File 'lib/liltest/case.rb', line 78

def self.response
  @response
end

.write_failed_expectationsObject



36
37
38
39
40
41
42
43
44
# File 'lib/liltest/case.rb', line 36

def self.write_failed_expectations
  if @expectations
    @expectations.each do |expectation|
      if expectation.failed?
        $stdout.write "\n #{expectation.failed_reason}"
      end
    end
  end
end

.write_failed_testsObject



46
47
48
49
50
51
52
53
# File 'lib/liltest/case.rb', line 46

def self.write_failed_tests
  if @failed
    $stdout.write "\n"
    @failed.each do |failed|
      $stdout.write "\n #{@current_context} #{failed[:description]} failed"
    end
  end
end