spicycode-micronaut 0.2.3 → 0.2.4
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/VERSION.yml +1 -1
- data/examples/example_helper.rb +10 -2
- data/examples/lib/micronaut/behaviour_example.rb +59 -39
- data/lib/micronaut/behaviour.rb +10 -10
- data/lib/micronaut/configuration.rb +2 -2
- metadata +2 -2
data/VERSION.yml
CHANGED
data/examples/example_helper.rb
CHANGED
@@ -11,6 +11,7 @@ end
|
|
11
11
|
with_ruby("1.8") do
|
12
12
|
gem :mocha
|
13
13
|
end
|
14
|
+
|
14
15
|
require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
|
15
16
|
|
16
17
|
module Micronaut
|
@@ -29,13 +30,20 @@ def remove_last_describe_from_world
|
|
29
30
|
Micronaut.world.behaviours.pop
|
30
31
|
end
|
31
32
|
|
33
|
+
def isolate_behaviour
|
34
|
+
if block_given?
|
35
|
+
yield
|
36
|
+
Micronaut.world.behaviours.pop
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
32
40
|
def not_in_editor?
|
33
|
-
|
41
|
+
!(ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM'))
|
34
42
|
end
|
35
43
|
|
36
44
|
Micronaut.configure do |c|
|
37
45
|
c.mock_with :mocha
|
38
46
|
c.color_enabled = not_in_editor?
|
39
47
|
c.filter_run :focused => true
|
40
|
-
c.formatter = :documentation
|
48
|
+
#c.formatter = :documentation
|
41
49
|
end
|
@@ -2,9 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
|
|
2
2
|
|
3
3
|
describe Micronaut::Behaviour do
|
4
4
|
|
5
|
-
before(:all) { puts "ba: describe Micronaut::Behaviour" }
|
6
|
-
after(:all) { puts "aa: describe Micronaut::Behaviour" }
|
7
|
-
|
8
5
|
def empty_behaviour_group
|
9
6
|
group = Micronaut::Behaviour.describe(Object, 'Empty Behaviour Group') { }
|
10
7
|
remove_last_describe_from_world
|
@@ -12,9 +9,6 @@ describe Micronaut::Behaviour do
|
|
12
9
|
|
13
10
|
describe "describing behaviour with #describe" do
|
14
11
|
|
15
|
-
before(:all) { puts "ba: describing behaviour with #describe" }
|
16
|
-
after(:all) { puts "aa: describing behaviour with #describe" }
|
17
|
-
|
18
12
|
example "an ArgumentError is raised if no type or description is given" do
|
19
13
|
lambda { Micronaut::Behaviour.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
|
20
14
|
end
|
@@ -26,13 +20,15 @@ describe Micronaut::Behaviour do
|
|
26
20
|
describe '#name' do
|
27
21
|
|
28
22
|
it "should expose the first parameter as name" do
|
29
|
-
|
30
|
-
|
23
|
+
isolate_behaviour do
|
24
|
+
Micronaut::Behaviour.describe("my favorite pony") { }.name.should == 'my favorite pony'
|
25
|
+
end
|
31
26
|
end
|
32
27
|
|
33
28
|
it "should call to_s on the first parameter in case it is a constant" do
|
34
|
-
|
35
|
-
|
29
|
+
isolate_behaviour do
|
30
|
+
Micronaut::Behaviour.describe(Object) { }.name.should == 'Object'
|
31
|
+
end
|
36
32
|
end
|
37
33
|
|
38
34
|
end
|
@@ -40,13 +36,15 @@ describe Micronaut::Behaviour do
|
|
40
36
|
describe '#describes' do
|
41
37
|
|
42
38
|
it "should be the first parameter when it is a constant" do
|
43
|
-
|
44
|
-
|
39
|
+
isolate_behaviour do
|
40
|
+
Micronaut::Behaviour.describe(Object) { }.describes.should == Object
|
41
|
+
end
|
45
42
|
end
|
46
43
|
|
47
44
|
it "should be nil when the first parameter is a string" do
|
48
|
-
|
49
|
-
|
45
|
+
isolate_behaviour do
|
46
|
+
Micronaut::Behaviour.describe("i'm a computer") { }.describes.should be_nil
|
47
|
+
end
|
50
48
|
end
|
51
49
|
|
52
50
|
end
|
@@ -54,13 +52,15 @@ describe Micronaut::Behaviour do
|
|
54
52
|
describe '#description' do
|
55
53
|
|
56
54
|
it "should expose the second parameter as description" do
|
57
|
-
|
58
|
-
|
55
|
+
isolate_behaviour do
|
56
|
+
Micronaut::Behaviour.describe(Object, "my desc") { }.description.should == 'my desc'
|
57
|
+
end
|
59
58
|
end
|
60
59
|
|
61
60
|
it "should allow the second parameter to be nil" do
|
62
|
-
|
63
|
-
|
61
|
+
isolate_behaviour do
|
62
|
+
Micronaut::Behaviour.describe(Object, nil) { }.description.size.should == 0
|
63
|
+
end
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
@@ -68,28 +68,33 @@ describe Micronaut::Behaviour do
|
|
68
68
|
describe '#metadata' do
|
69
69
|
|
70
70
|
it "should add the third parameter to the metadata" do
|
71
|
-
|
72
|
-
|
71
|
+
isolate_behaviour do
|
72
|
+
Micronaut::Behaviour.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
|
73
|
+
end
|
73
74
|
end
|
74
75
|
|
75
76
|
it "should add the caller to metadata" do
|
76
|
-
|
77
|
-
|
77
|
+
isolate_behaviour do
|
78
|
+
Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}:#{__LINE__}/
|
79
|
+
end
|
78
80
|
end
|
79
81
|
|
80
82
|
it "should add the the file_path to metadata" do
|
81
|
-
|
82
|
-
|
83
|
+
isolate_behaviour do
|
84
|
+
Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
|
85
|
+
end
|
83
86
|
end
|
84
87
|
|
85
88
|
it "should have a reader for file_path" do
|
86
|
-
|
87
|
-
|
89
|
+
isolate_behaviour do
|
90
|
+
Micronaut::Behaviour.describe(Object) { }.file_path.should == __FILE__
|
91
|
+
end
|
88
92
|
end
|
89
93
|
|
90
94
|
it "should add the line_number to metadata" do
|
91
|
-
|
92
|
-
|
95
|
+
isolate_behaviour do
|
96
|
+
Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
|
97
|
+
end
|
93
98
|
end
|
94
99
|
|
95
100
|
it "should add file path and line number metadata for arbitrarily nested describes" do
|
@@ -99,10 +104,8 @@ describe Micronaut::Behaviour do
|
|
99
104
|
Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
|
100
105
|
end
|
101
106
|
end
|
102
|
-
|
103
|
-
remove_last_describe_from_world
|
104
|
-
remove_last_describe_from_world
|
105
|
-
remove_last_describe_from_world
|
107
|
+
|
108
|
+
4.times { remove_last_describe_from_world }
|
106
109
|
end
|
107
110
|
|
108
111
|
end
|
@@ -269,13 +272,13 @@ describe Micronaut::Behaviour do
|
|
269
272
|
|
270
273
|
describe "how instance variables inherit" do
|
271
274
|
|
272
|
-
before do
|
273
|
-
@before_each_top_level = 'before_each_top_level'
|
274
|
-
end
|
275
|
-
|
276
275
|
before(:all) do
|
277
276
|
@before_all_top_level = 'before_all_top_level'
|
278
277
|
end
|
278
|
+
|
279
|
+
before(:each) do
|
280
|
+
@before_each_top_level = 'before_each_top_level'
|
281
|
+
end
|
279
282
|
|
280
283
|
it "should be able to access a before each ivar at the same level" do
|
281
284
|
@before_each_top_level.should == 'before_each_top_level'
|
@@ -284,6 +287,11 @@ describe Micronaut::Behaviour do
|
|
284
287
|
it "should be able to access a before all ivar at the same level" do
|
285
288
|
@before_all_top_level.should == 'before_all_top_level'
|
286
289
|
end
|
290
|
+
|
291
|
+
|
292
|
+
it "should be able to access the before all ivars in the before_all_ivars hash" do
|
293
|
+
running_example.behaviour.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
|
294
|
+
end
|
287
295
|
|
288
296
|
describe "but now I am nested" do
|
289
297
|
|
@@ -291,12 +299,24 @@ describe Micronaut::Behaviour do
|
|
291
299
|
@before_each_top_level.should == 'before_each_top_level'
|
292
300
|
end
|
293
301
|
|
294
|
-
it "should
|
295
|
-
@before_all_top_level.should
|
302
|
+
it "should be able to access a parent behaviours before all ivar at a nested level" do
|
303
|
+
@before_all_top_level.should == "before_all_top_level"
|
304
|
+
end
|
305
|
+
|
306
|
+
it "changes to before all ivars from within an example do not persist outside the current describe" do
|
307
|
+
@before_all_top_level = "ive been changed"
|
308
|
+
end
|
309
|
+
|
310
|
+
describe "accessing a before_all ivar that was changed in a parent behaviour" do
|
311
|
+
|
312
|
+
it "should have access to the modified version" do
|
313
|
+
@before_all_top_level.should == 'ive been changed'
|
314
|
+
end
|
315
|
+
|
296
316
|
end
|
297
317
|
|
298
318
|
end
|
299
319
|
|
300
320
|
end
|
301
321
|
|
302
|
-
end
|
322
|
+
end
|
data/lib/micronaut/behaviour.rb
CHANGED
@@ -156,31 +156,31 @@ module Micronaut
|
|
156
156
|
@_after_ancestors ||= ancestors(true)
|
157
157
|
end
|
158
158
|
|
159
|
+
def self.before_all_ivars
|
160
|
+
@before_all_ivars ||= {}
|
161
|
+
end
|
162
|
+
|
159
163
|
def self.eval_before_alls(running_behaviour)
|
164
|
+
superclass.before_all_ivars.each { |ivar, val| running_behaviour.instance_variable_set(ivar, val) }
|
160
165
|
Micronaut.configuration.find_before_or_after(:before, :all, self).each { |blk| running_behaviour.instance_eval(&blk) }
|
161
166
|
|
162
167
|
before_alls.each { |blk| running_behaviour.instance_eval(&blk) }
|
168
|
+
running_behaviour.instance_variables.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) }
|
163
169
|
end
|
164
170
|
|
165
171
|
def self.eval_before_eachs(running_behaviour)
|
166
172
|
Micronaut.configuration.find_before_or_after(:before, :each, self).each { |blk| running_behaviour.instance_eval(&blk) }
|
167
|
-
|
168
|
-
before_ancestors.each do |ancestor|
|
169
|
-
ancestor.before_eachs.each { |blk| running_behaviour.instance_eval(&blk) }
|
170
|
-
end
|
173
|
+
before_ancestors.each { |ancestor| ancestor.before_eachs.each { |blk| running_behaviour.instance_eval(&blk) } }
|
171
174
|
end
|
172
175
|
|
173
176
|
def self.eval_after_alls(running_behaviour)
|
174
177
|
after_alls.each { |blk| running_behaviour.instance_eval(&blk) }
|
175
|
-
|
176
178
|
Micronaut.configuration.find_before_or_after(:after, :all, self).each { |blk| running_behaviour.instance_eval(&blk) }
|
179
|
+
before_all_ivars.keys.each { |ivar| before_all_ivars[ivar] = running_behaviour.instance_variable_get(ivar) }
|
177
180
|
end
|
178
181
|
|
179
182
|
def self.eval_after_eachs(running_behaviour)
|
180
|
-
after_ancestors.each
|
181
|
-
ancestor.after_eachs.each { |blk| running_behaviour.instance_eval(&blk) }
|
182
|
-
end
|
183
|
-
|
183
|
+
after_ancestors.each { |ancestor| ancestor.after_eachs.each { |blk| running_behaviour.instance_eval(&blk) } }
|
184
184
|
Micronaut.configuration.find_before_or_after(:after, :each, self).each { |blk| running_behaviour.instance_eval(&blk) }
|
185
185
|
end
|
186
186
|
|
@@ -214,4 +214,4 @@ module Micronaut
|
|
214
214
|
end
|
215
215
|
|
216
216
|
end
|
217
|
-
end
|
217
|
+
end
|
@@ -149,8 +149,8 @@ module Micronaut
|
|
149
149
|
before_and_afters[:after][each_or_all] << [options, block]
|
150
150
|
end
|
151
151
|
|
152
|
-
def find_before_or_after(
|
153
|
-
before_and_afters[
|
152
|
+
def find_before_or_after(desired_before_or_after, desired_each_or_all, group)
|
153
|
+
before_and_afters[desired_before_or_after][desired_each_or_all].select do |options, block|
|
154
154
|
options.all? do |filter_on, filter|
|
155
155
|
Micronaut.world.apply_condition(filter_on, filter, group.metadata)
|
156
156
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spicycode-micronaut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Humphries
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-13 00:00:00 -08:00
|
13
13
|
default_executable: micronaut
|
14
14
|
dependencies: []
|
15
15
|
|