spicycode-micronaut 0.0.5 → 0.0.6

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.5"
7
+ GEM_VERSION = "0.0.6"
8
8
  AUTHOR = "Chad Humphries"
9
9
  EMAIL = "chad@spicycode.com"
10
10
  HOMEPAGE = "http://spicycode.com"
@@ -15,7 +15,7 @@ spec = Gem::Specification.new do |s|
15
15
  s.version = GEM_VERSION
16
16
  s.platform = Gem::Platform::RUBY
17
17
  s.has_rdoc = true
18
- s.extra_rdoc_files = ["README", "LICENSE"]
18
+ s.extra_rdoc_files = ["README", "LICENSE", "RSPEC-LICENSE"]
19
19
  s.summary = SUMMARY
20
20
  s.description = s.summary
21
21
  s.author = AUTHOR
@@ -56,6 +56,19 @@ namespace :micronaut do
56
56
  ruby command
57
57
  end
58
58
 
59
+ desc "List files that don't have examples"
60
+ task :untested do
61
+ code = Dir["lib/**/*.rb"].map { |g| Dir.glob(g) }.flatten
62
+ examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
63
+ examples.map! { |f| f =~ /examples\/(.*)_example/; "#{$1}.rb" }
64
+ missing_examples = (code - examples)
65
+ puts
66
+ puts "The following files seem to be missing their examples:"
67
+ missing_examples.each do |missing|
68
+ puts " #{missing}"
69
+ end
70
+ end
71
+
59
72
  desc "Run all examples using rcov"
60
73
  task :coverage do
61
74
  examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
@@ -26,4 +26,18 @@ def dummy_reporter
26
26
  DummyFormatter.new({}, StringIO.new)
27
27
  end
28
28
 
29
- Micronaut::Runner.autorun
29
+ Micronaut.configure do |config|
30
+
31
+ config.mock_with :mocha
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
+ end
42
+
43
+ Micronaut::Runner.autorun
@@ -11,176 +11,176 @@ describe Micronaut::BehaviourGroup do
11
11
  end
12
12
 
13
13
  describe "describing behaviour with #describe" do
14
-
15
- it "should raise an ArgumentError if no name is given" do
16
- lambda { Micronaut::BehaviourGroup.describe() {} }.should raise_error(ArgumentError)
17
- end
18
-
19
- it "should raise an ArgumentError if no block is given" do
20
- lambda { Micronaut::BehaviourGroup.describe('foo') }.should raise_error(ArgumentError)
21
- end
22
-
23
- describe '#name' do
24
-
25
- it "should expose the first parameter as name" do
26
- Micronaut::BehaviourGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
27
- end
28
-
29
- it "should call to_s on the first parameter in case it is a constant" do
30
- Micronaut::BehaviourGroup.describe(Foo) { }.name.should == 'Foo'
31
- end
32
-
33
- end
34
-
35
- describe '#described_type' do
36
-
37
- it "should be the first parameter when it is a constant" do
38
- Micronaut::BehaviourGroup.describe(Foo) { }.described_type.should == Foo
39
- end
40
-
41
- it "should be nil when the first parameter is a string" do
42
- Micronaut::BehaviourGroup.describe("i'm a computer") { }.described_type.should be_nil
43
- end
44
-
45
- end
46
-
47
- describe '#description' do
48
-
49
- it "should expose the second parameter as description" do
50
- Micronaut::BehaviourGroup.describe(Foo, "my desc") { }.description.should == 'my desc'
51
- end
52
-
53
- it "should allow the second parameter to be nil" do
54
- Micronaut::BehaviourGroup.describe(Foo, nil) { }.description.size.should == 0
55
- end
56
-
57
- end
58
-
59
- describe '#options' do
60
-
61
- it "should expose the third parameter as options" do
62
- Micronaut::BehaviourGroup.describe(Foo, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
63
- end
64
-
65
- it "should be an empty hash if no options are supplied" do
66
- Micronaut::BehaviourGroup.describe(Foo, nil) { }.options.should == {}
67
- end
68
-
69
- end
70
-
71
- describe "adding before and after hooks" do
72
-
73
- it "should expose the before each blocks at before_eachs" do
74
- group = empty_behaviour_group
75
- group.before(:each) { 'foo' }
76
- group.should have(1).before_eachs
77
- end
78
-
79
- it "should maintain the before each block order" do
80
- group = empty_behaviour_group
81
- group.before(:each) { 15 }
82
- group.before(:each) { 'A' }
83
- group.before(:each) { 33.5 }
84
-
85
- group.before_eachs[0].call.should == 15
86
- group.before_eachs[1].call.should == 'A'
87
- group.before_eachs[2].call.should == 33.5
88
- end
89
-
90
- it "should expose the before all blocks at before_alls" do
91
- group = empty_behaviour_group
92
- group.before(:all) { 'foo' }
93
- group.should have(1).before_alls
94
- end
95
-
96
- it "should maintain the before all block order" do
97
- group = empty_behaviour_group
98
- group.before(:all) { 15 }
99
- group.before(:all) { 'A' }
100
- group.before(:all) { 33.5 }
101
-
102
- group.before_alls[0].call.should == 15
103
- group.before_alls[1].call.should == 'A'
104
- group.before_alls[2].call.should == 33.5
105
- end
106
-
107
- it "should expose the after each blocks at after_eachs" do
108
- group = empty_behaviour_group
109
- group.after(:each) { 'foo' }
110
- group.should have(1).after_eachs
111
- end
112
-
113
- it "should maintain the after each block order" do
114
- group = empty_behaviour_group
115
- group.after(:each) { 15 }
116
- group.after(:each) { 'A' }
117
- group.after(:each) { 33.5 }
118
-
119
- group.after_eachs[0].call.should == 15
120
- group.after_eachs[1].call.should == 'A'
121
- group.after_eachs[2].call.should == 33.5
122
- end
123
-
124
- it "should expose the after all blocks at after_alls" do
125
- group = empty_behaviour_group
126
- group.after(:all) { 'foo' }
127
- group.should have(1).after_alls
128
- end
129
-
130
- it "should maintain the after each block order" do
131
- group = empty_behaviour_group
132
- group.after(:all) { 15 }
133
- group.after(:all) { 'A' }
134
- group.after(:all) { 33.5 }
135
-
136
- group.after_alls[0].call.should == 15
137
- group.after_alls[1].call.should == 'A'
138
- group.after_alls[2].call.should == 33.5
139
- end
140
-
141
- end
142
-
143
- describe "adding examples" do
144
-
145
- it "should allow adding an example using 'it'" do
146
- group = empty_behaviour_group
147
- group.it("should do something") { }
148
- group.examples.size.should == 1
149
- end
150
-
151
- it "should expose all examples at examples" do
152
- group = empty_behaviour_group
153
- group.it("should do something 1") { }
154
- group.it("should do something 2") { }
155
- group.it("should do something 3") { }
156
- group.examples.size.should == 3
157
- end
158
-
159
- it "should maintain the example order" do
160
- group = empty_behaviour_group
161
- group.it("should 1") { }
162
- group.it("should 2") { }
163
- group.it("should 3") { }
164
- group.examples[0].first.should == 'should 1'
165
- group.examples[1].first.should == 'should 2'
166
- group.examples[2].first.should == 'should 3'
167
- end
168
-
169
- end
170
-
171
- end
172
-
14
+
15
+ it "should raise an ArgumentError if no name is given" do
16
+ lambda { Micronaut::BehaviourGroup.describe() {} }.should raise_error(ArgumentError)
17
+ end
18
+
19
+ it "should raise an ArgumentError if no block is given" do
20
+ lambda { Micronaut::BehaviourGroup.describe('foo') }.should raise_error(ArgumentError)
21
+ end
22
+
23
+ describe '#name' do
24
+
25
+ it "should expose the first parameter as name" do
26
+ Micronaut::BehaviourGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
27
+ end
28
+
29
+ it "should call to_s on the first parameter in case it is a constant" do
30
+ Micronaut::BehaviourGroup.describe(Foo) { }.name.should == 'Foo'
31
+ end
32
+
33
+ end
34
+
35
+ describe '#described_type' do
36
+
37
+ it "should be the first parameter when it is a constant" do
38
+ Micronaut::BehaviourGroup.describe(Foo) { }.described_type.should == Foo
39
+ end
40
+
41
+ it "should be nil when the first parameter is a string" do
42
+ Micronaut::BehaviourGroup.describe("i'm a computer") { }.described_type.should be_nil
43
+ end
44
+
45
+ end
46
+
47
+ describe '#description' do
48
+
49
+ it "should expose the second parameter as description" do
50
+ Micronaut::BehaviourGroup.describe(Foo, "my desc") { }.description.should == 'my desc'
51
+ end
52
+
53
+ it "should allow the second parameter to be nil" do
54
+ Micronaut::BehaviourGroup.describe(Foo, nil) { }.description.size.should == 0
55
+ end
56
+
57
+ end
58
+
59
+ describe '#options' do
60
+
61
+ it "should expose the third parameter as options" do
62
+ Micronaut::BehaviourGroup.describe(Foo, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
63
+ end
64
+
65
+ it "should be an empty hash if no options are supplied" do
66
+ Micronaut::BehaviourGroup.describe(Foo, nil) { }.options.should == {}
67
+ end
68
+
69
+ end
70
+
71
+ describe "adding before and after hooks" do
72
+
73
+ it "should expose the before each blocks at before_eachs" do
74
+ group = empty_behaviour_group
75
+ group.before(:each) { 'foo' }
76
+ group.should have(1).before_eachs
77
+ end
78
+
79
+ it "should maintain the before each block order" do
80
+ group = empty_behaviour_group
81
+ group.before(:each) { 15 }
82
+ group.before(:each) { 'A' }
83
+ group.before(:each) { 33.5 }
84
+
85
+ group.before_eachs[0].last.call.should == 15
86
+ group.before_eachs[1].last.call.should == 'A'
87
+ group.before_eachs[2].last.call.should == 33.5
88
+ end
89
+
90
+ it "should expose the before all blocks at before_alls" do
91
+ group = empty_behaviour_group
92
+ group.before(:all) { 'foo' }
93
+ group.should have(1).before_alls
94
+ end
95
+
96
+ it "should maintain the before all block order" do
97
+ group = empty_behaviour_group
98
+ group.before(:all) { 15 }
99
+ group.before(:all) { 'A' }
100
+ group.before(:all) { 33.5 }
101
+
102
+ group.before_alls[0].last.call.should == 15
103
+ group.before_alls[1].last.call.should == 'A'
104
+ group.before_alls[2].last.call.should == 33.5
105
+ end
106
+
107
+ it "should expose the after each blocks at after_eachs" do
108
+ group = empty_behaviour_group
109
+ group.after(:each) { 'foo' }
110
+ group.should have(1).after_eachs
111
+ end
112
+
113
+ it "should maintain the after each block order" do
114
+ group = empty_behaviour_group
115
+ group.after(:each) { 15 }
116
+ group.after(:each) { 'A' }
117
+ group.after(:each) { 33.5 }
118
+
119
+ group.after_eachs[0].last.call.should == 15
120
+ group.after_eachs[1].last.call.should == 'A'
121
+ group.after_eachs[2].last.call.should == 33.5
122
+ end
123
+
124
+ it "should expose the after all blocks at after_alls" do
125
+ group = empty_behaviour_group
126
+ group.after(:all) { 'foo' }
127
+ group.should have(1).after_alls
128
+ end
129
+
130
+ it "should maintain the after each block order" do
131
+ group = empty_behaviour_group
132
+ group.after(:all) { 15 }
133
+ group.after(:all) { 'A' }
134
+ group.after(:all) { 33.5 }
135
+
136
+ group.after_alls[0].last.call.should == 15
137
+ group.after_alls[1].last.call.should == 'A'
138
+ group.after_alls[2].last.call.should == 33.5
139
+ end
140
+
141
+ end
142
+
143
+ describe "adding examples" do
144
+
145
+ it "should allow adding an example using 'it'" do
146
+ group = empty_behaviour_group
147
+ group.it("should do something") { }
148
+ group.examples.size.should == 1
149
+ end
150
+
151
+ it "should expose all examples at examples" do
152
+ group = empty_behaviour_group
153
+ group.it("should do something 1") { }
154
+ group.it("should do something 2") { }
155
+ group.it("should do something 3") { }
156
+ group.examples.size.should == 3
157
+ end
158
+
159
+ it "should maintain the example order" do
160
+ group = empty_behaviour_group
161
+ group.it("should 1") { }
162
+ group.it("should 2") { }
163
+ group.it("should 3") { }
164
+ group.examples[0].description.should == 'should 1'
165
+ group.examples[1].description.should == 'should 2'
166
+ group.examples[2].description.should == 'should 3'
167
+ end
168
+
169
+ end
170
+
171
+ end
172
+
173
173
  before { @wee = 1 }
174
-
175
- describe "nested describes" do
176
-
177
- before { @wee += 5 }
178
- # it "should set the described type to the parent described type (if it is not given)"
179
-
180
- it "should have all of the parent before blocks" do
181
- @wee.should == 6
182
- end
183
-
184
- end
185
-
174
+
175
+ describe "nested describes" do
176
+
177
+ before { @wee += 5 }
178
+ # it "should set the described type to the parent described type (if it is not given)"
179
+
180
+ it "should have all of the parent before blocks" do
181
+ @wee.should == 6
182
+ end
183
+
184
+ end
185
+
186
186
  end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
2
+
3
+ describe Micronaut::Configuration do
4
+
5
+ describe "#mock_with" do
6
+
7
+ it "should include the mocha adapter when called with :mocha" do
8
+ Micronaut::BehaviourGroup.expects(:send).with(:include, Micronaut::Mocking::WithMocha)
9
+ Micronaut::Configuration.new.mock_with :mocha
10
+ end
11
+
12
+ it "should include the do absolutely nothing mocking adapter for all other cases" do
13
+ Micronaut::BehaviourGroup.expects(:send).with(:include, Micronaut::Mocking::WithAbsolutelyNothing)
14
+ Micronaut::Configuration.new.mock_with
15
+ end
16
+
17
+ end
18
+
19
+ describe "#include" do
20
+
21
+ module InstanceLevelMethods
22
+ def you_call_this_a_blt?
23
+ "egad man, where's the mayo?!?!?"
24
+ end
25
+ end
26
+
27
+ it "should include the given module into each behaviour group" do
28
+ Micronaut.configuration.include(InstanceLevelMethods)
29
+ group = Micronaut::BehaviourGroup.describe(Object, 'does like, stuff and junk') { }
30
+ group.should_not respond_to(:you_call_this_a_blt?)
31
+ remove_last_describe_from_world
32
+
33
+ group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
34
+ end
35
+
36
+ end
37
+
38
+ describe "#extend" do
39
+
40
+ module FocusedSupport
41
+
42
+ def fit(desc, options={}, &block)
43
+ it(desc, options.merge(:focused => true), &block)
44
+ end
45
+
46
+ end
47
+
48
+ it "should extend the given module into each behaviour group" do
49
+ Micronaut.configuration.extend(FocusedSupport)
50
+ group = Micronaut::BehaviourGroup.describe(FocusedSupport, 'the focused support ') { }
51
+ group.should respond_to(:fit)
52
+ remove_last_describe_from_world
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
2
+
3
+ describe Micronaut::KernelExtensions do
4
+
5
+ it "should be included in Object" do
6
+ Object.included_modules.should include(Micronaut::KernelExtensions)
7
+ end
8
+
9
+ it "should add a describe method to Object" do
10
+ Object.methods.should include("describe")
11
+ end
12
+
13
+ end
@@ -1,6 +1,23 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../example_helper")
2
2
 
3
3
  describe Micronaut do
4
+
5
+ describe "configuration" do
6
+
7
+ it "should return an instance of Micronaut::Configuration" do
8
+ Micronaut.configuration.should be_an_instance_of(Micronaut::Configuration)
9
+ end
10
+
11
+ end
4
12
 
13
+ describe "configure" do
14
+
15
+ it "should yield the current configuration" do
16
+ Micronaut.configure do |config|
17
+ config.should == Micronaut.configuration
18
+ end
19
+ end
20
+
21
+ end
5
22
 
6
23
  end
@@ -1,12 +1,13 @@
1
- require 'micronaut/mocking/with_mocha'
1
+ require 'micronaut/mocking'
2
2
  require 'micronaut/matchers'
3
3
  require 'micronaut/expectations'
4
4
  require 'micronaut/world'
5
+ require 'micronaut/configuration'
5
6
  require 'micronaut/runner'
6
7
  require 'micronaut/runner_options'
7
- require 'micronaut/behaviour_group_class_methods'
8
+ require 'micronaut/example'
8
9
  require 'micronaut/behaviour_group'
9
- require 'micronaut/extensions/kernel'
10
+ require 'micronaut/kernel_extensions'
10
11
  require 'micronaut/formatters'
11
12
 
12
13
  module Micronaut
@@ -25,4 +26,12 @@ module Micronaut
25
26
  # './lib' in project dir, or '/usr/local/blahblah' if installed
26
27
  MICRONAUT_DIR = File.expand_path(File.dirname(File.dirname(file)))
27
28
 
29
+ def self.configuration
30
+ @configuration ||= Micronaut::Configuration.new
31
+ end
32
+
33
+ def self.configure
34
+ yield configuration
35
+ end
36
+
28
37
  end
@@ -1,65 +1,190 @@
1
1
  module Micronaut
2
+
2
3
  class BehaviourGroup
3
- extend Micronaut::BehaviourGroupClassMethods
4
- include Micronaut::Matchers
5
- include Micronaut::Mocking::WithMocha
4
+ include Micronaut::Matchers
6
5
 
7
- def eval_before_alls
8
- self.class.each_ancestor do |ancestor|
9
- ancestor.before_alls.each { |blk| instance_eval(&blk) }
6
+ def self.inherited(klass)
7
+ super
8
+ Micronaut::World.behaviour_groups << klass
9
+ end
10
+
11
+ def self.befores
12
+ @_befores ||= { :all => [], :each => [] }
13
+ end
14
+
15
+ def self.before_eachs
16
+ befores[:each]
17
+ end
18
+
19
+ def self.before_alls
20
+ befores[:all]
21
+ end
22
+
23
+ def self.before(type=:each, options={}, &block)
24
+ befores[type] << [options, block]
25
+ end
26
+
27
+ def self.afters
28
+ @_afters ||= { :all => [], :each => [] }
29
+ end
30
+
31
+ def self.after_eachs
32
+ afters[:each]
33
+ end
34
+
35
+ def self.after_alls
36
+ afters[:all]
37
+ end
38
+
39
+ def self.after(type=:each, options={}, &block)
40
+ afters[type] << [options, block]
41
+ end
42
+
43
+ def self.it(desc=nil, options={}, &block)
44
+ examples << Micronaut::Example.new(self, desc, options, block)
45
+ end
46
+
47
+ def self.examples
48
+ @_examples ||= []
49
+ end
50
+
51
+ def self.set_it_up(*args)
52
+ metadata[:options] = args.last.is_a?(Hash) ? args.pop : {}
53
+ metadata[:described_type] = args.first.is_a?(String) ? self.superclass.described_type : args.shift
54
+ metadata[:description] = args.shift || ''
55
+ metadata[:name] = "#{metadata[:described_type]} #{metadata[:description]}".strip
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?
63
+ end
64
+ end
65
+
66
+ def self.metadata
67
+ @_metadata ||= {}
68
+ end
69
+
70
+ def self.name
71
+ metadata[:name]
72
+ end
73
+
74
+ def self.described_type
75
+ metadata[:described_type]
76
+ end
77
+
78
+ def self.description
79
+ metadata[:description]
80
+ end
81
+
82
+ def self.options
83
+ metadata[:options]
84
+ end
85
+
86
+ def self.describe(*args, &describe_block)
87
+ raise ArgumentError if args.empty? || describe_block.nil?
88
+ subclass('NestedLevel') do
89
+ set_it_up(*args)
90
+ module_eval(&describe_block)
10
91
  end
11
92
  end
12
93
 
13
- def eval_after_alls
14
- self.class.each_ancestor(:superclass_first) do |ancestor|
15
- ancestor.after_alls.each { |blk| instance_eval(&blk) }
94
+ def self.ancestors(superclass_last=false)
95
+ classes = []
96
+ current_class = self
97
+
98
+ while current_class < Micronaut::BehaviourGroup
99
+ superclass_last ? classes << current_class : classes.unshift(current_class)
100
+ current_class = current_class.superclass
101
+ end
102
+
103
+ classes
104
+ end
105
+
106
+ def self.before_ancestors
107
+ @_before_ancestors ||= ancestors
108
+ end
109
+
110
+ def self.after_ancestors
111
+ @_after_ancestors ||= ancestors(true)
112
+ end
113
+
114
+ def self.eval_before_alls(example)
115
+ before_ancestors.each do |ancestor|
116
+ ancestor.before_alls.each { |opts, blk| example.instance_eval(&blk) }
117
+ end
118
+ end
119
+
120
+ def self.eval_before_eachs(example)
121
+ before_ancestors.each do |ancestor|
122
+ ancestor.before_eachs.each { |opts, blk| example.instance_eval(&blk) }
16
123
  end
17
124
  end
18
125
 
19
- def eval_before_eachs
20
- self.class.each_ancestor do |ancestor|
21
- ancestor.before_eachs.each { |blk| instance_eval(&blk) }
126
+ def self.eval_after_alls(example)
127
+ after_ancestors.each do |ancestor|
128
+ ancestor.after_alls.each { |opts, blk| example.instance_eval(&blk) }
22
129
  end
23
130
  end
24
131
 
25
- def eval_after_eachs
26
- self.class.each_ancestor(:superclass_first) do |ancestor|
27
- ancestor.after_eachs.each { |blk| instance_eval(&blk) }
132
+ def self.eval_after_eachs(example)
133
+ after_ancestors.each do |ancestor|
134
+ ancestor.after_eachs.each { |opts, blk| example.instance_eval(&blk) }
28
135
  end
29
136
  end
30
137
 
31
- def execute(reporter)
32
- return true if self.class.examples.empty?
33
- eval_before_alls
138
+ def self.run(reporter)
139
+ return true if examples.empty?
140
+
141
+ group = new
142
+
143
+ eval_before_alls(group)
34
144
  success = true
35
145
 
36
- self.class.examples.each do |desc, opts, block|
37
- reporter.example_started(self)
146
+ examples.each do |ex|
147
+ reporter.example_started(ex)
38
148
 
39
149
  execution_error = nil
40
150
  begin
41
- setup_mocks
42
- eval_before_eachs
43
- if block
44
- instance_eval(&block)
45
- verify_mocks
46
- reporter.example_passed(self)
151
+ group._setup_mocks
152
+ eval_before_eachs(group)
153
+
154
+ if ex.example_block
155
+ group.instance_eval(&ex.example_block)
156
+ group._verify_mocks
157
+ reporter.example_passed(ex)
47
158
  else
48
- reporter.example_pending([desc, self], 'Not yet implemented')
159
+ reporter.example_pending(ex, 'Not yet implemented')
49
160
  end
50
- eval_after_eachs
161
+ eval_after_eachs(group)
51
162
  rescue Exception => e
52
- reporter.example_failed(self, e)
163
+ reporter.example_failed(ex, e)
53
164
  execution_error ||= e
54
165
  ensure
55
- teardown_mocks
166
+ group._teardown_mocks
56
167
  end
57
168
 
58
169
  success &= execution_error.nil?
59
170
  end
60
- eval_after_alls
171
+ eval_after_alls(group)
61
172
  success
62
173
  end
63
174
 
175
+ def self.subclass(base_name, &body) # :nodoc:
176
+ @_sub_class_count ||= 0
177
+ @_sub_class_count += 1
178
+ klass = Class.new(self)
179
+ class_name = "#{base_name}_#{@_sub_class_count}"
180
+ const_set(class_name, klass)
181
+ klass.instance_eval(&body)
182
+ klass
183
+ end
184
+
185
+ def self.to_s
186
+ self == Micronaut::BehaviourGroup ? 'Micronaut::BehaviourGroup' : name
187
+ end
188
+
64
189
  end
65
- end
190
+ end
@@ -0,0 +1,47 @@
1
+ module Micronaut
2
+
3
+ class Configuration
4
+ attr_reader :mock_framework
5
+
6
+ def mock_with(make_a_mockery_with=nil)
7
+ @mock_framework = case make_a_mockery_with
8
+ when :mocha
9
+ Micronaut::Mocking::WithMocha
10
+ else
11
+ Micronaut::Mocking::WithAbsolutelyNothing
12
+ end
13
+
14
+ Micronaut::BehaviourGroup.send(:include, @mock_framework)
15
+ end
16
+
17
+ def befores
18
+ @befores ||= { :each => [], :all => {} }
19
+ end
20
+
21
+ def afters
22
+ @afters ||= { :each => [], :all => {} }
23
+ end
24
+
25
+ def extra_modules
26
+ @extra_modules ||= { :include => [], :extend => [] }
27
+ end
28
+
29
+ def include(module_to_include, options={})
30
+ extra_modules[:include] << [module_to_include, options]
31
+ end
32
+
33
+ def extend(module_to_extend, options={})
34
+ extra_modules[:extend] << [module_to_extend, options]
35
+ end
36
+
37
+ def before(type=:each, options={}, &block)
38
+ befores[type] << [options, block]
39
+ end
40
+
41
+ def after(type=:each, options={}, &block)
42
+ afters[type] << [options, block]
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,17 @@
1
+ module Micronaut
2
+
3
+ class Example
4
+
5
+ attr_reader :behaviour, :description, :options, :example_block
6
+
7
+ def initialize(behaviour, desc, options, example_block=nil)
8
+ @behaviour, @description, @options, @example_block = behaviour, desc, options, example_block
9
+ end
10
+
11
+ def inspect
12
+ "#{behaviour.name} - #{desc}"
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -64,7 +64,7 @@ module Micronaut
64
64
  @output.puts
65
65
  @output.puts "Pending:"
66
66
  @pending_examples.each do |pending_example, message|
67
- @output.puts "\n #{pending_example.last.class.name} #{pending_example.first}"
67
+ @output.puts "\n #{pending_example.behaviour}\n - #{pending_example.description}"
68
68
  end
69
69
  end
70
70
  @output.flush
@@ -0,0 +1,11 @@
1
+ module Micronaut
2
+ module KernelExtensions
3
+
4
+ def describe(*args, &describe_block)
5
+ Micronaut::BehaviourGroup.describe(*args, &describe_block)
6
+ end
7
+
8
+ end
9
+ end
10
+
11
+ include Micronaut::KernelExtensions
@@ -1,12 +1,10 @@
1
1
  require 'micronaut/matchers/generated_descriptions'
2
- require 'micronaut/matchers/errors'
3
2
  require 'micronaut/matchers/simple_matcher'
4
3
  require 'micronaut/matchers/be'
5
4
  require 'micronaut/matchers/be_close'
6
5
  require 'micronaut/matchers/change'
7
6
  require 'micronaut/matchers/eql'
8
7
  require 'micronaut/matchers/equal'
9
- require 'micronaut/matchers/exist'
10
8
  require 'micronaut/matchers/has'
11
9
  require 'micronaut/matchers/have'
12
10
  require 'micronaut/matchers/include'
@@ -136,6 +134,8 @@ module Micronaut
136
134
  #
137
135
  module Matchers
138
136
 
137
+ class MatcherError < StandardError; end
138
+
139
139
  private
140
140
  def method_missing(sym, *args, &block) # :nodoc:
141
141
  return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
@@ -1,5 +1,6 @@
1
1
  module Micronaut
2
2
  module Matchers
3
+
3
4
  def has(sym, *args) # :nodoc:
4
5
  simple_matcher do |actual, matcher|
5
6
  matcher.failure_message = "expected ##{predicate(sym)}(#{args[0].inspect}) to return true, got false"
@@ -8,11 +9,11 @@ module Micronaut
8
9
  actual.__send__(predicate(sym), *args)
9
10
  end
10
11
  end
11
-
12
- private
12
+
13
+ private
13
14
  def predicate(sym)
14
15
  "#{sym.to_s.sub("have_","has_")}?".to_sym
15
16
  end
16
17
 
17
18
  end
18
- end
19
+ end
@@ -1,6 +1,8 @@
1
1
  module Micronaut
2
2
  module Matchers
3
+
3
4
  class Have #:nodoc:
5
+
4
6
  def initialize(expected, relativity=:exactly)
5
7
  @expected = (expected == :no ? 0 : expected)
6
8
  @relativity = relativity
@@ -146,5 +148,6 @@ EOF
146
148
  def have_at_most(n)
147
149
  Matchers::Have.new(n, :at_most)
148
150
  end
151
+
149
152
  end
150
- end
153
+ end
@@ -0,0 +1,6 @@
1
+ module Micronaut
2
+ module Mocking
3
+ autoload :WithMocha, 'micronaut/mocking/with_mocha'
4
+ autoload :WithAbsolutelyNothing, 'micronaut/mocking/with_absolutely_nothing'
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module Micronaut
2
+ module Mocking
3
+ module WithAbsolutelyNothing
4
+
5
+ def _setup_mocks; end
6
+ def _verify_mocks; end
7
+ def _teardown_mocks; end
8
+
9
+ end
10
+ end
11
+ end
@@ -5,18 +5,9 @@ module Micronaut
5
5
  module Mocking
6
6
  module WithMocha
7
7
  include Mocha::Standalone
8
- def setup_mocks
9
- mocha_setup
10
- end
11
-
12
- def verify_mocks
13
- mocha_verify
14
- end
15
-
16
- def teardown_mocks
17
- mocha_teardown
18
- end
19
-
8
+ alias :_setup_mocks :mocha_setup
9
+ alias :_verify_mocks :mocha_verify
10
+ alias :_teardown_mocks :mocha_teardown
20
11
  end
21
12
  end
22
13
  end
@@ -22,14 +22,6 @@ module Micronaut
22
22
  def run(args = [])
23
23
  @verbose = args.delete('-v')
24
24
 
25
- filter = if args.first =~ /^(-n|--name)$/ then
26
- args.shift
27
- arg = args.shift
28
- arg =~ /\/(.*)\// ? Regexp.new($1) : arg
29
- else
30
- /./ # anything - ^example_ already filtered by #examples
31
- end
32
-
33
25
  total_examples = Micronaut::World.behaviour_groups.inject(0) { |sum, eg| sum + eg.examples.size }
34
26
 
35
27
  old_sync, options.formatter.output.sync = options.formatter.output.sync, true if options.formatter.output.respond_to?(:sync=)
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries
@@ -9,7 +9,7 @@ autorequire: micronaut
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-02 00:00:00 -08:00
12
+ date: 2008-12-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,6 +30,7 @@ extensions: []
30
30
  extra_rdoc_files:
31
31
  - README
32
32
  - LICENSE
33
+ - RSPEC-LICENSE
33
34
  files:
34
35
  - LICENSE
35
36
  - README
@@ -40,7 +41,8 @@ files:
40
41
  - lib/autotest/micronaut.rb
41
42
  - lib/micronaut
42
43
  - lib/micronaut/behaviour_group.rb
43
- - lib/micronaut/behaviour_group_class_methods.rb
44
+ - lib/micronaut/configuration.rb
45
+ - lib/micronaut/example.rb
44
46
  - lib/micronaut/expectations
45
47
  - lib/micronaut/expectations/errors.rb
46
48
  - lib/micronaut/expectations/extensions
@@ -50,20 +52,18 @@ files:
50
52
  - lib/micronaut/expectations/handler.rb
51
53
  - lib/micronaut/expectations/wrap_expectation.rb
52
54
  - lib/micronaut/expectations.rb
53
- - lib/micronaut/extensions
54
- - lib/micronaut/extensions/kernel.rb
55
55
  - lib/micronaut/formatters
56
56
  - lib/micronaut/formatters/base_formatter.rb
57
57
  - lib/micronaut/formatters/base_text_formatter.rb
58
58
  - lib/micronaut/formatters/progress_formatter.rb
59
59
  - lib/micronaut/formatters.rb
60
+ - lib/micronaut/kernel_extensions.rb
60
61
  - lib/micronaut/matchers
61
62
  - lib/micronaut/matchers/be.rb
62
63
  - lib/micronaut/matchers/be_close.rb
63
64
  - lib/micronaut/matchers/change.rb
64
65
  - lib/micronaut/matchers/eql.rb
65
66
  - lib/micronaut/matchers/equal.rb
66
- - lib/micronaut/matchers/errors.rb
67
67
  - lib/micronaut/matchers/generated_descriptions.rb
68
68
  - lib/micronaut/matchers/has.rb
69
69
  - lib/micronaut/matchers/have.rb
@@ -78,7 +78,9 @@ files:
78
78
  - lib/micronaut/matchers/throw_symbol.rb
79
79
  - lib/micronaut/matchers.rb
80
80
  - lib/micronaut/mocking
81
+ - lib/micronaut/mocking/with_absolutely_nothing.rb
81
82
  - lib/micronaut/mocking/with_mocha.rb
83
+ - lib/micronaut/mocking.rb
82
84
  - lib/micronaut/runner.rb
83
85
  - lib/micronaut/runner_options.rb
84
86
  - lib/micronaut/world.rb
@@ -87,6 +89,7 @@ files:
87
89
  - examples/lib
88
90
  - examples/lib/micronaut
89
91
  - examples/lib/micronaut/behaviour_group_example.rb
92
+ - examples/lib/micronaut/configuration_example.rb
90
93
  - examples/lib/micronaut/expectations
91
94
  - examples/lib/micronaut/expectations/extensions
92
95
  - examples/lib/micronaut/expectations/extensions/object_example.rb
@@ -95,6 +98,7 @@ files:
95
98
  - examples/lib/micronaut/formatters
96
99
  - examples/lib/micronaut/formatters/base_formatter_example.rb
97
100
  - examples/lib/micronaut/formatters/progress_formatter_example.rb
101
+ - examples/lib/micronaut/kernel_extensions_example.rb
98
102
  - examples/lib/micronaut/matchers
99
103
  - examples/lib/micronaut/matchers/be_close_example.rb
100
104
  - examples/lib/micronaut/matchers/be_example.rb
@@ -1,119 +0,0 @@
1
- module Micronaut
2
- module BehaviourGroupClassMethods
3
-
4
- def inherited(klass)
5
- super
6
- Micronaut::World.behaviour_groups << klass
7
- end
8
-
9
- def befores
10
- @_befores ||= { :all => [], :each => [] }
11
- end
12
-
13
- def before_eachs
14
- befores[:each]
15
- end
16
-
17
- def before_alls
18
- befores[:all]
19
- end
20
-
21
- def before(type=:each, &block)
22
- befores[type] << block
23
- end
24
-
25
- def afters
26
- @_afters ||= { :all => [], :each => [] }
27
- end
28
-
29
- def after_eachs
30
- afters[:each]
31
- end
32
-
33
- def after_alls
34
- afters[:all]
35
- end
36
-
37
- def after(type=:each, &block)
38
- afters[type] << block
39
- end
40
-
41
- def it(desc=nil, options={}, &block)
42
- examples << [desc, options, block]
43
- end
44
-
45
- def examples
46
- @_examples ||= []
47
- end
48
-
49
- def set_it_up(*args)
50
- metadata[:options] = args.last.is_a?(Hash) ? args.pop : {}
51
- metadata[:described_type] = args.first.is_a?(String) ? self.superclass.described_type : args.shift
52
- metadata[:description] = args.shift || ''
53
- metadata[:name] = "#{metadata[:described_type]} #{metadata[:description]}".strip
54
- end
55
-
56
- def metadata
57
- @_metadata ||= {}
58
- end
59
-
60
- def name
61
- metadata[:name]
62
- end
63
-
64
- def described_type
65
- metadata[:described_type]
66
- end
67
-
68
- def description
69
- metadata[:description]
70
- end
71
-
72
- def options
73
- metadata[:options]
74
- end
75
-
76
- def describe(*args, &describe_block)
77
- raise ArgumentError if args.empty? || describe_block.nil?
78
-
79
- args << {} unless Hash === args.last
80
- # args.last[:spec_path] ||= File.expand_path(caller(0)[2])
81
-
82
- subclass('NestedLevel') do
83
- set_it_up(*args)
84
- module_eval(&describe_block)
85
- end
86
- end
87
-
88
- def each_ancestor(superclass_last=false)
89
- classes = []
90
- current_class = self
91
-
92
- while current_class < Micronaut::BehaviourGroup
93
- superclass_last ? classes << current_class : classes.unshift(current_class)
94
- current_class = current_class.superclass
95
- end
96
-
97
- classes.each { |example_group| yield example_group }
98
- end
99
-
100
- def run(runner)
101
- new.execute(runner)
102
- end
103
-
104
- def subclass(base_name, &body) # :nodoc:
105
- @_sub_class_count ||= 0
106
- @_sub_class_count += 1
107
- klass = Class.new(self)
108
- class_name = "#{base_name}_#{@_sub_class_count}"
109
- const_set(class_name, klass)
110
- klass.instance_eval(&body)
111
- klass
112
- end
113
-
114
- def to_s
115
- name
116
- end
117
-
118
- end
119
- end
@@ -1,13 +0,0 @@
1
- module Micronaut
2
- module Extensions
3
- module Kernel
4
-
5
- def describe(*args, &describe_block)
6
- Micronaut::BehaviourGroup.describe(*args, &describe_block)
7
- end
8
-
9
- end
10
- end
11
- end
12
-
13
- include Micronaut::Extensions::Kernel
@@ -1,5 +0,0 @@
1
- module Micronaut
2
- module Matchers
3
- class MatcherError < StandardError; end
4
- end
5
- end