Skip to content

Commit

Permalink
Use RSpec annotations instead of included class to trigger RSpec hooks
Browse files Browse the repository at this point in the history
Since we already use :type to trigger inclusion of Aruba::Api, we can
safely use it to activate the around hooks as well.

This also increases safety for custom integrations, since having those
work correctly depended on "aruba/rspec" never being loaded.
  • Loading branch information
mvz committed Mar 17, 2024
1 parent f2d8a3b commit 9dbad6b
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions lib/aruba/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,35 @@
config.include Aruba::Api, type: :aruba

# Setup environment for aruba
config.around :each do |example|
if self.class.include? Aruba::Api
setup_aruba
config.around :each, type: :aruba do |example|
setup_aruba

# Modify PATH to include project/bin
prepend_environment_variable(
"PATH",
aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR
)
# Modify PATH to include project/bin
prepend_environment_variable(
"PATH",
aruba.config.command_search_paths.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR
)

# Use configured home directory as HOME
set_environment_variable "HOME", aruba.config.home_directory
end
# Use configured home directory as HOME
set_environment_variable "HOME", aruba.config.home_directory

example.run

next unless self.class.include? Aruba::Api

stop_all_commands
end

config.around :each do |example|
if self.class.include? Aruba::Api
with_environment do
example.run
end
else
config.around :each, type: :aruba do |example|
with_environment do
example.run
end
end

config.before :each do |example|
next unless self.class.include? Aruba::Api

config.before :each, type: :aruba do |example|
example.metadata.each { |k, v| aruba.config.set_if_option(k, v) }
end

# Activate announcers based on rspec metadata
config.before :each do |example|
next unless self.class.include?(Aruba::Api)

config.before :each, type: :aruba do |example|
if example.metadata[:announce_full_environment]
aruba.announcer.activate(:full_environment)
end
Expand Down

0 comments on commit 9dbad6b

Please sign in to comment.