diff --git a/features/steps/laravel_steps.rb b/features/steps/laravel_steps.rb index ba9c9eaa..d1a1424d 100644 --- a/features/steps/laravel_steps.rb +++ b/features/steps/laravel_steps.rb @@ -1,5 +1,3 @@ -require 'net/http' - Given(/^I enable session tracking$/) do steps %{ When I set environment variable "BUGSNAG_CAPTURE_SESSIONS" to "true" @@ -15,13 +13,13 @@ When(/^I start the laravel fixture$/) do steps %{ - When I start the service "#{fixture}" - And I wait for the host "localhost" to open port "#{fixture_port}" + When I start the service "#{Laravel.fixture}" + And I wait for the host "localhost" to open port "#{Laravel.fixture_port}" } end When("I navigate to the route {string}") do |route| - navigate_to(route) + Laravel.navigate_to(route) end Then("the exception {string} matches one of the following:") do |path, values| @@ -29,20 +27,6 @@ assert_includes(values.raw.flatten, desired_value) end -def fixture - ENV['LARAVEL_FIXTURE'] || 'laravel56' -end - -def fixture_port - case fixture - when 'laravel-latest' then 61299 - when 'laravel66' then 61266 - when 'laravel58' then 61258 - when 'laravel56' then 61256 - else raise "Unknown laravel fixture '#{ENV['LARAVEL_FIXTURE']}'!" - end -end - def current_ip return 'host.docker.internal' if OS.mac? @@ -50,12 +34,3 @@ def current_ip ip_list = /((?:[0-9]*\.){3}[0-9]*)/.match(ip_addr) ip_list.captures.first end - -def navigate_to(route, attempts = 0) - Net::HTTP.get('localhost', route, fixture_port) -rescue => e - raise "Failed to navigate to #{route} (#{e})" if attempts > 15 - - sleep 1 - navigate_to(route, attempts + 1) -end diff --git a/features/support/env.rb b/features/support/env.rb index b8711b61..a39311dc 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -37,6 +37,7 @@ Before do ENV["BUGSNAG_API_KEY"] = $api_key ENV["BUGSNAG_ENDPOINT"] = "http://#{current_ip}:9339" + Laravel.reset! end at_exit do diff --git a/features/support/laravel.rb b/features/support/laravel.rb new file mode 100644 index 00000000..c37081e8 --- /dev/null +++ b/features/support/laravel.rb @@ -0,0 +1,34 @@ +require 'net/http' + +class Laravel + class << self + attr_reader :last_response + + def reset! + @last_response = nil + end + + def navigate_to(route, attempts = 0) + @last_response = Net::HTTP.get('localhost', route, fixture_port) + rescue => e + raise "Failed to navigate to #{route} (#{e})" if attempts > 15 + + sleep 1 + navigate_to(route, attempts + 1) + end + + def fixture + ENV.fetch('LARAVEL_FIXTURE', 'laravel56') + end + + def fixture_port + case fixture + when 'laravel-latest' then 61299 + when 'laravel66' then 61266 + when 'laravel58' then 61258 + when 'laravel56' then 61256 + else raise "Unknown laravel fixture '#{ENV['LARAVEL_FIXTURE']}'!" + end + end + end +end