spicycode-micronaut 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/examples/example_helper.rb +0 -8
- data/lib/micronaut/behaviour_group.rb +11 -7
- data/lib/micronaut/configuration.rb +44 -13
- data/lib/micronaut/expectations.rb +9 -10
- data/lib/micronaut/world.rb +1 -1
- metadata +1 -1
data/Rakefile
CHANGED
data/examples/example_helper.rb
CHANGED
@@ -30,14 +30,6 @@ Micronaut.configure do |config|
|
|
30
30
|
|
31
31
|
config.mock_with :mocha
|
32
32
|
|
33
|
-
config.before(:each, :pending => true) do
|
34
|
-
raise "the roof"
|
35
|
-
end
|
36
|
-
|
37
|
-
config.after(:each, :focused => true) do
|
38
|
-
puts 'was the focus worth it?'
|
39
|
-
end
|
40
|
-
|
41
33
|
end
|
42
34
|
|
43
35
|
Micronaut::Runner.autorun
|
@@ -54,12 +54,8 @@ module Micronaut
|
|
54
54
|
metadata[:description] = args.shift || ''
|
55
55
|
metadata[:name] = "#{metadata[:described_type]} #{metadata[:description]}".strip
|
56
56
|
|
57
|
-
Micronaut.configuration.
|
58
|
-
send(
|
59
|
-
end
|
60
|
-
|
61
|
-
Micronaut.configuration.extra_modules[:include].each do |mod, options|
|
62
|
-
send(:include, mod) if options.empty?
|
57
|
+
Micronaut.configuration.find_modules(self).each do |include_or_extend, mod, opts|
|
58
|
+
send(include_or_extend, mod)
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
@@ -112,24 +108,32 @@ module Micronaut
|
|
112
108
|
end
|
113
109
|
|
114
110
|
def self.eval_before_alls(example)
|
111
|
+
Micronaut.configuration.find_before_or_after(:before, :all, self).each { |blk| example.instance_eval(&blk) }
|
112
|
+
|
115
113
|
before_ancestors.each do |ancestor|
|
116
114
|
ancestor.before_alls.each { |opts, blk| example.instance_eval(&blk) }
|
117
115
|
end
|
118
116
|
end
|
119
117
|
|
120
118
|
def self.eval_before_eachs(example)
|
119
|
+
Micronaut.configuration.find_before_or_after(:before, :each, self).each { |blk| example.instance_eval(&blk) }
|
120
|
+
|
121
121
|
before_ancestors.each do |ancestor|
|
122
122
|
ancestor.before_eachs.each { |opts, blk| example.instance_eval(&blk) }
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
def self.eval_after_alls(example)
|
127
|
+
Micronaut.configuration.find_before_or_after(:after, :all, self).each { |blk| example.instance_eval(&blk) }
|
128
|
+
|
127
129
|
after_ancestors.each do |ancestor|
|
128
130
|
ancestor.after_alls.each { |opts, blk| example.instance_eval(&blk) }
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
132
134
|
def self.eval_after_eachs(example)
|
135
|
+
Micronaut.configuration.find_before_or_after(:after, :each, self).each { |blk| example.instance_eval(&blk) }
|
136
|
+
|
133
137
|
after_ancestors.each do |ancestor|
|
134
138
|
ancestor.after_eachs.each { |opts, blk| example.instance_eval(&blk) }
|
135
139
|
end
|
@@ -138,8 +142,8 @@ module Micronaut
|
|
138
142
|
def self.run(reporter)
|
139
143
|
return true if examples.empty?
|
140
144
|
|
145
|
+
|
141
146
|
group = new
|
142
|
-
|
143
147
|
eval_before_alls(group)
|
144
148
|
success = true
|
145
149
|
|
@@ -14,32 +14,63 @@ module Micronaut
|
|
14
14
|
Micronaut::BehaviourGroup.send(:include, @mock_framework)
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
@
|
17
|
+
def extra_modules
|
18
|
+
@extra_modules ||= []
|
19
19
|
end
|
20
|
-
|
21
|
-
def
|
22
|
-
|
20
|
+
|
21
|
+
def include(module_to_include, options={})
|
22
|
+
extra_modules << [:include, module_to_include, options]
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
25
|
+
def extend(module_to_extend, options={})
|
26
|
+
extra_modules << [:extend, module_to_extend, options]
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
extra_modules
|
29
|
+
def find_modules(group)
|
30
|
+
extra_modules.select do |include_or_extend, mod, options|
|
31
|
+
options.all? do |key, value|
|
32
|
+
case value
|
33
|
+
when Hash
|
34
|
+
value.all? { |k, v| group.metadata[key][k] == v }
|
35
|
+
when Regexp
|
36
|
+
group.metadata[key] =~ value
|
37
|
+
when Proc
|
38
|
+
value.call(group.metadata[key]) rescue false
|
39
|
+
else
|
40
|
+
group.metadata[key] == value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
31
44
|
end
|
32
45
|
|
33
|
-
def
|
34
|
-
|
46
|
+
def before_and_afters
|
47
|
+
@before_and_afters ||= []
|
35
48
|
end
|
36
49
|
|
37
50
|
def before(type=:each, options={}, &block)
|
38
|
-
|
51
|
+
before_and_afters << [:before, :each, options, block]
|
39
52
|
end
|
40
53
|
|
41
54
|
def after(type=:each, options={}, &block)
|
42
|
-
|
55
|
+
before_and_afters << [:after, :each, options, block]
|
56
|
+
end
|
57
|
+
|
58
|
+
def find_before_or_after(desired_type, desired_each_or_all, group)
|
59
|
+
before_and_afters.select do |type, each_or_all, options, block|
|
60
|
+
type == desired_type && each_or_all == desired_each_or_all &&
|
61
|
+
options.all? do |key, value|
|
62
|
+
case value
|
63
|
+
when Hash
|
64
|
+
value.all? { |k, v| group.metadata[key][k] == v }
|
65
|
+
when Regexp
|
66
|
+
group.metadata[key] =~ value
|
67
|
+
when Proc
|
68
|
+
value.call(group.metadata[key]) rescue false
|
69
|
+
else
|
70
|
+
group.metadata[key] == value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end.map { |type, each_or_all, options, block| block }
|
43
74
|
end
|
44
75
|
|
45
76
|
end
|
@@ -5,7 +5,7 @@ require 'micronaut/expectations/handler'
|
|
5
5
|
require 'micronaut/expectations/wrap_expectation'
|
6
6
|
|
7
7
|
module Micronaut
|
8
|
-
|
8
|
+
|
9
9
|
# Micronaut::Expectations lets you set expectations on your objects.
|
10
10
|
#
|
11
11
|
# result.should == 37
|
@@ -31,15 +31,14 @@ module Micronaut
|
|
31
31
|
# Micronaut ships with a standard set of useful matchers, and writing your own
|
32
32
|
# matchers is quite simple. See Micronaut::Matchers for details.
|
33
33
|
module Expectations
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if Array === message && message.length == 3
|
39
|
-
message, expected, target = message[0], message[1], message[2]
|
40
|
-
end
|
41
|
-
Kernel::raise(Micronaut::Expectations::ExpectationNotMetError.new(message))
|
34
|
+
|
35
|
+
def self.fail_with(message, expected=nil, target=nil) # :nodoc:
|
36
|
+
if Array === message && message.length == 3
|
37
|
+
message, expected, target = message[0], message[1], message[2]
|
42
38
|
end
|
39
|
+
Kernel::raise(Micronaut::Expectations::ExpectationNotMetError.new(message))
|
43
40
|
end
|
41
|
+
|
44
42
|
end
|
45
|
-
|
43
|
+
|
44
|
+
end
|
data/lib/micronaut/world.rb
CHANGED