-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathlaravel_steps.rb
143 lines (112 loc) · 4.83 KB
/
laravel_steps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require_relative "../lib/laravel"
require_relative "../lib/utils"
Given(/^I enable session tracking$/) do
steps %{
Given I set environment variable "BUGSNAG_CAPTURE_SESSIONS" to "true"
}
end
When(/^I start the laravel fixture$/) do
steps %{
When I start the service "#{Laravel.fixture}"
And I wait for the host "localhost" to open port "#{Laravel.fixture_port}"
}
end
When("I start the laravel queue worker") do
step("I start the laravel queue worker with --tries=1")
end
When("I start the laravel queue worker with --tries={int}") do |tries|
Maze::Docker.exec(Laravel.fixture, Laravel.queue_worker_daemon_command(tries), detach: true)
end
When("I run the laravel queue worker") do
step("I run the laravel queue worker with --tries=1")
end
When("I run the laravel queue worker with --tries={int}") do |tries|
Maze::Docker.exec(Laravel.fixture, Laravel.queue_worker_once_command(tries))
end
When("I navigate to the route {string}") do |route|
Laravel.navigate_to(route)
end
Then("the Laravel response matches {string}") do |regex|
wait = Maze::Wait.new(timeout: 10)
success = wait.until { Laravel.last_response != nil }
raise 'No response from the Laravel fixture!' unless success
assert_match(Regexp.new(regex), Laravel.last_response)
end
Then("the exception {string} matches one of the following:") do |path, values|
body = Maze::Server.errors.current[:body]
desired_value = Maze::Helper.read_key_path(body, "events.0.exceptions.0.#{path}")
Maze.check.includes(values.raw.flatten, desired_value)
end
Then("the event {string} matches the current major Laravel version") do |path|
# skip this assertion if we're running Lumen
next if Laravel.lumen?
# don't try to check the major version on the 'latest' fixture
unless Laravel.latest?
step("the event '#{path}' starts with '#{Laravel.major_version}'")
end
step("the event '#{path}' matches '^((\\d+\\.){2}\\d+|\\d+\\.x-dev)$'")
end
Then("the session payload field {string} matches the current major Laravel version") do |path|
# skip this assertion if we're running Lumen
next if Laravel.lumen?
# don't try to check the major version on the 'latest' fixture
unless Laravel.latest?
step("the session payload field '#{path}' starts with '#{Laravel.major_version}'")
end
step("the session payload field '#{path}' matches the regex '^((\\d+\\.){2}\\d+|\\d+\\.x-dev)$'")
end
Then("the event {string} matches the current major Lumen version") do |path|
# skip this assertion if we're running Laravel
next unless Laravel.lumen?
# don't try to check the major version on the 'latest' fixture
unless Laravel.latest?
step("the event '#{path}' starts with '#{Laravel.major_version}'")
end
step("the event '#{path}' matches '^((\\d+\\.){2}\\d+|\\d+\\.x-dev)$'")
end
Then("the session payload field {string} matches the current major Lumen version") do |path|
# skip this assertion if we're running Laravel
next unless Laravel.lumen?
# don't try to check the major version on the 'latest' fixture
unless Laravel.latest?
step("the session payload field '#{path}' starts with '#{Laravel.major_version}'")
end
step("the session payload field '#{path}' matches the regex '^((\\d+\\.){2}\\d+|\\d+\\.x-dev)$'")
end
# conditionally run a step if the laravel version matches a specified version
#
# e.g. this will only check app.type on Laravel 5.2 and above:
# on Laravel versions > 5.1 the event "app.type" equals "Queue"
Then(/^on Laravel versions (>=?|<=?|==) ([0-9.]+) (.*)$/) do |operator, version, step_to_run|
should_run_step = Laravel.version.send(operator, version)
# make sure this step is debuggable!
$logger.debug("Laravel v#{Laravel.version} #{operator} #{version}? #{should_run_step}")
if should_run_step
step(step_to_run)
else
$logger.info("Skipping step on Laravel v#{Laravel.version}: #{step_to_run}")
end
end
# conditionally run a number of steps if the laravel version matches a specified version
#
# e.g. this will only run the indented steps on Laravel 5.2 and above:
# on Laravel versions > 5.1:
# """
# the event "app.type" equals "Queue"
# the event "other.thing" equals "yes"
# """
Then(/^on Laravel versions (>=?|<=?|==) ([0-9.]+):/) do |operator, version, steps_to_run|
should_run_steps = Laravel.version.send(operator, version)
# make sure this step is debuggable!
$logger.debug("Laravel v#{Laravel.version} #{operator} #{version}? #{should_run_steps}")
if should_run_steps
steps_to_run.each_line(chomp: true) do |step_to_run|
step(step_to_run)
end
else
indent = " " * 4
# e.g. "a step\nanother step\n" -> " 1) a step\n 2) another step"
steps_indented = steps_to_run.each_line.map.with_index(1) { |step, i| "#{indent}#{i}) #{step.chomp}" }.join("\n")
$logger.info("Skipping steps on Laravel v#{Laravel.version}:\n#{steps_indented}")
end
end