Class: RSpec::Plugins::Proxy
- Inherits:
-
Object
- Object
- RSpec::Plugins::Proxy
- Defined in:
- lib/rspec-plugins/core.rb
Instance Attribute Summary collapse
-
#example_group ⇒ Object
readonly
Returns the value of attribute example_group.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
- #[](plugin_id) ⇒ Object
- #dispatch(current_example_group, plugin_id, meth, *args, &block) ⇒ Object
- #enable(enable_plugins) ⇒ Object
-
#initialize(example_group) ⇒ Proxy
constructor
A new instance of Proxy.
Constructor Details
#initialize(example_group) ⇒ Proxy
Returns a new instance of Proxy.
34 35 36 37 |
# File 'lib/rspec-plugins/core.rb', line 34 def initialize(example_group) @example_group = example_group @plugins = {} end |
Instance Attribute Details
#example_group ⇒ Object (readonly)
Returns the value of attribute example_group.
32 33 34 |
# File 'lib/rspec-plugins/core.rb', line 32 def example_group @example_group end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
32 33 34 |
# File 'lib/rspec-plugins/core.rb', line 32 def plugins @plugins end |
Instance Method Details
#[](plugin_id) ⇒ Object
39 40 41 |
# File 'lib/rspec-plugins/core.rb', line 39 def [](plugin_id) @plugins[plugin_id] end |
#dispatch(current_example_group, plugin_id, meth, *args, &block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rspec-plugins/core.rb', line 71 def dispatch(current_example_group, plugin_id, meth, *args, &block) plugin = @plugins[plugin_id] if plugin current_example_group.before(:all) do plugin.current_example_group = current_example_group Core.log "Dispatching method :#{meth} to #{plugin}" plugin.dispatch(meth, *args, &block) end else raise Core::NoPluginError, "Plugin :#{plugin_id} not found. Available plugins: #{@plugins.keys}" end end |
#enable(enable_plugins) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rspec-plugins/core.rb', line 43 def enable(enable_plugins) proxy = self enable_plugins.each_pair do |key, plugin| Core.log "Add plugin :#{key}" plugin.proxy = proxy plugin.id = key # TODO check for duplicates @plugins[key] = plugin @example_group.send :before, :all do |running_example_group| plugin.current_example_group = running_example_group plugin.enable Core.log "Enabled plugin :#{key}" end if plugin.respond_to?(:around) @example_group.send :around, :each do |example| Core.log "Calling #{plugin}#around" plugin.around(example) end end @example_group.send :after, :all do |running_example_group| plugin.current_example_group = running_example_group plugin.disable proxy.plugins.delete(key) Core.log "Disabled plugin :#{key}" end end end |