Module: ExampleHelper
- Included in:
- ServerspecLauncherRakeTasks, SpecHelper
- Defined in:
- lib/serverspec_launcher/helpers/example_helper.rb
Overview
Helper to load and list shared_examples loaded in to RSpec
Instance Method Summary collapse
- #load_bundled_examples(shared_example_gems) ⇒ Object
- #load_examples_from_gem(dep) ⇒ Object
- #load_shared_examples(shared_example_gems = [], project_root = Dir.pwd, shareDir = 'shared') ⇒ Object
- #shared_examples ⇒ Object
Instance Method Details
#load_bundled_examples(shared_example_gems) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/serverspec_launcher/helpers/example_helper.rb', line 23 def load_bundled_examples(shared_example_gems) Bundler.load.specs.map(&:name).each do |dep| next unless shared_example_gems.include? dep load_examples_from_gem(dep) load_examples_from_gem(dep.tr('-', '/')) end end |
#load_examples_from_gem(dep) ⇒ Object
31 32 33 34 35 |
# File 'lib/serverspec_launcher/helpers/example_helper.rb', line 31 def load_examples_from_gem(dep) Gem.find_files("#{dep}/**/*.rb").each do |path| require path if File.open(path).grep(/shared_examples/).any? end end |
#load_shared_examples(shared_example_gems = [], project_root = Dir.pwd, shareDir = 'shared') ⇒ Object
16 17 18 19 20 21 |
# File 'lib/serverspec_launcher/helpers/example_helper.rb', line 16 def load_shared_examples(shared_example_gems = [], project_root = Dir.pwd, shareDir = 'shared') load_bundled_examples(shared_example_gems) Dir.glob("#{project_root}/**/#{shareDir}/**/*.rb") do |path| require path if File.open(path).grep(/shared_examples/).any? end end |
#shared_examples ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/serverspec_launcher/helpers/example_helper.rb', line 8 def shared_examples groups = RSpec.world.shared_example_group_registry.send(:shared_example_groups) examples = groups[:main].map do |example, _details| example end examples end |