Module: RunscopeCi
- Includes:
- HTTParty
- Defined in:
- lib/runscope_ci.rb,
lib/runscope_ci/version.rb
Defined Under Namespace
Classes: RsTest
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
- #access_token ⇒ Object
- #access_token_name ⇒ Object
- #all_tests_have_result?(result, tests) ⇒ Boolean
- #extract_tests(response_data) ⇒ Object
- #trigger_bucket(trigger_url) ⇒ Object
- #trigger_bucket_and_poll_results(trigger_url, expected_result, interval_sleep = 5, retry_limit = 60) ⇒ Object
Instance Method Details
#access_token ⇒ Object
12 13 14 |
# File 'lib/runscope_ci.rb', line 12 def access_token ENV[access_token_name] end |
#access_token_name ⇒ Object
8 9 10 |
# File 'lib/runscope_ci.rb', line 8 def access_token_name "RUNSCOPE_ACCESS_TOKEN" end |
#all_tests_have_result?(result, tests) ⇒ Boolean
41 42 43 |
# File 'lib/runscope_ci.rb', line 41 def all_tests_have_result?(result, tests) tests.all?{|t| t.result == result} end |
#extract_tests(response_data) ⇒ Object
23 24 25 |
# File 'lib/runscope_ci.rb', line 23 def extract_tests(response_data) response_data["data"]["runs"].collect { |run| RunscopeCi::RsTest.new(run) } end |
#trigger_bucket(trigger_url) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/runscope_ci.rb', line 16 def trigger_bucket(trigger_url) res = HTTParty.get(trigger_url) raise "Received error #{res.code} #{res.message} #{res.body}" unless res.code == 201 puts "Triggered test bucket url -> #{trigger_url}" JSON.parse(res.body) end |
#trigger_bucket_and_poll_results(trigger_url, expected_result, interval_sleep = 5, retry_limit = 60) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/runscope_ci.rb', line 27 def trigger_bucket_and_poll_results(trigger_url, expected_result, interval_sleep=5, retry_limit=60) tests = extract_tests(trigger_bucket(trigger_url)) attempt = 1 until ( tests.collect {|t| t.result_detail }.select{|rs_test| rs_test.result == "working"}.empty? ) puts "attempt #{attempt}" raise("Timed out waiting for results, tests still 'working'") if attempt > retry_limit sleep interval_sleep attempt += 1 end [all_tests_have_result?(expected_result, tests),tests] end |