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 CHANGED
@@ -4,7 +4,7 @@ require 'rubygems/specification'
4
4
  require 'date'
5
5
 
6
6
  GEM = "micronaut"
7
- GEM_VERSION = "0.0.6"
7
+ GEM_VERSION = "0.0.7"
8
8
  AUTHOR = "Chad Humphries"
9
9
  EMAIL = "chad@spicycode.com"
10
10
  HOMEPAGE = "http://spicycode.com"
@@ -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.extra_modules[:extend].each do |mod, options|
58
- send(:extend, mod) if options.empty?
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 befores
18
- @befores ||= { :each => [], :all => {} }
17
+ def extra_modules
18
+ @extra_modules ||= []
19
19
  end
20
-
21
- def afters
22
- @afters ||= { :each => [], :all => {} }
20
+
21
+ def include(module_to_include, options={})
22
+ extra_modules << [:include, module_to_include, options]
23
23
  end
24
24
 
25
- def extra_modules
26
- @extra_modules ||= { :include => [], :extend => [] }
25
+ def extend(module_to_extend, options={})
26
+ extra_modules << [:extend, module_to_extend, options]
27
27
  end
28
28
 
29
- def include(module_to_include, options={})
30
- extra_modules[:include] << [module_to_include, options]
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 extend(module_to_extend, options={})
34
- extra_modules[:extend] << [module_to_extend, options]
46
+ def before_and_afters
47
+ @before_and_afters ||= []
35
48
  end
36
49
 
37
50
  def before(type=:each, options={}, &block)
38
- befores[type] << [options, block]
51
+ before_and_afters << [:before, :each, options, block]
39
52
  end
40
53
 
41
54
  def after(type=:each, options={}, &block)
42
- afters[type] << [options, block]
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
- class << self
35
- attr_accessor :differ
36
-
37
- def fail_with(message, expected=nil, target=nil) # :nodoc:
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
- end
43
+
44
+ end
@@ -30,7 +30,7 @@ module Micronaut
30
30
  end
31
31
  end
32
32
  end
33
-
33
+
34
34
  end
35
35
 
36
36
  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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries