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.
- data/RSPEC-LICENSE +23 -0
- data/Rakefile +2 -2
- data/examples/example_helper.rb +10 -0
- data/examples/lib/micronaut/behaviour_group_example.rb +170 -159
- data/examples/lib/micronaut/expectations/fail_with_example.rb +10 -64
- data/examples/lib/micronaut/formatters/progress_formatter_example.rb +3 -7
- data/examples/lib/micronaut/matchers/description_generation_example.rb +1 -1
- data/examples/lib/micronaut/matchers/have_example.rb +2 -2
- data/examples/lib/micronaut/matchers/operator_matcher_example.rb +0 -2
- data/examples/lib/micronaut/matchers/raise_error_example.rb +32 -1
- data/examples/lib/micronaut/{example_runner_example.rb → runner_example.rb} +0 -0
- data/examples/lib/micronaut/runner_options_example.rb +5 -0
- data/examples/lib/micronaut/world_example.rb +94 -0
- data/lib/micronaut.rb +1 -15
- data/lib/micronaut/behaviour_group.rb +34 -16
- data/lib/micronaut/behaviour_group_class_methods.rb +32 -47
- data/lib/micronaut/expectations.rb +0 -12
- data/lib/micronaut/extensions/kernel.rb +2 -2
- data/lib/micronaut/formatters/base_formatter.rb +4 -3
- data/lib/micronaut/formatters/base_text_formatter.rb +29 -17
- data/lib/micronaut/formatters/progress_formatter.rb +1 -1
- data/lib/micronaut/runner.rb +2 -2
- data/lib/micronaut/world.rb +36 -0
- metadata +7 -10
- data/examples/lib/micronaut/expectations/differs/default_example.rb +0 -125
- data/examples/lib/micronaut/matchers/exist_example.rb +0 -69
- data/lib/micronaut/example_world.rb +0 -17
- data/lib/micronaut/expectations/differs/default.rb +0 -58
- data/lib/micronaut/matchers/exist.rb +0 -16
@@ -16,7 +16,7 @@ describe Micronaut::Formatters::ProgressFormatter do
|
|
16
16
|
|
17
17
|
it "should produce standard summary without pending when pending has a 0 count" do
|
18
18
|
@formatter.dump_summary(3, 2, 1, 0)
|
19
|
-
@io.string.should == "\nFinished in 3 seconds\
|
19
|
+
@io.string.should == "\nFinished in 3 seconds\n2 examples, 1 failure\n"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should produce standard summary" do
|
@@ -27,11 +27,7 @@ describe Micronaut::Formatters::ProgressFormatter do
|
|
27
27
|
@formatter.example_pending(example, "message")
|
28
28
|
@io.rewind
|
29
29
|
@formatter.dump_summary(3, 2, 1, 1)
|
30
|
-
@io.string.should
|
31
|
-
Finished in 3 seconds
|
32
|
-
|
33
|
-
2 examples, 1 failure, 1 pending
|
34
|
-
|)
|
30
|
+
@io.string.should == "\nFinished in 3 seconds\n2 examples, 1 failure, 1 pending\n"
|
35
31
|
end
|
36
32
|
|
37
33
|
it "should push green dot for passing spec" do
|
@@ -85,7 +81,7 @@ EOE
|
|
85
81
|
@formatter.class.__send__ :public, :output_to_tty?
|
86
82
|
end
|
87
83
|
|
88
|
-
after
|
84
|
+
after do
|
89
85
|
@formatter.class.__send__ :protected, :output_to_tty?
|
90
86
|
end
|
91
87
|
|
@@ -112,7 +112,7 @@ describe 'should have(1).item when ActiveSupport::Inflector is defined' do
|
|
112
112
|
owner.should have(1).item
|
113
113
|
end
|
114
114
|
|
115
|
-
after
|
115
|
+
after do
|
116
116
|
if @active_support_was_not_defined
|
117
117
|
Object.__send__ :remove_const, :ActiveSupport
|
118
118
|
end
|
@@ -160,7 +160,7 @@ describe 'should have(1).item when Inflector is defined' do
|
|
160
160
|
owner.should have(1).item
|
161
161
|
end
|
162
162
|
|
163
|
-
after
|
163
|
+
after do
|
164
164
|
if @inflector_was_not_defined
|
165
165
|
Object.__send__ :remove_const, :Inflector
|
166
166
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
2
|
|
3
3
|
describe "should raise_error" do
|
4
|
+
|
4
5
|
it "should pass if anything is raised" do
|
5
6
|
lambda {raise}.should raise_error
|
6
7
|
end
|
@@ -10,9 +11,11 @@ describe "should raise_error" do
|
|
10
11
|
lambda {}.should raise_error
|
11
12
|
}.should fail_with("expected Exception but nothing was raised")
|
12
13
|
end
|
14
|
+
|
13
15
|
end
|
14
16
|
|
15
17
|
describe "should_not raise_error" do
|
18
|
+
|
16
19
|
it "should pass if nothing is raised" do
|
17
20
|
lambda {}.should_not raise_error
|
18
21
|
end
|
@@ -22,50 +25,63 @@ describe "should_not raise_error" do
|
|
22
25
|
lambda {raise}.should_not raise_error
|
23
26
|
}.should fail_with("expected no Exception, got RuntimeError")
|
24
27
|
end
|
28
|
+
|
25
29
|
end
|
26
30
|
|
27
31
|
describe "should raise_error(message)" do
|
32
|
+
|
28
33
|
it "should pass if RuntimeError is raised with the right message" do
|
29
34
|
lambda {raise 'blah'}.should raise_error('blah')
|
30
35
|
end
|
36
|
+
|
31
37
|
it "should pass if RuntimeError is raised with a matching message" do
|
32
38
|
lambda {raise 'blah'}.should raise_error(/blah/)
|
33
39
|
end
|
40
|
+
|
34
41
|
it "should pass if any other error is raised with the right message" do
|
35
42
|
lambda {raise NameError.new('blah')}.should raise_error('blah')
|
36
43
|
end
|
44
|
+
|
37
45
|
it "should fail if RuntimeError error is raised with the wrong message" do
|
38
46
|
lambda do
|
39
47
|
lambda {raise 'blarg'}.should raise_error('blah')
|
40
48
|
end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
|
41
49
|
end
|
50
|
+
|
42
51
|
it "should fail if any other error is raised with the wrong message" do
|
43
52
|
lambda do
|
44
53
|
lambda {raise NameError.new('blarg')}.should raise_error('blah')
|
45
54
|
end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
|
46
55
|
end
|
56
|
+
|
47
57
|
end
|
48
58
|
|
49
59
|
describe "should_not raise_error(message)" do
|
60
|
+
|
50
61
|
it "should pass if RuntimeError error is raised with the different message" do
|
51
62
|
lambda {raise 'blarg'}.should_not raise_error('blah')
|
52
63
|
end
|
64
|
+
|
53
65
|
it "should pass if any other error is raised with the wrong message" do
|
54
66
|
lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
|
55
67
|
end
|
68
|
+
|
56
69
|
it "should fail if RuntimeError is raised with message" do
|
57
70
|
lambda do
|
58
71
|
lambda {raise 'blah'}.should_not raise_error('blah')
|
59
72
|
end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
|
60
73
|
end
|
74
|
+
|
61
75
|
it "should fail if any other error is raised with message" do
|
62
76
|
lambda do
|
63
77
|
lambda {raise NameError.new('blah')}.should_not raise_error('blah')
|
64
78
|
end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
|
65
79
|
end
|
80
|
+
|
66
81
|
end
|
67
82
|
|
68
83
|
describe "should raise_error(NamedError)" do
|
84
|
+
|
69
85
|
it "should pass if named error is raised" do
|
70
86
|
lambda { non_existent_method }.should raise_error(NameError)
|
71
87
|
end
|
@@ -87,9 +103,11 @@ describe "should raise_error(NamedError)" do
|
|
87
103
|
lambda { load "non/existent/file" }.should raise_error(NameError)
|
88
104
|
}.should fail_with(/expected NameError, got #<LoadError/)
|
89
105
|
end
|
106
|
+
|
90
107
|
end
|
91
108
|
|
92
109
|
describe "should_not raise_error(NamedError)" do
|
110
|
+
|
93
111
|
it "should pass if nothing is raised" do
|
94
112
|
lambda { }.should_not raise_error(NameError)
|
95
113
|
end
|
@@ -103,9 +121,11 @@ describe "should_not raise_error(NamedError)" do
|
|
103
121
|
lambda { non_existent_method }.should_not raise_error(NameError)
|
104
122
|
}.should fail_with(/expected no NameError, got #<NameError: undefined/)
|
105
123
|
end
|
124
|
+
|
106
125
|
end
|
107
126
|
|
108
127
|
describe "should raise_error(NamedError, error_message) with String" do
|
128
|
+
|
109
129
|
it "should pass if named error is raised with same message" do
|
110
130
|
lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
|
111
131
|
end
|
@@ -127,9 +147,11 @@ describe "should raise_error(NamedError, error_message) with String" do
|
|
127
147
|
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
|
128
148
|
}.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
|
129
149
|
end
|
150
|
+
|
130
151
|
end
|
131
152
|
|
132
153
|
describe "should raise_error(NamedError, error_message) { |err| ... }" do
|
154
|
+
|
133
155
|
it "should yield exception if named error is raised with same message" do
|
134
156
|
ran = false
|
135
157
|
|
@@ -200,9 +222,11 @@ describe "should raise_error(NamedError, error_message) { |err| ... }" do
|
|
200
222
|
|
201
223
|
ran.should == false
|
202
224
|
end
|
225
|
+
|
203
226
|
end
|
204
227
|
|
205
228
|
describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
|
229
|
+
|
206
230
|
it "should pass if nothing is raised" do
|
207
231
|
ran = false
|
208
232
|
|
@@ -248,9 +272,11 @@ describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
|
|
248
272
|
|
249
273
|
ran.should == false
|
250
274
|
end
|
275
|
+
|
251
276
|
end
|
252
277
|
|
253
278
|
describe "should_not raise_error(NamedError, error_message) with String" do
|
279
|
+
|
254
280
|
it "should pass if nothing is raised" do
|
255
281
|
lambda {}.should_not raise_error(RuntimeError, "example message")
|
256
282
|
end
|
@@ -268,9 +294,11 @@ describe "should_not raise_error(NamedError, error_message) with String" do
|
|
268
294
|
lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
|
269
295
|
}.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
|
270
296
|
end
|
297
|
+
|
271
298
|
end
|
272
299
|
|
273
300
|
describe "should raise_error(NamedError, error_message) with Regexp" do
|
301
|
+
|
274
302
|
it "should pass if named error is raised with matching message" do
|
275
303
|
lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
|
276
304
|
end
|
@@ -292,9 +320,11 @@ describe "should raise_error(NamedError, error_message) with Regexp" do
|
|
292
320
|
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
|
293
321
|
}.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
|
294
322
|
end
|
323
|
+
|
295
324
|
end
|
296
325
|
|
297
326
|
describe "should_not raise_error(NamedError, error_message) with Regexp" do
|
327
|
+
|
298
328
|
it "should pass if nothing is raised" do
|
299
329
|
lambda {}.should_not raise_error(RuntimeError, /ample mess/)
|
300
330
|
end
|
@@ -312,4 +342,5 @@ describe "should_not raise_error(NamedError, error_message) with Regexp" do
|
|
312
342
|
lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
|
313
343
|
}.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
|
314
344
|
end
|
315
|
-
|
345
|
+
|
346
|
+
end
|
File without changes
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
|
2
|
+
|
3
|
+
class Bar; end
|
4
|
+
|
5
|
+
describe Micronaut::World do
|
6
|
+
|
7
|
+
describe "behaviour groups" do
|
8
|
+
|
9
|
+
it "should contain all defined behaviour groups" do
|
10
|
+
behaviour_group = Micronaut::BehaviourGroup.describe(Bar, 'Empty Behaviour Group') { }
|
11
|
+
Micronaut::World.behaviour_groups.should include(behaviour_group)
|
12
|
+
remove_last_describe_from_world
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "find" do
|
18
|
+
|
19
|
+
before(:all) do
|
20
|
+
options_1 = { :foo => 1, :color => 'blue', :feature => 'reporting' }
|
21
|
+
options_2 = { :pending => true, :feature => 'reporting' }
|
22
|
+
options_3 = { :array => [1,2,3,4], :color => 'blue', :feature => 'weather status' }
|
23
|
+
@bg1 = Micronaut::BehaviourGroup.describe(Bar, "find group-1", options_1) { }
|
24
|
+
@bg2 = Micronaut::BehaviourGroup.describe(Bar, "find group-2", options_2) { }
|
25
|
+
@bg3 = Micronaut::BehaviourGroup.describe(Bar, "find group-3", options_3) { }
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:all) do
|
29
|
+
Micronaut::World.behaviour_groups.delete(@bg1)
|
30
|
+
Micronaut::World.behaviour_groups.delete(@bg2)
|
31
|
+
Micronaut::World.behaviour_groups.delete(@bg3)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should find no groups when given no search parameters" do
|
35
|
+
Micronaut::World.find.should == []
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should find three groups when searching for :described_type => Bar" do
|
39
|
+
Micronaut::World.find(:described_type => Bar).should == [@bg1, @bg2, @bg3]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should find one group when searching for :description => 'find group-1'" do
|
43
|
+
Micronaut::World.find(:description => 'find group-1').should == [@bg1]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should find two groups when searching for :description => lambda { |v| v.include?('-1') || v.include?('-3') }" do
|
47
|
+
Micronaut::World.find(:description => lambda { |v| v.include?('-1') || v.include?('-3') }).should == [@bg1, @bg3]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should find three groups when searching for :description => /find group/" do
|
51
|
+
Micronaut::World.find(:description => /find group/).should == [@bg1, @bg2, @bg3]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should find one group when searching for :options => { :foo => 1 }" do
|
55
|
+
Micronaut::World.find(:options => { :foo => 1 }).should == [@bg1]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should find one group when searching for :options => { :pending => true }" do
|
59
|
+
Micronaut::World.find(:options => { :pending => true }).should == [@bg2]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should find one group when searching for :options => { :array => [1,2,3,4] }" do
|
63
|
+
Micronaut::World.find(:options => { :array => [1,2,3,4] }).should == [@bg3]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should find no group when searching for :options => { :array => [4,3,2,1] }" do
|
67
|
+
Micronaut::World.find(:options => { :array => [4,3,2,1] }).should be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should find two groups when searching for :options => { :color => 'blue' }" do
|
71
|
+
Micronaut::World.find(:options => { :color => 'blue' }).should == [@bg1, @bg3]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should find two groups when searching for :options => { :feature => 'reporting' }" do
|
75
|
+
Micronaut::World.find(:options => { :feature => 'reporting' }).should == [@bg1, @bg2]
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "reset" do
|
81
|
+
|
82
|
+
it "should clear the list of behaviour groups" do
|
83
|
+
original_groups = Micronaut::World.behaviour_groups
|
84
|
+
|
85
|
+
Micronaut::World.behaviour_groups.should_not be_empty
|
86
|
+
Micronaut::World.reset
|
87
|
+
Micronaut::World.behaviour_groups.should be_empty
|
88
|
+
|
89
|
+
Micronaut::World.behaviour_groups.concat(original_groups)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
data/lib/micronaut.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'micronaut/mocking/with_mocha'
|
2
2
|
require 'micronaut/matchers'
|
3
3
|
require 'micronaut/expectations'
|
4
|
-
require 'micronaut/
|
4
|
+
require 'micronaut/world'
|
5
5
|
require 'micronaut/runner'
|
6
6
|
require 'micronaut/runner_options'
|
7
7
|
require 'micronaut/behaviour_group_class_methods'
|
@@ -24,19 +24,5 @@ module Micronaut
|
|
24
24
|
|
25
25
|
# './lib' in project dir, or '/usr/local/blahblah' if installed
|
26
26
|
MICRONAUT_DIR = File.expand_path(File.dirname(File.dirname(file)))
|
27
|
-
|
28
|
-
def self.filter_backtrace(backtrace)
|
29
|
-
return ["No backtrace"] unless backtrace
|
30
|
-
|
31
|
-
new_backtrace = []
|
32
|
-
backtrace.each_with_index do |line, index|
|
33
|
-
break if line.rindex(MICRONAUT_DIR, 0)
|
34
|
-
new_backtrace << line
|
35
|
-
end
|
36
|
-
|
37
|
-
new_backtrace = backtrace.reject { |line| line.rindex(MICRONAUT_DIR, 0) } if new_backtrace.empty?
|
38
|
-
new_backtrace = backtrace.dup if new_backtrace.empty?
|
39
|
-
new_backtrace
|
40
|
-
end
|
41
27
|
|
42
28
|
end
|
@@ -4,44 +4,62 @@ module Micronaut
|
|
4
4
|
include Micronaut::Matchers
|
5
5
|
include Micronaut::Mocking::WithMocha
|
6
6
|
|
7
|
+
def eval_before_alls
|
8
|
+
self.class.each_ancestor do |ancestor|
|
9
|
+
ancestor.before_alls.each { |blk| instance_eval(&blk) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def eval_after_alls
|
14
|
+
self.class.each_ancestor(:superclass_first) do |ancestor|
|
15
|
+
ancestor.after_alls.each { |blk| instance_eval(&blk) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def eval_before_eachs
|
20
|
+
self.class.each_ancestor do |ancestor|
|
21
|
+
ancestor.before_eachs.each { |blk| instance_eval(&blk) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def eval_after_eachs
|
26
|
+
self.class.each_ancestor(:superclass_first) do |ancestor|
|
27
|
+
ancestor.after_eachs.each { |blk| instance_eval(&blk) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
7
31
|
def execute(reporter)
|
8
32
|
return true if self.class.examples.empty?
|
9
|
-
|
10
|
-
|
33
|
+
eval_before_alls
|
11
34
|
success = true
|
12
|
-
|
35
|
+
|
13
36
|
self.class.examples.each do |desc, opts, block|
|
14
|
-
execution_error = nil
|
15
37
|
reporter.example_started(self)
|
16
|
-
|
38
|
+
|
39
|
+
execution_error = nil
|
17
40
|
begin
|
18
41
|
setup_mocks
|
19
|
-
|
42
|
+
eval_before_eachs
|
20
43
|
if block
|
21
44
|
instance_eval(&block)
|
45
|
+
verify_mocks
|
22
46
|
reporter.example_passed(self)
|
23
47
|
else
|
24
48
|
reporter.example_pending([desc, self], 'Not yet implemented')
|
25
49
|
end
|
26
|
-
|
50
|
+
eval_after_eachs
|
27
51
|
rescue Exception => e
|
28
52
|
reporter.example_failed(self, e)
|
29
53
|
execution_error ||= e
|
30
54
|
ensure
|
31
55
|
teardown_mocks
|
32
56
|
end
|
33
|
-
|
34
|
-
begin
|
35
|
-
self.class.afters[:each].each { |ae| instance_eval(&ae) }
|
36
|
-
rescue Exception => e
|
37
|
-
execution_error ||= e
|
38
|
-
end
|
39
|
-
|
57
|
+
|
40
58
|
success &= execution_error.nil?
|
41
59
|
end
|
42
|
-
|
60
|
+
eval_after_alls
|
43
61
|
success
|
44
62
|
end
|
45
|
-
|
63
|
+
|
46
64
|
end
|
47
65
|
end
|