-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce driver registration (#133)
- Loading branch information
1 parent
7f43cb7
commit da9c947
Showing
9 changed files
with
126 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Spec | ||
module Item | ||
# :nodoc: | ||
def _lucky_flow_all_tags : Set(String) | ||
all_tags = tags || Set(String).new | ||
temp = parent | ||
if temp.is_a?(Spec::Item) | ||
all_tags += temp._lucky_flow_all_tags | ||
end | ||
all_tags | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class LuckyFlow::Registry | ||
@@registry = Hash(String, Proc(LuckyFlow::Driver)).new | ||
@@running_registry = Hash(String, LuckyFlow::Driver).new | ||
|
||
def self.register(name : String | Symbol, &block : -> LuckyFlow::Driver) | ||
@@registry[name.to_s] = block | ||
end | ||
|
||
def self.available : Set(String) | ||
Set.new(@@registry.keys) | ||
end | ||
|
||
def self.get_driver(name : String) : LuckyFlow::Driver | ||
@@running_registry[name] ||= @@registry[name].call | ||
end | ||
|
||
def self.shutdown_all | ||
@@running_registry.values.each(&.shutdown) | ||
@@running_registry.clear | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module LuckyFlow::Spec | ||
macro setup | ||
Spec.around_each do |spec| | ||
if driver_name = (spec.example._lucky_flow_all_tags & LuckyFlow::Registry.available).first? | ||
LuckyFlow.driver(driver_name) | ||
end | ||
|
||
spec.run | ||
|
||
LuckyFlow.reset | ||
LuckyFlow.use_default_driver | ||
end | ||
|
||
Spec.after_suite do | ||
LuckyFlow.shutdown | ||
end | ||
end | ||
end |