filtration 0.0.6 → 0.0.7

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.
Files changed (3) hide show
  1. data/lib/filtration.rb +0 -2
  2. data/spec/filtration_spec.rb +42 -0
  3. metadata +22 -38
@@ -28,8 +28,6 @@ module Filtration
28
28
  if filter.nil?
29
29
  block.call(old_method.bind(self).call(*args))
30
30
  else
31
- filter_method = method(filter)
32
- raise "Filter method #{filter} takes 0 arguments" if filter_method.arity == 0
33
31
  self.send(filter,old_method.bind(self).call(*args))
34
32
  end
35
33
  end
@@ -121,6 +121,47 @@ describe Filtration do
121
121
  end
122
122
  end
123
123
 
124
+ context 'and both a filter method and a block' do
125
+ it 'raises an error' do
126
+ test = Class.new(Good) do
127
+ extend RSpec::Matchers
128
+ expect { postfilter(:foo,:double) {|x| x * 2} }.to raise_error
129
+ def double(x) x * 2; end
130
+ end
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ context 'given a target method with no arguments' do
137
+
138
+ context 'and a code block for filtering' do
139
+ it 'executes the block on the target method argument' do
140
+ test = Class.new(Bad) { postfilter(:foo){|x| x * 2} }
141
+ test.new.foo.should === 4
142
+ end
143
+ end
144
+
145
+ context 'and a valid filter method' do
146
+ it 'executes the filter method on the target method argument' do
147
+ test = Class.new(Bad) do
148
+ postfilter :foo, :double
149
+ def double(x) x * 2; end
150
+ end
151
+ test.new.foo.should === 4
152
+ end
153
+ end
154
+
155
+ context 'and an invalid filter method' do
156
+ it 'raises an error' do
157
+ test = Class.new(Bad) do
158
+ postfilter :foo, :double
159
+ def double() 2; end
160
+ end
161
+ expect { test.new.foo }.to raise_error
162
+ end
163
+ end
164
+
124
165
  context 'and both a filter method and a block' do
125
166
  it 'raises an error' do
126
167
  test = Class.new(Bad) do
@@ -133,6 +174,7 @@ describe Filtration do
133
174
 
134
175
  end
135
176
 
177
+
136
178
  end
137
179
 
138
180
  end
metadata CHANGED
@@ -1,74 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: filtration
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 6
9
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - R. Scott Reis
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-08-13 00:00:00 -05:00
18
- default_executable:
12
+ date: 2011-10-28 00:00:00.000000000Z
19
13
  dependencies: []
20
-
21
14
  description:
22
15
  email:
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
- extra_rdoc_files:
18
+ extra_rdoc_files:
28
19
  - README.rdoc
29
- files:
20
+ files:
30
21
  - LICENSE
31
22
  - README.rdoc
32
23
  - lib/filtration.rb
33
24
  - spec/spec_helper.rb
34
25
  - spec/spec_dummies.rb
35
26
  - spec/filtration_spec.rb
36
- has_rdoc: true
37
27
  homepage:
38
28
  licenses: []
39
-
40
29
  post_install_message:
41
- rdoc_options:
30
+ rdoc_options:
42
31
  - -m
43
32
  - README.rdoc
44
33
  - -t
45
34
  - Filtration
46
- require_paths:
35
+ require_paths:
47
36
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
37
+ required_ruby_version: !ruby/object:Gem::Requirement
49
38
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
44
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- segments:
62
- - 0
63
- version: "0"
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
64
49
  requirements: []
65
-
66
50
  rubyforge_project:
67
- rubygems_version: 1.3.7
51
+ rubygems_version: 1.8.6
68
52
  signing_key:
69
53
  specification_version: 3
70
54
  summary: Filtration enables pre/post method callback, similar to Python decorators
71
- test_files:
55
+ test_files:
72
56
  - spec/spec_helper.rb
73
57
  - spec/spec_dummies.rb
74
58
  - spec/filtration_spec.rb