rspec-plugins 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/LICENSE +1 -1
- data/lib/rspec-plugins/core.rb +33 -20
- data/lib/rspec-plugins/version.rb +1 -1
- data/spec/counter_plugin_spec.rb +46 -13
- metadata +8 -3
data/.gitignore
CHANGED
data/LICENSE
CHANGED
@@ -176,7 +176,7 @@ recommend that a file or class name and description of purpose be included on
|
|
176
176
|
the same "printed page" as the copyright notice for easier identification within
|
177
177
|
third-party archives.
|
178
178
|
|
179
|
-
Copyright [
|
179
|
+
Copyright [2013] [Drachenfels Gmbh, Ruben Jenster]
|
180
180
|
|
181
181
|
Licensed under the Apache License, Version 2.0 (the "License");
|
182
182
|
you may not use this file except in compliance with the License.
|
data/lib/rspec-plugins/core.rb
CHANGED
@@ -2,6 +2,9 @@ require 'rspec/core'
|
|
2
2
|
|
3
3
|
module RSpec::Plugins
|
4
4
|
module Core
|
5
|
+
|
6
|
+
class NoPluginError < NameError; end
|
7
|
+
|
5
8
|
class << self
|
6
9
|
attr_accessor :debug
|
7
10
|
|
@@ -18,17 +21,7 @@ module RSpec::Plugins
|
|
18
21
|
example_group.metadata[:plugins] = proxy
|
19
22
|
example_group.define_singleton_method(:plugins) { proxy }
|
20
23
|
example_group.define_singleton_method :plugin do |plugin_id, meth, *args, &block|
|
21
|
-
|
22
|
-
plugin = proxy[plugin_id]
|
23
|
-
if plugin.nil?
|
24
|
-
raise("No plugin with id :#{plugin_id} enabled. Enabled plugins: #{proxy.plugins.keys}")
|
25
|
-
else
|
26
|
-
current_example_group.before(:all) do
|
27
|
-
plugin.current_example_group = current_example_group
|
28
|
-
Core.log("Calling plugin method #{plugin}##{meth}")
|
29
|
-
plugin.send(meth, *args, &block)
|
30
|
-
end
|
31
|
-
end
|
24
|
+
proxy.dispatch(self, plugin_id, meth, *args, &block)
|
32
25
|
end
|
33
26
|
log "Included RSpec::Plugins::Core in example group [#{example_group.description}]"
|
34
27
|
end
|
@@ -43,8 +36,8 @@ module RSpec::Plugins
|
|
43
36
|
@plugins = {}
|
44
37
|
end
|
45
38
|
|
46
|
-
def [](
|
47
|
-
@plugins[
|
39
|
+
def [](plugin_id)
|
40
|
+
@plugins[plugin_id]
|
48
41
|
end
|
49
42
|
|
50
43
|
def enable(enable_plugins)
|
@@ -52,6 +45,7 @@ module RSpec::Plugins
|
|
52
45
|
enable_plugins.each_pair do |key, plugin|
|
53
46
|
Core.log "Add plugin :#{key}"
|
54
47
|
plugin.proxy = proxy
|
48
|
+
plugin.id = key
|
55
49
|
# TODO check for duplicates
|
56
50
|
@plugins[key] = plugin
|
57
51
|
@example_group.send :before, :all do |running_example_group|
|
@@ -60,9 +54,9 @@ module RSpec::Plugins
|
|
60
54
|
Core.log "Enabled plugin :#{key}"
|
61
55
|
end
|
62
56
|
if plugin.respond_to?(:around)
|
63
|
-
@example_group.send :around, :each do |
|
57
|
+
@example_group.send :around, :each do |example|
|
64
58
|
Core.log "Calling #{plugin}#around"
|
65
|
-
plugin.around(
|
59
|
+
plugin.around(example)
|
66
60
|
end
|
67
61
|
end
|
68
62
|
@example_group.send :after, :all do |running_example_group|
|
@@ -73,16 +67,26 @@ module RSpec::Plugins
|
|
73
67
|
end
|
74
68
|
end
|
75
69
|
end
|
70
|
+
|
71
|
+
def dispatch(current_example_group, plugin_id, meth, *args, &block)
|
72
|
+
plugin = @plugins[plugin_id]
|
73
|
+
if plugin
|
74
|
+
current_example_group.before(:all) do
|
75
|
+
plugin.current_example_group = current_example_group
|
76
|
+
Core.log "Dispatching method :#{meth} to #{plugin}"
|
77
|
+
plugin.dispatch(meth, *args, &block)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
raise Core::NoPluginError, "Plugin :#{plugin_id} not found. Available plugins: #{@plugins.keys}"
|
81
|
+
end
|
82
|
+
end
|
76
83
|
end
|
77
84
|
|
78
85
|
class Base
|
79
|
-
attr_accessor :enabled, :proxy, :current_example_group
|
80
|
-
|
81
|
-
def log(message)
|
82
|
-
Core.log(message)
|
83
|
-
end
|
86
|
+
attr_accessor :id, :enabled, :proxy, :current_example_group
|
84
87
|
|
85
88
|
def initialize
|
89
|
+
@id = nil
|
86
90
|
@enabled = false
|
87
91
|
@proxy = nil
|
88
92
|
@current_example_group = nil
|
@@ -96,6 +100,15 @@ module RSpec::Plugins
|
|
96
100
|
@enabled = false
|
97
101
|
end
|
98
102
|
|
103
|
+
def dispatch(meth, *args, &block)
|
104
|
+
send meth, *args, &block
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
def log(message)
|
109
|
+
Core.log "plugin[#{id}]: #{message}"
|
110
|
+
end
|
111
|
+
|
99
112
|
def after(*args, &block)
|
100
113
|
plugin = self
|
101
114
|
@current_example_group.send :after, :all do
|
data/spec/counter_plugin_spec.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class CounterPlugin < RSpec::Plugins::Base
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :count, :count_after, :count_around
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
super
|
8
|
-
@
|
8
|
+
@count = 0
|
9
|
+
@count_after = 0
|
10
|
+
@count_around = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def around(example)
|
14
|
+
@count_around += 1
|
9
15
|
end
|
10
16
|
|
11
17
|
def increment
|
12
|
-
@
|
18
|
+
@count += 1
|
19
|
+
after do |plugin|
|
20
|
+
log "Setting @count_after to @count*2"
|
21
|
+
plugin.count_after = @count*2
|
22
|
+
end
|
13
23
|
end
|
14
24
|
end
|
15
25
|
|
@@ -29,12 +39,16 @@ describe '-- #1 plugins' do
|
|
29
39
|
|
30
40
|
describe "plugin :counter" do
|
31
41
|
subject { plugins[:counter] }
|
32
|
-
its(:
|
42
|
+
its(:id) { should eq(:counter) }
|
43
|
+
its(:count) { should eq(2) }
|
44
|
+
its(:count_after) { should eq(0) }
|
33
45
|
end
|
34
46
|
|
35
47
|
describe "plugin :counter2" do
|
36
48
|
subject { plugins[:counter2] }
|
37
|
-
its(:
|
49
|
+
its(:id) { should eq(:counter2) }
|
50
|
+
its(:count) { should eq(1) }
|
51
|
+
its(:count_after) { should eq(0) }
|
38
52
|
end
|
39
53
|
|
40
54
|
context "counter.increment 1, counter2.increment 2" do
|
@@ -44,12 +58,14 @@ describe '-- #1 plugins' do
|
|
44
58
|
|
45
59
|
describe "plugin :counter" do
|
46
60
|
subject { plugins[:counter] }
|
47
|
-
its(:
|
61
|
+
its(:count) { should eq(3) }
|
62
|
+
its(:count_after) { should eq(0) }
|
48
63
|
end
|
49
64
|
|
50
65
|
describe "plugin :counter2" do
|
51
66
|
subject { plugins[:counter2] }
|
52
|
-
its(:
|
67
|
+
its(:count) { should eq(3) }
|
68
|
+
its(:count_after) { should eq(0) }
|
53
69
|
end
|
54
70
|
end
|
55
71
|
end
|
@@ -60,12 +76,14 @@ describe '-- #1 plugins' do
|
|
60
76
|
|
61
77
|
describe "plugin :counter" do
|
62
78
|
subject { plugins[:counter] }
|
63
|
-
its(:
|
79
|
+
its(:count) { should eq(3) }
|
80
|
+
its(:count_after) { should eq(6) }
|
64
81
|
end
|
65
82
|
|
66
83
|
describe "plugin :counter2" do
|
67
84
|
subject { plugins[:counter2] }
|
68
|
-
its(:
|
85
|
+
its(:count) { should eq(5) }
|
86
|
+
its(:count_after) { should eq(6) }
|
69
87
|
end
|
70
88
|
end
|
71
89
|
end
|
@@ -76,14 +94,29 @@ describe '-- #2 plugins' do
|
|
76
94
|
let(:plugins) { example.metadata[:plugins] }
|
77
95
|
plugins.enable :counter => CounterPlugin.new
|
78
96
|
|
79
|
-
describe "#plugins" do
|
97
|
+
describe "#plugins[:counter]" do
|
80
98
|
subject { plugins[:counter] }
|
81
|
-
its(:
|
99
|
+
its(:count) { should eq(0) }
|
100
|
+
its(:count_after) { should eq(0) }
|
82
101
|
end
|
83
102
|
|
84
|
-
describe "#plugins" do
|
103
|
+
describe "#plugins[:counter]" do
|
85
104
|
plugin :counter, :increment
|
86
105
|
subject { plugins[:counter] }
|
87
|
-
its(:
|
106
|
+
its(:count) { should eq(1) }
|
107
|
+
its(:count_after) { should eq(0) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "-- #3 plugins" do
|
112
|
+
include RSpec::Plugins::Core
|
113
|
+
|
114
|
+
let(:plugins) { example.metadata[:plugins] }
|
115
|
+
describe "fail if no plugin is enabled" do
|
116
|
+
it "should fail" do
|
117
|
+
expect {
|
118
|
+
plugins.dispatch(:foobar, :mymethod, :arg1)
|
119
|
+
}.to raise_error RSpec::Plugins::Core::NoPluginError
|
120
|
+
end
|
88
121
|
end
|
89
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -89,12 +89,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- - ! '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
hash: -630404549343680935
|
92
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
96
|
none: false
|
94
97
|
requirements:
|
95
98
|
- - ! '>='
|
96
99
|
- !ruby/object:Gem::Version
|
97
100
|
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: -630404549343680935
|
98
104
|
requirements: []
|
99
105
|
rubyforge_project:
|
100
106
|
rubygems_version: 1.8.25
|
@@ -105,4 +111,3 @@ summary: Make your hooks reusable through in a plugin module or easily create a
|
|
105
111
|
test_files:
|
106
112
|
- spec/counter_plugin_spec.rb
|
107
113
|
- spec/spec_helper.rb
|
108
|
-
has_rdoc:
|