Skip to content

Commit

Permalink
Update features
Browse files Browse the repository at this point in the history
  • Loading branch information
josepjaume committed Oct 14, 2011
1 parent ea76d35 commit 22afc7c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gemspec
group :test do
gem 'guard'
gem 'guard-minitest'
gem 'guard-spinach'
end

group :darwin do
Expand Down
7 changes: 7 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ guard 'minitest' do
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
watch(%r|^test/test_helper\.rb|) { "test" }
end

guard 'spinach' do
watch(%r|^features/(.*)\.feature|)
watch(%r|^features/steps/(.*)([^/]+)\.rb|) do |m|
"features/#{m[1]}#{m[2]}.feature"
end
end
File renamed without changes.
24 changes: 22 additions & 2 deletions lib/spinach/hookable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
module Spinach
# The hookable module includes subscription capabilities to the class in which
# it is included.
#
# Take in account that while most subscription/notification mechanism work
# at the class level, Hookable defines hooks at the instance level - so they
# are not the same in all the class instances.
module Hookable

def self.included(base)
Expand Down Expand Up @@ -27,6 +33,9 @@ def hook(hook)
module InstanceMethods
attr_writer :hooks

# @return [Hash]
# hash in which the key is the hook name and the value an array of any
# defined callbacks, or nil.
def hooks
@hooks ||= {}
end
Expand All @@ -36,22 +45,33 @@ def reset
self.hooks = {}
end

# Runs a particular hook
# Runs a particular hook given a set of arguments
#
# @param [String] name
# the hook's name
#
# @param [
def run_hook(name, *args)
if callbacks = hooks[name.to_sym]
callbacks.each{ |c| c.call(*args) }
end
end

# @param [String] name
# the hook's identifier
#
# @return [Array]
# array of hooks for that particular identifier
def hooks_for(name)
hooks[name.to_sym] || []
end

# Adds a hook to the queue
#
# @param [String] name
# the hook's identifier
#
# @param [Proc] block
# an action to perform once that hook is executed
def add_hook(name, &block)
hooks[name.to_sym] ||= []
hooks[name.to_sym] << block
Expand Down
23 changes: 3 additions & 20 deletions lib/spinach/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
require_relative 'hookable'

module Spinach
# The hooks class is a subscription/notification mechanism that allows you to
# hook into signals provided by the runner and perform certain actions on
# it.
#
# @example
# Spinach.hooks.before_run do
# # Runs before the entire spinach execution
# end
#
# Spinach.hooks.before_scenario do |scenario_data|
# # Runs before every scenario and passes a hash of the parsed scenario
# # data to the block as argument
# end
#
# Spinach.hooks.on_failed_step do |step_data|
# # Runs before every failed stepand passes a hash of the parsed step
# # data to the block as argument
# end
# Spinach's hooks is a subscription mechanism to allow developers to define
# certain callbacks given several Spinach signals, like running a feature,
# executing a particular step and such.
class Hooks
include Hookable

Expand Down Expand Up @@ -143,7 +128,5 @@ class Hooks
# # step_data contains a hash with this step's data
# end
hook :on_skipped_step

end

end
1 change: 0 additions & 1 deletion test/spinach/hookable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@
end
end
end

end

0 comments on commit 22afc7c

Please sign in to comment.