spicycode-micronaut 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/RSPEC-LICENSE +23 -0
  2. data/Rakefile +2 -2
  3. data/examples/example_helper.rb +10 -0
  4. data/examples/lib/micronaut/behaviour_group_example.rb +170 -159
  5. data/examples/lib/micronaut/expectations/fail_with_example.rb +10 -64
  6. data/examples/lib/micronaut/formatters/progress_formatter_example.rb +3 -7
  7. data/examples/lib/micronaut/matchers/description_generation_example.rb +1 -1
  8. data/examples/lib/micronaut/matchers/have_example.rb +2 -2
  9. data/examples/lib/micronaut/matchers/operator_matcher_example.rb +0 -2
  10. data/examples/lib/micronaut/matchers/raise_error_example.rb +32 -1
  11. data/examples/lib/micronaut/{example_runner_example.rb → runner_example.rb} +0 -0
  12. data/examples/lib/micronaut/runner_options_example.rb +5 -0
  13. data/examples/lib/micronaut/world_example.rb +94 -0
  14. data/lib/micronaut.rb +1 -15
  15. data/lib/micronaut/behaviour_group.rb +34 -16
  16. data/lib/micronaut/behaviour_group_class_methods.rb +32 -47
  17. data/lib/micronaut/expectations.rb +0 -12
  18. data/lib/micronaut/extensions/kernel.rb +2 -2
  19. data/lib/micronaut/formatters/base_formatter.rb +4 -3
  20. data/lib/micronaut/formatters/base_text_formatter.rb +29 -17
  21. data/lib/micronaut/formatters/progress_formatter.rb +1 -1
  22. data/lib/micronaut/runner.rb +2 -2
  23. data/lib/micronaut/world.rb +36 -0
  24. metadata +7 -10
  25. data/examples/lib/micronaut/expectations/differs/default_example.rb +0 -125
  26. data/examples/lib/micronaut/matchers/exist_example.rb +0 -69
  27. data/lib/micronaut/example_world.rb +0 -17
  28. data/lib/micronaut/expectations/differs/default.rb +0 -58
  29. data/lib/micronaut/matchers/exist.rb +0 -16
data/RSPEC-LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2005-2008 The RSpec Development Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
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.4"
7
+ GEM_VERSION = "0.0.5"
8
8
  AUTHOR = "Chad Humphries"
9
9
  EMAIL = "chad@spicycode.com"
10
10
  HOMEPAGE = "http://spicycode.com"
@@ -27,7 +27,7 @@ spec = Gem::Specification.new do |s|
27
27
 
28
28
  s.require_path = 'lib'
29
29
  s.autorequire = GEM
30
- s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,examples}/**/*")
30
+ s.files = %w(LICENSE README RSPEC-LICENSE Rakefile) + Dir.glob("{lib,examples}/**/*")
31
31
  end
32
32
 
33
33
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -16,4 +16,14 @@ module Micronaut
16
16
  end
17
17
  end
18
18
 
19
+ def remove_last_describe_from_world
20
+ Micronaut::World.behaviour_groups.pop
21
+ end
22
+
23
+ class DummyFormatter < Micronaut::Formatters::BaseTextFormatter; end
24
+
25
+ def dummy_reporter
26
+ DummyFormatter.new({}, StringIO.new)
27
+ end
28
+
19
29
  Micronaut::Runner.autorun
@@ -11,165 +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 Object when the first parameter is a string" do
42
- Micronaut::BehaviourGroup.describe("i'm a computer") { }.described_type.should == Object
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.should be_nil
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
-
172
- end
173
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
+
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
174
185
 
175
186
  end
@@ -1,71 +1,17 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
2
 
3
- describe Micronaut::Expectations, "#fail_with with no diff" do
4
- before do
5
- @old_differ = Micronaut::Expectations.differ
6
- Micronaut::Expectations.differ = nil
7
- end
3
+ describe Micronaut::Expectations do
4
+
5
+ describe "#fail_with" do
8
6
 
9
- it "should handle just a message" do
10
- lambda {
11
- Micronaut::Expectations.fail_with "the message"
12
- }.should fail_with("the message")
13
- end
7
+ it "should handle just a message" do
8
+ lambda { Micronaut::Expectations.fail_with "the message" }.should fail_with("the message")
9
+ end
14
10
 
15
- it "should handle an Array" do
16
- lambda {
17
- Micronaut::Expectations.fail_with ["the message","expected","actual"]
18
- }.should fail_with("the message")
19
- end
11
+ it "should handle an Array" do
12
+ lambda { Micronaut::Expectations.fail_with ["the message","expected","actual"] }.should fail_with("the message")
13
+ end
20
14
 
21
- after(:each) do
22
- Micronaut::Expectations.differ = @old_differ
23
15
  end
24
- end
25
16
 
26
- describe Micronaut::Expectations, "#fail_with with diff" do
27
- before do
28
- @old_differ = Micronaut::Expectations.differ
29
- @differ = mock("differ")
30
- Micronaut::Expectations.differ = @differ
31
- end
32
-
33
- it "should not call differ if no expected/actual" do
34
- lambda {
35
- Micronaut::Expectations.fail_with "the message"
36
- }.should fail_with("the message")
37
- end
38
-
39
- it "should call differ if expected/actual are presented separately" do
40
- @differ.expects(:diff_as_string).returns("diff")
41
- lambda {
42
- Micronaut::Expectations.fail_with "the message", "expected", "actual"
43
- }.should fail_with("the message\nDiff:diff")
44
- end
45
-
46
- it "should call differ if expected/actual are not strings" do
47
- @differ.expects(:diff_as_object).returns("diff")
48
- lambda {
49
- Micronaut::Expectations.fail_with "the message", :expected, :actual
50
- }.should fail_with("the message\nDiff:diff")
51
- end
52
-
53
- it "should not call differ if expected or actual are procs" do
54
- @differ.expects(:diff_as_string).never
55
- @differ.expects(:diff_as_object).never
56
- lambda {
57
- Micronaut::Expectations.fail_with "the message", lambda {}, lambda {}
58
- }.should fail_with("the message")
59
- end
60
-
61
- it "should call differ if expected/actual are presented in an Array with message" do
62
- @differ.expects(:diff_as_string).with("actual","expected").returns("diff")
63
- lambda {
64
- Micronaut::Expectations.fail_with(["the message", "expected", "actual"])
65
- }.should fail_with(/the message\nDiff:diff/)
66
- end
67
-
68
- after(:each) do
69
- Micronaut::Expectations.differ = @old_differ
70
- end
71
- end
17
+ end