Sha256: 00d5e75df71d12c319d055565001e4b3fafd629ecf24ead03601d1204cf9b290
Contents?: true
Size: 1.22 KB
Versions: 5
Compression:
Stored size: 1.22 KB
Contents
module ApiPi class Case attr_reader :tests, :url def initialize(url, tests) @tests = tests @url = url @success_count = 0 @failure_count = 0 end # Begin investigating each GET request and their tests. def investigate puts "\nRequesting JSON from #{url} and testing" tests.each_pair do |test, block| print " - #{test}\n" check test, block end summary exit_status end private # Runs tests and returns the results from the assertions. def check test, block res = [] begin block.call rescue ApiPi::AssertionError => e res << e.message end failed = !res.empty? failed ? @failure_count += 1 : @success_count += 1 puts "\tERROR: #{res.first}\n" if failed end # Text output from results of #check. def summary s = tests.keys.size puts "\n#{s} tests, #{@success_count} succeeded, #{@failure_count} failed" end # Exit api_pi with a status of 1 if there are any failed tests. # Exit witha status of 0 if all tests succeeded. def exit_status @failure_count == 0 ? exit(0) : exit(1) end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
api_pi-0.9.3 | lib/api_pi/case.rb |
api_pi-0.9.2 | lib/api_pi/case.rb |
api_pi-0.9 | lib/api_pi/case.rb |
api_pi-0.2.3 | lib/api_pi/case.rb |
api_pi-0.2.2 | lib/api_pi/case.rb |