Class: Oncall::DSL::Assertion

Inherits:
Object
  • Object
show all
Defined in:
lib/oncall/dsl/assertion.rb

Instance Method Summary collapse

Constructor Details

#initialize(response, method, path) ⇒ Assertion

Returns a new instance of Assertion.



4
5
6
7
8
9
# File 'lib/oncall/dsl/assertion.rb', line 4

def initialize(response, method, path)
  @reporter = Oncall::Core.reporter
  @response = response
  @method = method
  @path = path
end

Instance Method Details

#status(expected) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/oncall/dsl/assertion.rb', line 11

def status(expected)
  result = @response.code == expected.to_s

  message = "#{@method} #{@path}\nexpected: #{expected}\nactual: #{@response.code}"

  @reporter.report_status(result, message)
end

#validate(expected) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/oncall/dsl/assertion.rb', line 19

def validate(expected)
  result = JSON::Validator.validate(expected, @response.body)

  message = "#{@method} #{@path}\nexpected: #{expected}\nactual: #{@response.body}"

  @reporter.report_status(result, message)
end