aspect 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +23 -8
  3. data/README.md +41 -0
  4. data/Rakefile +53 -7
  5. data/VERSION +1 -1
  6. data/aspect.gemspec +12 -15
  7. data/lib/aspect/has_attributes.rb +31 -22
  8. data/lib/aspect/has_registry.rb +28 -0
  9. data/lib/aspect/message_transform.rb +97 -0
  10. data/lib/aspect/validator.rb +112 -0
  11. data/lib/aspect/verifier/check.rb +125 -0
  12. data/lib/aspect/verifier.rb +212 -0
  13. data/lib/aspect/version.rb +3 -0
  14. data/lib/aspect.rb +1 -2
  15. data/spec/coverage/assets/0.10.0/application.css +799 -0
  16. data/spec/coverage/assets/0.10.0/application.js +1707 -0
  17. data/spec/coverage/assets/0.10.0/colorbox/border.png +0 -0
  18. data/spec/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  19. data/spec/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  20. data/spec/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  21. data/spec/coverage/assets/0.10.0/favicon_green.png +0 -0
  22. data/spec/coverage/assets/0.10.0/favicon_red.png +0 -0
  23. data/spec/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  24. data/spec/coverage/assets/0.10.0/loading.gif +0 -0
  25. data/spec/coverage/assets/0.10.0/magnify.png +0 -0
  26. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  27. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  28. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  29. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  30. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  31. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  32. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  33. data/spec/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  34. data/spec/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  35. data/spec/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  36. data/spec/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  37. data/spec/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  38. data/spec/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  39. data/spec/coverage/index.html +72 -0
  40. data/spec/lib/aspect/has_attributes_spec.rb +247 -67
  41. data/spec/mutants.txt +12676 -0
  42. data/spec/spec_helper.rb +1 -0
  43. metadata +63 -19
@@ -0,0 +1,72 @@
1
+ <!DOCTYPE html>
2
+ <html xmlns='http://www.w3.org/1999/xhtml'>
3
+ <head>
4
+ <title>Code coverage for Aspect</title>
5
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
+ <script src='./assets/0.10.0/application.js' type='text/javascript'></script>
7
+ <link href='./assets/0.10.0/application.css' media='screen, projection, print' rel='stylesheet' type='text/css'>
8
+ <link rel="shortcut icon" type="image/png" href="./assets/0.10.0/favicon_green.png" />
9
+ <link rel="icon" type="image/png" href="./assets/0.10.0/favicon.png" />
10
+ </head>
11
+
12
+ <body>
13
+ <div id="loading">
14
+ <img src="./assets/0.10.0/loading.gif" alt="loading"/>
15
+ </div>
16
+ <div id="wrapper" style="display:none;">
17
+ <div class="timestamp">Generated <abbr class="timeago" title="2016-02-03T20:13:38-05:00">2016-02-03T20:13:38-05:00</abbr></div>
18
+ <ul class="group_tabs"></ul>
19
+
20
+ <div id="content">
21
+ <div class="file_list_container" id="AllFiles">
22
+ <h2>
23
+ <span class="group_name">All Files</span>
24
+ (<span class="covered_percent"><span class="green">100.0%</span></span>
25
+ covered at
26
+ <span class="covered_strength">
27
+ <span class="red">
28
+ 0.0
29
+ </span>
30
+ </span> hits/line)
31
+ </h2>
32
+ <a name="AllFiles"></a>
33
+ <div>
34
+ <b>0</b> files in total.
35
+ <b>0.0</b> relevant lines.
36
+ <span class="green"><b>0.0</b> lines covered</span> and
37
+ <span class="red"><b>0.0</b> lines missed </span>
38
+ </div>
39
+ <table class="file_list">
40
+ <thead>
41
+ <tr>
42
+ <th>File</th>
43
+ <th>% covered</th>
44
+ <th>Lines</th>
45
+ <th>Relevant Lines</th>
46
+ <th>Lines covered</th>
47
+ <th>Lines missed</th>
48
+ <th>Avg. Hits / Line</th>
49
+ </tr>
50
+ </thead>
51
+ <tbody>
52
+
53
+ </tbody>
54
+ </table>
55
+ </div>
56
+
57
+
58
+
59
+ </div>
60
+
61
+ <div id="footer">
62
+ Generated by <a href="http://github.com/colszowka/simplecov">simplecov</a> v0.11.1
63
+ and simplecov-html v0.10.0<br/>
64
+ using RSpec
65
+ </div>
66
+
67
+ <div class="source_files">
68
+
69
+ </div>
70
+ </div>
71
+ </body>
72
+ </html>
@@ -1,13 +1,19 @@
1
1
  require "spec_helper"
2
2
 
3
+ class TestObject
4
+ include Aspect::HasAttributes
5
+
6
+ def initialize
7
+ @name = "foobar"
8
+ end
9
+ end
10
+
3
11
  describe Aspect::HasAttributes do
4
12
  describe ".attribute" do
5
13
  context "when no options are given" do
6
14
  context "and no block is given" do
7
15
  let(:instance) do
8
- instance_class = Class.new do
9
- include Aspect::HasAttributes
10
-
16
+ instance_class = Class.new(TestObject) do
11
17
  attribute(:name)
12
18
  end
13
19
 
@@ -15,7 +21,7 @@ describe Aspect::HasAttributes do
15
21
  end
16
22
 
17
23
  it "should define a getter and a setter which uses the argument given to set the instance variable" do
18
- expect(instance.name).to eq(nil)
24
+ expect(instance.name).to eq("foobar")
19
25
  instance.name = "foo"
20
26
  expect(instance.name).to eq("foo")
21
27
  end
@@ -23,9 +29,7 @@ describe Aspect::HasAttributes do
23
29
 
24
30
  context "and a block is given" do
25
31
  let(:instance) do
26
- instance_class = Class.new do
27
- include Aspect::HasAttributes
28
-
32
+ instance_class = Class.new(TestObject) do
29
33
  attribute(:name) { |value| value.to_s }
30
34
  end
31
35
 
@@ -33,7 +37,7 @@ describe Aspect::HasAttributes do
33
37
  end
34
38
 
35
39
  it "should define a getter and a setter which uses the return value of the block to set the instance variable" do
36
- expect(instance.name).to eq(nil)
40
+ expect(instance.name).to eq("foobar")
37
41
  instance.name = 123
38
42
  expect(instance.name).to eq("123")
39
43
  end
@@ -43,25 +47,73 @@ describe Aspect::HasAttributes do
43
47
  context "when the :getter option is given" do
44
48
  context "and it's truthy" do
45
49
  let(:instance) do
46
- instance_class = Class.new do
47
- include Aspect::HasAttributes
48
-
50
+ instance_class = Class.new(TestObject) do
49
51
  attribute(:name, getter: true)
50
52
  end
51
53
 
52
54
  instance_class.new
53
55
  end
54
56
 
55
- it "should define a query getter which uses the argument given to set the instance variable" do
56
- expect(instance.name).to eq(nil)
57
+ it "should define the getter" do
58
+ expect(instance.name).to eq("foobar")
59
+ end
60
+
61
+ context "and it's a Hash" do
62
+ context "and the :method option is passed" do
63
+ let(:instance) do
64
+ instance_class = Class.new(TestObject) do
65
+ attribute(:name, getter: { method: :capitalize })
66
+ end
67
+
68
+ instance_class.new
69
+ end
70
+
71
+ it "define the getter which calls the given method on the instance variable" do
72
+ expect(instance.name).to eq("Foobar")
73
+ end
74
+ end
75
+
76
+ context "and the :instance_method option is passed" do
77
+ let(:instance) do
78
+ instance_class = Class.new(TestObject) do
79
+ attribute(:name, getter: { instance_method: :reversitalize })
80
+
81
+ def reversitalize(value)
82
+ value.reverse.capitalize
83
+ end
84
+ end
85
+
86
+ instance_class.new
87
+ end
88
+
89
+ it "define the getter which calls the given instance method, passing the instance variable as the argument" do
90
+ expect(instance.name).to eq("Raboof")
91
+ end
92
+ end
93
+
94
+ context "and both the :method and :instance_method options are passed" do
95
+ let(:instance) do
96
+ instance_class = Class.new(TestObject) do
97
+ attribute(:name, getter: { method: :capitalize, instance_method: :exclamationize })
98
+
99
+ def exclamationize(value)
100
+ "#{value}!"
101
+ end
102
+ end
103
+
104
+ instance_class.new
105
+ end
106
+
107
+ it "define the getter which calls the given instance method, passing the result of the method called on the instance variable as the argument" do
108
+ expect(instance.name).to eq("Foobar!")
109
+ end
110
+ end
57
111
  end
58
112
  end
59
113
 
60
114
  context "and it's falsey" do
61
115
  let(:instance) do
62
- instance_class = Class.new do
63
- include Aspect::HasAttributes
64
-
116
+ instance_class = Class.new(TestObject) do
65
117
  attribute(:name, getter: false)
66
118
  end
67
119
 
@@ -69,7 +121,7 @@ describe Aspect::HasAttributes do
69
121
  end
70
122
 
71
123
  it "should not define a getter" do
72
- expect(instance.respond_to?(:name)).to eq(false)
124
+ expect(instance).not_to respond_to(:name)
73
125
  end
74
126
  end
75
127
  end
@@ -78,37 +130,90 @@ describe Aspect::HasAttributes do
78
130
  context "and no block is given" do
79
131
  context "and it's truthy" do
80
132
  let(:instance) do
81
- instance_class = Class.new do
82
- include Aspect::HasAttributes
83
-
133
+ instance_class = Class.new(TestObject) do
84
134
  attribute(:name, setter: true)
85
135
  end
86
136
 
87
137
  instance_class.new
88
138
  end
89
139
 
90
- it "should define a query setter which uses the argument given to set the instance variable" do
91
- expect(instance.name).to eq(nil)
140
+ it "should define a setter which uses the argument given to set the instance variable" do
141
+ expect(instance.name).to eq("foobar")
92
142
  instance.name = "foobar"
93
143
  expect(instance.name).to eq("foobar")
94
144
  end
145
+
146
+ context "and it's a Hash" do
147
+ context "and the :method option is passed" do
148
+ let(:instance) do
149
+ instance_class = Class.new(TestObject) do
150
+ attribute(:name, setter: { method: :capitalize })
151
+ end
152
+
153
+ instance_class.new
154
+ end
155
+
156
+ it "should define the setter which calls the given method on the instance variable" do
157
+ expect(instance.name).to eq("foobar")
158
+ instance.name = "foobar"
159
+ expect(instance.name).to eq("Foobar")
160
+ end
161
+ end
162
+
163
+ context "and the :instance_method option is passed" do
164
+ let(:instance) do
165
+ instance_class = Class.new(TestObject) do
166
+ attribute(:name, setter: { instance_method: :reversitalize })
167
+
168
+ def reversitalize(value)
169
+ value.reverse.capitalize
170
+ end
171
+ end
172
+
173
+ instance_class.new
174
+ end
175
+
176
+ it "should define the setter which calls the given instance method, passing the instance variable as the argument" do
177
+ expect(instance.name).to eq("foobar")
178
+ instance.name = "foobar"
179
+ expect(instance.name).to eq("Raboof")
180
+ end
181
+ end
182
+
183
+ context "and both the :method and :instance_method options are passed" do
184
+ let(:instance) do
185
+ instance_class = Class.new(TestObject) do
186
+ attribute(:name, setter: { method: :capitalize, instance_method: :exclamationize })
187
+
188
+ def exclamationize(value)
189
+ "#{value}!"
190
+ end
191
+ end
192
+
193
+ instance_class.new
194
+ end
195
+
196
+ it "define the setter which calls the given instance method, passing the result of the method called on the instance variable as the argument" do
197
+ expect(instance.name).to eq("foobar")
198
+ instance.name = "foobar"
199
+ expect(instance.name).to eq("Foobar!")
200
+ end
201
+ end
202
+ end
95
203
  end
96
204
 
97
205
  context "and it's falsey" do
98
206
  let(:instance) do
99
- instance_class = Class.new do
100
- include Aspect::HasAttributes
101
-
102
- attribute(:admin, query: false)
207
+ instance_class = Class.new(TestObject) do
208
+ attribute(:name, setter: false)
103
209
  end
104
210
 
105
211
  instance_class.new
106
212
  end
107
213
 
108
- it "should define a getter and a setter which uses the return value of the block to set the instance variable" do
109
- expect(instance.admin).to eq(nil)
110
- instance.admin = "truthy"
111
- expect(instance.admin).to eq("truthy")
214
+ it "should define a getter and not a setter" do
215
+ expect(instance).to respond_to(:name)
216
+ expect(instance).not_to respond_to(:name=)
112
217
  end
113
218
  end
114
219
  end
@@ -116,43 +221,90 @@ describe Aspect::HasAttributes do
116
221
  context "and a block is given" do
117
222
  context "and it's truthy" do
118
223
  let(:instance) do
119
- instance_class = Class.new do
120
- include Aspect::HasAttributes
121
-
122
- attribute(:moderator, query: true)
123
- attribute(:admin, query: true) { |value| @moderator && value }
224
+ instance_class = Class.new(TestObject) do
225
+ attribute(:name, setter: true) { |value| value.reverse }
124
226
  end
125
227
 
126
228
  instance_class.new
127
229
  end
128
230
 
129
- it "should define a query getter and a query setter which uses the return value of the block to set the instance variable as a truthy value" do
130
- expect(instance.moderator?).to eq(false)
131
- expect(instance.admin?).to eq(false)
132
- instance.admin = "truthy"
133
- expect(instance.admin?).to eq(false)
134
- instance.moderator = true
135
- instance.admin = "truthy"
136
- expect(instance.moderator?).to eq(true)
137
- expect(instance.admin?).to eq(true)
231
+ it "should define a setter which uses the argument given to set the instance variable" do
232
+ expect(instance.name).to eq("foobar")
233
+ instance.name = "foobar"
234
+ expect(instance.name).to eq("raboof")
235
+ end
236
+
237
+ context "and it's a Hash" do
238
+ context "and the :method option is passed" do
239
+ let(:instance) do
240
+ instance_class = Class.new(TestObject) do
241
+ attribute(:name, setter: { method: :capitalize })
242
+ end
243
+
244
+ instance_class.new
245
+ end
246
+
247
+ it "should define the setter which calls the given method on the instance variable" do
248
+ expect(instance.name).to eq("foobar")
249
+ instance.name = "foobar"
250
+ expect(instance.name).to eq("Foobar")
251
+ end
252
+ end
253
+
254
+ context "and the :instance_method option is passed" do
255
+ let(:instance) do
256
+ instance_class = Class.new(TestObject) do
257
+ attribute(:name, setter: { instance_method: :reversitalize })
258
+
259
+ def reversitalize(value)
260
+ value.reverse.capitalize
261
+ end
262
+ end
263
+
264
+ instance_class.new
265
+ end
266
+
267
+ it "should define the setter which calls the given instance method, passing the instance variable as the argument" do
268
+ expect(instance.name).to eq("foobar")
269
+ instance.name = "foobar"
270
+ expect(instance.name).to eq("Raboof")
271
+ end
272
+ end
273
+
274
+ context "and both the :method and :instance_method options are passed" do
275
+ let(:instance) do
276
+ instance_class = Class.new(TestObject) do
277
+ attribute(:name, setter: { method: :capitalize, instance_method: :exclamationize })
278
+
279
+ def exclamationize(value)
280
+ "#{value}!"
281
+ end
282
+ end
283
+
284
+ instance_class.new
285
+ end
286
+
287
+ it "define the setter which calls the given instance method, passing the result of the method called on the instance variable as the argument" do
288
+ expect(instance.name).to eq("foobar")
289
+ instance.name = "foobar"
290
+ expect(instance.name).to eq("Foobar!")
291
+ end
292
+ end
138
293
  end
139
294
  end
140
295
 
141
296
  context "and it's falsey" do
142
297
  let(:instance) do
143
- instance_class = Class.new do
144
- include Aspect::HasAttributes
145
-
146
- attribute(:admin, query: false) { "return value" }
298
+ instance_class = Class.new(TestObject) do
299
+ attribute(:name, setter: false)
147
300
  end
148
301
 
149
302
  instance_class.new
150
303
  end
151
304
 
152
- it "should define a getter and a setter which uses the return value of the block to set the instance variable" do
153
- expect(instance.admin).to eq(nil)
154
- instance.admin = "anything"
155
- expect(instance.admin).to eq("return value")
305
+ it "should define a getter and not a setter" do
306
+ expect(instance).to respond_to(:name)
307
+ expect(instance).not_to respond_to(:name=)
156
308
  end
157
309
  end
158
310
  end
@@ -162,9 +314,7 @@ describe Aspect::HasAttributes do
162
314
  context "and no block is given" do
163
315
  context "and it's truthy" do
164
316
  let(:instance) do
165
- instance_class = Class.new do
166
- include Aspect::HasAttributes
167
-
317
+ instance_class = Class.new(TestObject) do
168
318
  attribute(:admin, query: true)
169
319
  end
170
320
 
@@ -180,9 +330,7 @@ describe Aspect::HasAttributes do
180
330
 
181
331
  context "and it's falsey" do
182
332
  let(:instance) do
183
- instance_class = Class.new do
184
- include Aspect::HasAttributes
185
-
333
+ instance_class = Class.new(TestObject) do
186
334
  attribute(:admin, query: false)
187
335
  end
188
336
 
@@ -200,9 +348,7 @@ describe Aspect::HasAttributes do
200
348
  context "and a block is given" do
201
349
  context "and it's truthy" do
202
350
  let(:instance) do
203
- instance_class = Class.new do
204
- include Aspect::HasAttributes
205
-
351
+ instance_class = Class.new(TestObject) do
206
352
  attribute(:moderator, query: true)
207
353
  attribute(:admin, query: true) { |value| @moderator && value }
208
354
  end
@@ -224,9 +370,7 @@ describe Aspect::HasAttributes do
224
370
 
225
371
  context "and it's falsey" do
226
372
  let(:instance) do
227
- instance_class = Class.new do
228
- include Aspect::HasAttributes
229
-
373
+ instance_class = Class.new(TestObject) do
230
374
  attribute(:admin, query: false) { "return value" }
231
375
  end
232
376
 
@@ -245,9 +389,7 @@ describe Aspect::HasAttributes do
245
389
 
246
390
  describe "#update_attributes" do
247
391
  let(:instance) do
248
- class_instance = Class.new do
249
- include Aspect::HasAttributes
250
-
392
+ class_instance = Class.new(TestObject) do
251
393
  attr_accessor :name
252
394
  attr_accessor :age
253
395
  end
@@ -262,4 +404,42 @@ describe Aspect::HasAttributes do
262
404
  expect(instance.age).to eq(123)
263
405
  end
264
406
  end
407
+
408
+ context "when included from the method", pending: true do
409
+ context "and the :method option is passed" do
410
+ context "and the values are not nil" do
411
+ let(:instance) do
412
+ class_instance = Class.new do
413
+ include Aspect::HasAttributes(method: { define: :atr, update: :mass_assign })
414
+ end
415
+
416
+ class_instance.new
417
+ end
418
+
419
+ it "should update the attributes on the instance" do
420
+ expect(instance.class).to respond_to("atr")
421
+ expect(instance.class).not_to respond_to("attribute")
422
+ expect(instance).to respond_to("mass_assign")
423
+ expect(instance).not_to respond_to("update_attributes")
424
+ end
425
+ end
426
+
427
+ context "and the values are nil" do
428
+ let(:instance) do
429
+ class_instance = Class.new do
430
+ include Aspect::HasAttributes(method: { define: nil, update: nil })
431
+ end
432
+
433
+ class_instance.new
434
+ end
435
+
436
+ it "should update the attributes on the instance" do
437
+ expect(instance.class).not_to respond_to("atr")
438
+ expect(instance.class).not_to respond_to("attribute")
439
+ expect(instance).not_to respond_to("mass_assign")
440
+ expect(instance).not_to respond_to("update_attributes")
441
+ end
442
+ end
443
+ end
444
+ end
265
445
  end