-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from nogates/fix_hooks_with_rspec_integration
Fix hooks with rspec integration
- Loading branch information
Showing
15 changed files
with
177 additions
and
73 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
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 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,46 @@ | ||
module Vigia | ||
module Hooks | ||
|
||
def execute_hook(filter_name, rspec_context) | ||
hooks_for_object(filter_name).each do |hook| | ||
rspec_context.instance_exec(&hook) | ||
end | ||
end | ||
|
||
def hooks_for_object(filter_name) | ||
config_hooks(filter_name) + object_hooks(filter_name) | ||
end | ||
|
||
def with_hooks(rspec_context) | ||
instance = self | ||
|
||
rspec_context.before(:context) do | ||
instance.execute_hook(:before, self) | ||
end | ||
|
||
rspec_context.after(:context) do | ||
instance.execute_hook(:after, self) | ||
end | ||
|
||
instance.execute_hook(:extend, rspec_context) | ||
|
||
yield | ||
end | ||
|
||
private | ||
|
||
def object_hooks(filter_name) | ||
return [] unless respond_to?(:options) | ||
option_name = "#{ filter_name }_#{ self.class.name.split('::').last.downcase }".to_sym | ||
[ *options[option_name] ].compact | ||
|
||
end | ||
|
||
def config_hooks(filter_name) | ||
Vigia.config.hooks.each_with_object([]) do |hook, collection| | ||
next unless self.is_a?(hook[:rspec_class]) and filter_name == hook[:filter] | ||
collection << hook[:block] | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Vigia::Sail::Example.register( | ||
:code_match, | ||
description: 'has the expected HTTP code', | ||
expectation: -> { expect(result.code).to be(expectations.code) } | ||
) | ||
|
||
Vigia::Sail::Example.register( | ||
:include_headers, | ||
description: 'includes the expected headers', | ||
expectation: -> { expect(result[:headers]).to include(expectations[:headers]) } | ||
) |
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
Oops, something went wrong.