-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added after_save_html and after_save_screenshot callbacks
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,30 @@ Capybara::Screenshot.prune_strategy = :keep_last_run | |
Capybara::Screenshot.prune_strategy = { keep: 20 } | ||
``` | ||
|
||
Callbacks | ||
--------- | ||
|
||
You can hook your own logic into callbacks after the html/screenshot has been saved. | ||
|
||
```ruby | ||
# after Saver#save_html | ||
Capybara::Screenshot.after_save_html do |path| | ||
mail = Mail.new do | ||
delivery_method :sendmail | ||
from '[email protected]' | ||
to '[email protected]' | ||
subject 'Capybara Screenshot' | ||
add_file File.read path | ||
end | ||
mail.delivery_method :sendmail | ||
mail.deliver | ||
end | ||
|
||
# after Saver#save_screenshot | ||
Capybara::Screenhot.after_save_screenshot do |path| | ||
# ... | ||
end | ||
``` | ||
|
||
Information about screenshots in RSpec output | ||
--------------------------------------------- | ||
|
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,44 @@ | ||
module Capybara | ||
module Screenshot | ||
module Callbacks | ||
class CallbackSet < Array | ||
def call *args | ||
each do |callback| | ||
callback.call *args | ||
end | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def callbacks | ||
@callbacks ||= {} | ||
end | ||
|
||
def define_callback name | ||
callbacks[name] ||= CallbackSet.new | ||
|
||
define_singleton_method name do |&block| | ||
callbacks[name] << block | ||
end | ||
end | ||
|
||
def run_callbacks name, *args | ||
if cb_set = callbacks[name] | ||
cb_set.call *args | ||
end | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def run_callbacks name, *args | ||
self.class.run_callbacks name, *args | ||
end | ||
end | ||
|
||
def self.included receiver | ||
receiver.extend ClassMethods | ||
receiver.send :include, InstanceMethods | ||
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