rsanheim-micronaut 0.1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/LICENSE +45 -0
  2. data/README +17 -0
  3. data/RSPEC-LICENSE +23 -0
  4. data/Rakefile +83 -0
  5. data/bin/micronaut +4 -0
  6. data/examples/example_helper.rb +36 -0
  7. data/examples/lib/micronaut/behaviour_example.rb +188 -0
  8. data/examples/lib/micronaut/configuration_example.rb +70 -0
  9. data/examples/lib/micronaut/example_example.rb +46 -0
  10. data/examples/lib/micronaut/expectations/extensions/object_example.rb +72 -0
  11. data/examples/lib/micronaut/expectations/fail_with_example.rb +17 -0
  12. data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +31 -0
  13. data/examples/lib/micronaut/formatters/base_formatter_example.rb +107 -0
  14. data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
  15. data/examples/lib/micronaut/formatters/progress_formatter_example.rb +74 -0
  16. data/examples/lib/micronaut/kernel_extensions_example.rb +13 -0
  17. data/examples/lib/micronaut/matchers/be_close_example.rb +52 -0
  18. data/examples/lib/micronaut/matchers/be_example.rb +298 -0
  19. data/examples/lib/micronaut/matchers/change_example.rb +360 -0
  20. data/examples/lib/micronaut/matchers/description_generation_example.rb +175 -0
  21. data/examples/lib/micronaut/matchers/eql_example.rb +35 -0
  22. data/examples/lib/micronaut/matchers/equal_example.rb +35 -0
  23. data/examples/lib/micronaut/matchers/handler_example.rb +153 -0
  24. data/examples/lib/micronaut/matchers/has_example.rb +71 -0
  25. data/examples/lib/micronaut/matchers/have_example.rb +575 -0
  26. data/examples/lib/micronaut/matchers/include_example.rb +103 -0
  27. data/examples/lib/micronaut/matchers/match_example.rb +43 -0
  28. data/examples/lib/micronaut/matchers/matcher_methods_example.rb +66 -0
  29. data/examples/lib/micronaut/matchers/operator_matcher_example.rb +189 -0
  30. data/examples/lib/micronaut/matchers/raise_error_example.rb +346 -0
  31. data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
  32. data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
  33. data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
  34. data/examples/lib/micronaut/matchers/throw_symbol_example.rb +96 -0
  35. data/examples/lib/micronaut/runner_example.rb +5 -0
  36. data/examples/lib/micronaut/runner_options_example.rb +5 -0
  37. data/examples/lib/micronaut/world_example.rb +102 -0
  38. data/examples/lib/micronaut_example.rb +23 -0
  39. data/examples/resources/example_classes.rb +67 -0
  40. data/lib/autotest/discover.rb +3 -0
  41. data/lib/autotest/micronaut.rb +47 -0
  42. data/lib/micronaut/behaviour.rb +211 -0
  43. data/lib/micronaut/configuration.rb +133 -0
  44. data/lib/micronaut/example.rb +28 -0
  45. data/lib/micronaut/expectations/extensions/object.rb +62 -0
  46. data/lib/micronaut/expectations/extensions/string_and_symbol.rb +19 -0
  47. data/lib/micronaut/expectations/handler.rb +52 -0
  48. data/lib/micronaut/expectations/wrap_expectation.rb +57 -0
  49. data/lib/micronaut/expectations.rb +46 -0
  50. data/lib/micronaut/formatters/base_formatter.rb +82 -0
  51. data/lib/micronaut/formatters/base_text_formatter.rb +148 -0
  52. data/lib/micronaut/formatters/documentation_formatter.rb +62 -0
  53. data/lib/micronaut/formatters/progress_formatter.rb +36 -0
  54. data/lib/micronaut/formatters.rb +12 -0
  55. data/lib/micronaut/kernel_extensions.rb +11 -0
  56. data/lib/micronaut/matchers/be.rb +204 -0
  57. data/lib/micronaut/matchers/be_close.rb +22 -0
  58. data/lib/micronaut/matchers/change.rb +148 -0
  59. data/lib/micronaut/matchers/eql.rb +26 -0
  60. data/lib/micronaut/matchers/equal.rb +26 -0
  61. data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
  62. data/lib/micronaut/matchers/has.rb +19 -0
  63. data/lib/micronaut/matchers/have.rb +153 -0
  64. data/lib/micronaut/matchers/include.rb +80 -0
  65. data/lib/micronaut/matchers/match.rb +22 -0
  66. data/lib/micronaut/matchers/method_missing.rb +9 -0
  67. data/lib/micronaut/matchers/operator_matcher.rb +50 -0
  68. data/lib/micronaut/matchers/raise_error.rb +128 -0
  69. data/lib/micronaut/matchers/respond_to.rb +50 -0
  70. data/lib/micronaut/matchers/satisfy.rb +50 -0
  71. data/lib/micronaut/matchers/simple_matcher.rb +135 -0
  72. data/lib/micronaut/matchers/throw_symbol.rb +108 -0
  73. data/lib/micronaut/matchers.rb +148 -0
  74. data/lib/micronaut/mocking/with_absolutely_nothing.rb +11 -0
  75. data/lib/micronaut/mocking/with_mocha.rb +13 -0
  76. data/lib/micronaut/mocking/with_rr.rb +24 -0
  77. data/lib/micronaut/mocking.rb +7 -0
  78. data/lib/micronaut/runner.rb +57 -0
  79. data/lib/micronaut/runner_options.rb +33 -0
  80. data/lib/micronaut/world.rb +75 -0
  81. data/lib/micronaut.rb +37 -0
  82. metadata +149 -0
@@ -0,0 +1,107 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Formatters::BaseFormatter do
4
+
5
+ before(:all) do
6
+ @formatter = Micronaut::Formatters::BaseFormatter.new(nil, nil)
7
+ end
8
+
9
+ class HaveInterfaceMatcher
10
+ def initialize(method)
11
+ @method = method
12
+ end
13
+
14
+ attr_reader :object
15
+ attr_reader :method
16
+
17
+ def matches?(object)
18
+ @object = object
19
+ object.respond_to?(@method)
20
+ end
21
+
22
+ def with(arity)
23
+ WithArity.new(self, @method, arity)
24
+ end
25
+
26
+ class WithArity
27
+ def initialize(matcher, method, arity)
28
+ @have_matcher = matcher
29
+ @method = method
30
+ @arity = arity
31
+ end
32
+
33
+ def matches?(an_object)
34
+ @have_matcher.matches?(an_object) && real_arity == @arity
35
+ end
36
+
37
+ def failure_message
38
+ "#{@have_matcher} should have method :#{@method} with #{argument_arity}, but it had #{real_arity}"
39
+ end
40
+
41
+ def arguments
42
+ self
43
+ end
44
+
45
+ alias_method :argument, :arguments
46
+
47
+ private
48
+
49
+ def real_arity
50
+ @have_matcher.object.method(@method).arity
51
+ end
52
+
53
+ def argument_arity
54
+ if @arity == 1
55
+ "1 argument"
56
+ else
57
+ "#{@arity} arguments"
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ def have_interface_for(method)
64
+ HaveInterfaceMatcher.new(method)
65
+ end
66
+
67
+ it "should have start as an interface with one argument" do
68
+ @formatter.should have_interface_for(:start).with(1).argument
69
+ end
70
+
71
+ it "should have add_behaviour as an interface with one argument" do
72
+ @formatter.should have_interface_for(:add_behaviour).with(1).argument
73
+ end
74
+
75
+ it "should have example_started as an interface with one argument" do
76
+ @formatter.should have_interface_for(:example_started).with(1).argument
77
+ end
78
+
79
+ it "should have example_failed as an interface with two arguments" do
80
+ @formatter.should have_interface_for(:example_failed).with(2).arguments
81
+ end
82
+
83
+ it "should have example_pending as an interface with two arguments" do
84
+ @formatter.should have_interface_for(:example_pending).with(2).arguments
85
+ end
86
+
87
+ it "should have start_dump as an interface with zero arguments" do
88
+ @formatter.should have_interface_for(:start_dump).with(0).arguments
89
+ end
90
+
91
+ it "should have dump_failures as an interface with no arguments" do
92
+ @formatter.should have_interface_for(:dump_failures).with(0).arguments
93
+ end
94
+
95
+ it "should have dump_summary as an interface with 4 arguments" do
96
+ @formatter.should have_interface_for(:dump_summary).with(4).arguments
97
+ end
98
+
99
+ it "should have dump_pending as an interface with zero arguments" do
100
+ @formatter.should have_interface_for(:dump_pending).with(0).arguments
101
+ end
102
+
103
+ it "should have close as an interface with zero arguments" do
104
+ @formatter.should have_interface_for(:close).with(0).arguments
105
+ end
106
+
107
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Formatters::DocumentationFormatter do
4
+
5
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Formatters::ProgressFormatter do
4
+
5
+ before do
6
+ @io = StringIO.new
7
+ @options = mock('options')
8
+ @options.stubs(:enable_color_in_output?).returns(false)
9
+ @formatter = Micronaut::Formatters::ProgressFormatter.new(@options, @io)
10
+ @original_profile_setting = Micronaut.configuration.profile_examples
11
+ end
12
+
13
+ it "should produce line break on start dump" do
14
+ @formatter.start_dump
15
+ @io.string.should eql("\n")
16
+ end
17
+
18
+ it "should produce standard summary without pending when pending has a 0 count" do
19
+ @formatter.dump_summary(3, 2, 1, 0)
20
+ @io.string.should =~ /\nFinished in 3 seconds\n2 examples, 1 failure\n/
21
+ end
22
+
23
+ it "should produce standard summary" do
24
+ behaviour = Micronaut::Behaviour.describe("behaviour") do
25
+ it('example') {}
26
+ end
27
+ remove_last_describe_from_world
28
+ example = behaviour.examples.first
29
+ @formatter.example_pending(example, "message")
30
+ @io.rewind
31
+ @formatter.dump_summary(3, 2, 1, 1)
32
+ @io.string.should =~ /\nFinished in 3 seconds\n2 examples, 1 failure, 1 pending\n/
33
+ end
34
+
35
+ it "should push green dot for passing spec" do
36
+ @options.expects(:enable_color_in_output?).returns(true)
37
+ @formatter.example_passed("spec")
38
+ @io.string.should == "\e[32m.\e[0m"
39
+ end
40
+
41
+ it "should push red F for failure spec" do
42
+ @options.expects(:enable_color_in_output?).returns(true)
43
+ @formatter.example_failed("spec", Micronaut::Expectations::ExpectationNotMetError.new)
44
+ @io.string.should eql("\e[31mF\e[0m")
45
+ end
46
+
47
+ it "should push magenta F for error spec" do
48
+ @options.expects(:enable_color_in_output?).returns(true)
49
+ @formatter.example_failed("spec", RuntimeError.new)
50
+ @io.string.should eql("\e[35mF\e[0m")
51
+ end
52
+
53
+ it "should push nothing on start" do
54
+ @formatter.start(4)
55
+ @io.string.should eql("")
56
+ end
57
+
58
+ it "should ensure two ':' in the first backtrace" do
59
+ backtrace = ["/tmp/x.rb:1", "/tmp/x.rb:2", "/tmp/x.rb:3"]
60
+ @formatter.format_backtrace(backtrace).should eql(<<-EOE.rstrip)
61
+ /tmp/x.rb:1
62
+ /tmp/x.rb:2
63
+ /tmp/x.rb:3
64
+ EOE
65
+
66
+ backtrace = ["/tmp/x.rb:1: message", "/tmp/x.rb:2", "/tmp/x.rb:3"]
67
+ @formatter.format_backtrace(backtrace).should eql(<<-EOE.rstrip)
68
+ /tmp/x.rb:1: message
69
+ /tmp/x.rb:2
70
+ /tmp/x.rb:3
71
+ EOE
72
+ end
73
+
74
+ 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
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers do
4
+
5
+ describe "be_close" do
6
+
7
+ it "should match when value == target" do
8
+ be_close(5.0, 0.5).matches?(5.0).should be_true
9
+ end
10
+
11
+ it "should match when value < (target + delta)" do
12
+ be_close(5.0, 0.5).matches?(5.49).should be_true
13
+ end
14
+
15
+ it "should match when value > (target - delta)" do
16
+ be_close(5.0, 0.5).matches?(4.51).should be_true
17
+ end
18
+
19
+ it "should not match when value == (target - delta)" do
20
+ be_close(5.0, 0.5).matches?(4.5).should be_false
21
+ end
22
+
23
+ it "should not match when value < (target - delta)" do
24
+ be_close(5.0, 0.5).matches?(4.49).should be_false
25
+ end
26
+
27
+ it "should not match when value == (target + delta)" do
28
+ be_close(5.0, 0.5).matches?(5.5).should be_false
29
+ end
30
+
31
+ it "should not match when value > (target + delta)" do
32
+ be_close(5.0, 0.5).matches?(5.51).should be_false
33
+ end
34
+
35
+ it "should provide a useful failure message" do
36
+ #given
37
+ matcher = be_close(5.0, 0.5)
38
+ #when
39
+ matcher.matches?(5.51)
40
+ #then
41
+ matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
42
+ end
43
+
44
+ it "should describe itself" do
45
+ matcher = be_close(5.0, 0.5)
46
+ matcher.matches?(5.1)
47
+ matcher.description.should == "be close to 5.0 (within +- 0.5)"
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,298 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers do
4
+
5
+ describe "should be_predicate" do
6
+
7
+ it "should pass when actual returns true for :predicate?" do
8
+ actual = stub("actual", :happy? => true)
9
+ actual.should be_happy
10
+ end
11
+
12
+ it "should pass when actual returns true for :predicates? (present tense)" do
13
+ actual = stub("actual", :exists? => true, :exist? => true)
14
+ actual.should be_exist
15
+ end
16
+
17
+ it "should fail when actual returns false for :predicate?" do
18
+ actual = stub("actual", :happy? => false)
19
+ lambda do
20
+ actual.should be_happy
21
+ end.should fail_with("expected happy? to return true, got false")
22
+ end
23
+
24
+ it "should fail when actual does not respond to :predicate?" do
25
+ lambda do
26
+ Object.new.should be_happy
27
+ end.should raise_error(NameError, /happy\?/)
28
+ end
29
+
30
+ it "should fail on error other than NameError" do
31
+ actual = stub("actual")
32
+ actual.expects(:foo?).raises("aaaah")
33
+ lambda do
34
+ actual.should be_foo
35
+ end.should raise_error(/aaaah/)
36
+ end
37
+
38
+ it "should fail on error other than NameError (with the present tense predicate)" do
39
+ actual = Object.new
40
+ actual.expects(:foos?).raises("aaaah")
41
+ lambda do
42
+ actual.should be_foo
43
+ end.should raise_error(/aaaah/)
44
+ end
45
+
46
+ end
47
+
48
+ describe "should_not be_predicate" do
49
+
50
+ it "should pass when actual returns false for :sym?" do
51
+ actual = stub("actual", :happy? => false)
52
+ actual.should_not be_happy
53
+ end
54
+
55
+ it "should fail when actual returns true for :sym?" do
56
+ actual = stub("actual", :happy? => true)
57
+ lambda do
58
+ actual.should_not be_happy
59
+ end.should fail_with("expected happy? to return false, got true")
60
+ end
61
+
62
+ it "should fail when actual does not respond to :sym?" do
63
+ lambda do
64
+ Object.new.should_not be_happy
65
+ end.should raise_error(NameError)
66
+ end
67
+
68
+ end
69
+
70
+ describe "should be_predicate(*args)" do
71
+
72
+ it "should pass when actual returns true for :predicate?(*args)" do
73
+ actual = mock("actual")
74
+ actual.expects(:older_than?).with(3).returns(true)
75
+ actual.should be_older_than(3)
76
+ end
77
+
78
+ it "should fail when actual returns false for :predicate?(*args)" do
79
+ actual = mock("actual")
80
+ actual.expects(:older_than?).with(3).returns(false)
81
+ lambda do
82
+ actual.should be_older_than(3)
83
+ end.should fail_with("expected older_than?(3) to return true, got false")
84
+ end
85
+
86
+ it "should fail when actual does not respond to :predicate?" do
87
+ lambda do
88
+ Object.new.should be_older_than(3)
89
+ end.should raise_error(NameError)
90
+ end
91
+
92
+ end
93
+
94
+ describe "should_not be_predicate(*args)" do
95
+
96
+ it "should pass when actual returns false for :predicate?(*args)" do
97
+ actual = mock("actual")
98
+ actual.expects(:older_than?).with(3).returns(false)
99
+ actual.should_not be_older_than(3)
100
+ end
101
+
102
+ it "should fail when actual returns true for :predicate?(*args)" do
103
+ actual = mock("actual")
104
+ actual.expects(:older_than?).with(3).returns(true)
105
+ lambda do
106
+ actual.should_not be_older_than(3)
107
+ end.should fail_with("expected older_than?(3) to return false, got true")
108
+ end
109
+
110
+ it "should fail when actual does not respond to :predicate?" do
111
+ lambda do
112
+ Object.new.should_not be_older_than(3)
113
+ end.should raise_error(NameError)
114
+ end
115
+
116
+ end
117
+
118
+ describe "should be_true" do
119
+
120
+ it "should pass when actual equal(true)" do
121
+ true.should be_true
122
+ end
123
+
124
+ it "should fail when actual equal(false)" do
125
+ lambda do
126
+ false.should be_true
127
+ end.should fail_with("expected true, got false")
128
+ end
129
+
130
+ end
131
+
132
+ describe "should be_false" do
133
+
134
+ it "should pass when actual equal(false)" do
135
+ false.should be_false
136
+ end
137
+
138
+ it "should fail when actual equal(true)" do
139
+ lambda do
140
+ true.should be_false
141
+ end.should fail_with("expected false, got true")
142
+ end
143
+
144
+ end
145
+
146
+ describe "should be_nil" do
147
+
148
+ it "should pass when actual is nil" do
149
+ nil.should be_nil
150
+ end
151
+
152
+ it "should fail when actual is not nil" do
153
+ lambda do
154
+ :not_nil.should be_nil
155
+ end.should fail_with("expected nil? to return true, got false")
156
+ end
157
+
158
+ end
159
+
160
+ describe "should_not be_nil" do
161
+
162
+ it "should pass when actual is not nil" do
163
+ :not_nil.should_not be_nil
164
+ end
165
+
166
+ it "should fail when actual is nil" do
167
+ lambda do
168
+ nil.should_not be_nil
169
+ end.should fail_with("expected nil? to return false, got true")
170
+ end
171
+
172
+ end
173
+
174
+ describe "should be <" do
175
+
176
+ it "should pass when < operator returns true" do
177
+ 3.should be < 4
178
+ end
179
+
180
+ it "should fail when < operator returns false" do
181
+ lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
182
+ end
183
+
184
+ end
185
+
186
+ describe "should be <=" do
187
+
188
+ it "should pass when <= operator returns true" do
189
+ 3.should be <= 4
190
+ 4.should be <= 4
191
+ end
192
+
193
+ it "should fail when <= operator returns false" do
194
+ lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
195
+ end
196
+
197
+ end
198
+
199
+ describe "should be >=" do
200
+
201
+ it "should pass when >= operator returns true" do
202
+ 4.should be >= 4
203
+ 5.should be >= 4
204
+ end
205
+
206
+ it "should fail when >= operator returns false" do
207
+ lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
208
+ end
209
+
210
+ end
211
+
212
+ describe "should be >" do
213
+
214
+ it "should pass when > operator returns true" do
215
+ 5.should be > 4
216
+ end
217
+
218
+ it "should fail when > operator returns false" do
219
+ lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
220
+ end
221
+
222
+ end
223
+
224
+ describe "should be ==" do
225
+
226
+ it "should pass when == operator returns true" do
227
+ 5.should be == 5
228
+ end
229
+
230
+ it "should fail when == operator returns false" do
231
+ lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
232
+ end
233
+
234
+ end
235
+
236
+ describe "should be ===" do
237
+
238
+ it "should pass when === operator returns true" do
239
+ Hash.should be === Hash.new
240
+ end
241
+
242
+ it "should fail when === operator returns false" do
243
+ lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === not a hash, got Hash])
244
+ end
245
+
246
+ end
247
+
248
+ describe "should_not with operators" do
249
+
250
+ it "should coach user to stop using operators with should_not" do
251
+ lambda do
252
+ 5.should_not be < 6
253
+ end.should raise_error(/not only FAILED,\nit reads really poorly./m)
254
+ end
255
+
256
+ end
257
+
258
+ describe "should be" do
259
+
260
+ it "should pass if actual is true or a set value" do
261
+ true.should be
262
+ 1.should be
263
+ end
264
+
265
+ it "should fail if actual is false" do
266
+ lambda {false.should be}.should fail_with("expected true, got false")
267
+ end
268
+
269
+ it "should fail if actual is nil" do
270
+ lambda {nil.should be}.should fail_with("expected true, got nil")
271
+ end
272
+
273
+ end
274
+
275
+ describe "should be(value)" do
276
+
277
+ it "should pass if actual.equal?(value)" do
278
+ 5.should be(5)
279
+ end
280
+
281
+ it "should fail if !actual.equal?(value)" do
282
+ lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
283
+ end
284
+
285
+ end
286
+
287
+ describe "'should be' with operator" do
288
+
289
+ it "should include 'be' in the description" do
290
+ (be > 6).description.should =~ /be > 6/
291
+ (be >= 6).description.should =~ /be >= 6/
292
+ (be <= 6).description.should =~ /be <= 6/
293
+ (be < 6).description.should =~ /be < 6/
294
+ end
295
+
296
+ end
297
+
298
+ end