Skip to content

Commit

Permalink
Refactor Laravel specific MR helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Jan 28, 2021
1 parent cf2e7e2 commit 7847cbf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
31 changes: 3 additions & 28 deletions features/steps/laravel_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'net/http'

Given(/^I enable session tracking$/) do
steps %{
When I set environment variable "BUGSNAG_CAPTURE_SESSIONS" to "true"
Expand All @@ -15,47 +13,24 @@

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|
desired_value = read_key_path(Server.current_request[:body], "events.0.exceptions.0.#{path}")
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?

ip_addr = `ifconfig | grep -Eo 'inet (addr:)?([0-9]*\\\.){3}[0-9]*' | grep -v '127.0.0.1'`
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
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions features/support/laravel.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7847cbf

Please sign in to comment.