spicycode-micronaut 0.1.4.2 → 0.1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/bin/micronaut +1 -1
- data/examples/example_helper.rb +8 -3
- data/examples/lib/micronaut/behaviour_example.rb +15 -28
- data/examples/lib/micronaut/configuration_example.rb +3 -2
- data/examples/lib/micronaut/formatters/progress_formatter_example.rb +10 -21
- data/examples/lib/micronaut/matchers/has_example.rb +2 -4
- data/examples/lib/micronaut/matchers/throw_symbol_example.rb +120 -91
- data/examples/lib/micronaut/world_example.rb +0 -7
- data/lib/autotest/micronaut.rb +2 -6
- data/lib/micronaut/behaviour.rb +2 -2
- data/lib/micronaut/configuration.rb +7 -7
- data/lib/micronaut/formatters/base_formatter.rb +33 -0
- data/lib/micronaut/formatters/base_text_formatter.rb +3 -32
- data/lib/micronaut/formatters/documentation_formatter.rb +4 -3
- data/lib/micronaut/runner.rb +8 -15
- data/lib/micronaut/world.rb +32 -34
- metadata +2 -2
data/Rakefile
CHANGED
data/bin/micronaut
CHANGED
data/examples/example_helper.rb
CHANGED
@@ -2,6 +2,7 @@ lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
2
2
|
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
3
3
|
|
4
4
|
require 'micronaut'
|
5
|
+
require 'rubygems'
|
5
6
|
gem :mocha
|
6
7
|
require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
|
7
8
|
|
@@ -27,11 +28,15 @@ def dummy_reporter
|
|
27
28
|
DummyFormatter.new({}, StringIO.new)
|
28
29
|
end
|
29
30
|
|
31
|
+
def use_color?
|
32
|
+
!ENV.has_key?('TM_MODE')
|
33
|
+
end
|
34
|
+
|
30
35
|
Micronaut.configure do |config|
|
31
36
|
config.mock_with :mocha
|
32
|
-
config.color_enabled =
|
37
|
+
config.color_enabled = use_color?
|
33
38
|
config.formatter = :progress
|
34
|
-
config.profile_examples =
|
35
|
-
config.
|
39
|
+
config.profile_examples = false
|
40
|
+
config.filter_run :options => { :focused => true, :using_mocks => true }
|
36
41
|
config.autorun!
|
37
42
|
end
|
@@ -2,12 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
|
|
2
2
|
|
3
3
|
describe Micronaut::Behaviour do
|
4
4
|
|
5
|
-
class Foo
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
5
|
def empty_behaviour_group
|
10
|
-
group = Micronaut::Behaviour.describe(
|
6
|
+
group = Micronaut::Behaviour.describe(Object, 'Empty Behaviour Group') { }
|
11
7
|
remove_last_describe_from_world
|
12
8
|
end
|
13
9
|
|
@@ -28,7 +24,7 @@ describe Micronaut::Behaviour do
|
|
28
24
|
end
|
29
25
|
|
30
26
|
it "should call to_s on the first parameter in case it is a constant" do
|
31
|
-
Micronaut::Behaviour.describe(
|
27
|
+
Micronaut::Behaviour.describe(Object) { }.name.should == 'Object'
|
32
28
|
end
|
33
29
|
|
34
30
|
end
|
@@ -36,7 +32,7 @@ describe Micronaut::Behaviour do
|
|
36
32
|
describe '#described_type' do
|
37
33
|
|
38
34
|
it "should be the first parameter when it is a constant" do
|
39
|
-
Micronaut::Behaviour.describe(
|
35
|
+
Micronaut::Behaviour.describe(Object) { }.described_type.should == Object
|
40
36
|
end
|
41
37
|
|
42
38
|
it "should be nil when the first parameter is a string" do
|
@@ -48,11 +44,11 @@ describe Micronaut::Behaviour do
|
|
48
44
|
describe '#description' do
|
49
45
|
|
50
46
|
it "should expose the second parameter as description" do
|
51
|
-
Micronaut::Behaviour.describe(
|
47
|
+
Micronaut::Behaviour.describe(Object, "my desc") { }.description.should == 'my desc'
|
52
48
|
end
|
53
49
|
|
54
50
|
it "should allow the second parameter to be nil" do
|
55
|
-
Micronaut::Behaviour.describe(
|
51
|
+
Micronaut::Behaviour.describe(Object, nil) { }.description.size.should == 0
|
56
52
|
end
|
57
53
|
|
58
54
|
end
|
@@ -60,11 +56,11 @@ describe Micronaut::Behaviour do
|
|
60
56
|
describe '#options' do
|
61
57
|
|
62
58
|
it "should expose the third parameter as options" do
|
63
|
-
Micronaut::Behaviour.describe(
|
59
|
+
Micronaut::Behaviour.describe(Object, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
|
64
60
|
end
|
65
61
|
|
66
62
|
it "should be an empty hash if no options are supplied" do
|
67
|
-
Micronaut::Behaviour.describe(
|
63
|
+
Micronaut::Behaviour.describe(Object, nil) { }.options.should == {}
|
68
64
|
end
|
69
65
|
|
70
66
|
end
|
@@ -171,29 +167,20 @@ describe Micronaut::Behaviour do
|
|
171
167
|
|
172
168
|
end
|
173
169
|
|
174
|
-
describe
|
175
|
-
|
176
|
-
before { "before_each_1" }
|
177
|
-
before(:all) { "before_all_1" }
|
178
|
-
after { "after_each_1" }
|
179
|
-
after(:all) { "after_all_1" }
|
170
|
+
describe Object, "describing nested behaviours" do
|
180
171
|
|
181
|
-
describe "nested
|
172
|
+
describe "A sample nested describe", :just_testing => 'yep' do
|
182
173
|
|
183
|
-
it "should set the described type to the
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should set the description to the first parameter if no described type is given" do
|
188
|
-
self.class.description.should == 'nested describes'
|
174
|
+
it "should set the described type to the constant Object" do
|
175
|
+
running_example.behaviour.described_type.should == Object
|
189
176
|
end
|
190
177
|
|
191
|
-
it "should set the
|
192
|
-
|
178
|
+
it "should set the description to 'A sample nested describe'" do
|
179
|
+
running_example.behaviour.description.should == 'A sample nested describe'
|
193
180
|
end
|
194
181
|
|
195
|
-
it "should have
|
196
|
-
|
182
|
+
it "should have :just_testing => 'yep' in the options" do
|
183
|
+
running_example.behaviour.options.should include(:just_testing => 'yep')
|
197
184
|
end
|
198
185
|
|
199
186
|
end
|
@@ -4,8 +4,9 @@ describe Micronaut::Configuration do
|
|
4
4
|
|
5
5
|
describe "#mock_with" do
|
6
6
|
|
7
|
-
it "should include the mocha adapter when called with :mocha" do
|
8
|
-
Micronaut
|
7
|
+
it "should require and include the mocha adapter when called with :mocha" do
|
8
|
+
Micronaut.configuration.expects(:require).with('micronaut/mocking/with_mocha')
|
9
|
+
Micronaut::Behaviour.expects(:send)
|
9
10
|
Micronaut.configuration.mock_with :mocha
|
10
11
|
end
|
11
12
|
|
@@ -7,29 +7,23 @@ describe Micronaut::Formatters::ProgressFormatter do
|
|
7
7
|
@formatter = Micronaut::Formatters::ProgressFormatter.new
|
8
8
|
@formatter.stubs(:color_enabled?).returns(false)
|
9
9
|
@formatter.stubs(:output).returns(@output)
|
10
|
-
@original_profile_setting = Micronaut.configuration.profile_examples
|
11
10
|
end
|
12
11
|
|
13
12
|
it "should produce line break on start dump" do
|
14
13
|
@formatter.start_dump
|
15
|
-
@output.string.should
|
14
|
+
@output.string.should == "\n"
|
16
15
|
end
|
17
16
|
|
18
17
|
it "should produce standard summary without pending when pending has a 0 count" do
|
19
18
|
@formatter.dump_summary(3, 2, 1, 0)
|
20
|
-
@output.string.should =~
|
19
|
+
@output.string.should =~ /Finished in 3 seconds\n2 examples, 1 failures/i
|
21
20
|
end
|
22
21
|
|
23
22
|
it "should produce standard summary" do
|
24
|
-
|
25
|
-
it('example') {}
|
26
|
-
end
|
27
|
-
remove_last_describe_from_world
|
28
|
-
example = behaviour.examples.first
|
29
|
-
@formatter.example_pending(example, "message")
|
23
|
+
@formatter.example_pending(running_example, "message")
|
30
24
|
@output.rewind
|
31
25
|
@formatter.dump_summary(3, 2, 1, 1)
|
32
|
-
@output.string.should =~
|
26
|
+
@output.string.should =~ /Finished in 3 seconds\n2 examples, 1 failures, 1 pending/i
|
33
27
|
end
|
34
28
|
|
35
29
|
describe "when color is enabled" do
|
@@ -38,39 +32,34 @@ describe Micronaut::Formatters::ProgressFormatter do
|
|
38
32
|
@formatter.stubs(:color_enabled?).returns(true)
|
39
33
|
end
|
40
34
|
|
41
|
-
it "should
|
42
|
-
@formatter.color_enabled?.should == true
|
35
|
+
it "should output a green dot for passing spec" do
|
43
36
|
@formatter.example_passed("spec")
|
44
37
|
@output.string.should == "\e[32m.\e[0m"
|
45
38
|
end
|
46
39
|
|
47
40
|
it "should push red F for failure spec" do
|
48
41
|
@formatter.example_failed("spec", Micronaut::Expectations::ExpectationNotMetError.new)
|
49
|
-
@output.string.should
|
42
|
+
@output.string.should == "\e[31mF\e[0m"
|
50
43
|
end
|
51
44
|
|
52
45
|
it "should push magenta F for error spec" do
|
53
46
|
@formatter.example_failed("spec", RuntimeError.new)
|
54
|
-
@output.string.should
|
47
|
+
@output.string.should == "\e[35mF\e[0m"
|
55
48
|
end
|
56
49
|
|
57
50
|
end
|
58
51
|
|
59
52
|
it "should push nothing on start" do
|
60
53
|
@formatter.start(4)
|
61
|
-
@output.string.should
|
54
|
+
@output.string.should == ""
|
62
55
|
end
|
63
56
|
|
64
57
|
it "should ensure two ':' in the first backtrace" do
|
65
58
|
backtrace = ["/tmp/x.rb:1", "/tmp/x.rb:2", "/tmp/x.rb:3"]
|
66
|
-
@formatter.format_backtrace(backtrace).should
|
67
|
-
/tmp/x.rb:1
|
68
|
-
EOE
|
59
|
+
@formatter.format_backtrace(backtrace).should == "/tmp/x.rb:1"
|
69
60
|
|
70
61
|
backtrace = ["/tmp/x.rb:1: message", "/tmp/x.rb:2", "/tmp/x.rb:3"]
|
71
|
-
@formatter.format_backtrace(backtrace).should
|
72
|
-
/tmp/x.rb:1: message
|
73
|
-
EOE
|
62
|
+
@formatter.format_backtrace(backtrace).should == "/tmp/x.rb:1: message"
|
74
63
|
end
|
75
64
|
|
76
65
|
end
|
@@ -15,12 +15,10 @@ describe Micronaut::Matchers do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should fail if target does not respond to #has_sym?" do
|
18
|
-
lambda {
|
19
|
-
Object.new.should have_key(:a)
|
20
|
-
}.should raise_error(NoMethodError)
|
18
|
+
lambda { Object.new.should have_key(:a) }.should raise_error(NoMethodError)
|
21
19
|
end
|
22
20
|
|
23
|
-
it "should
|
21
|
+
it "should re-raise an exception thrown in #has_sym?(*args)" do
|
24
22
|
o = Object.new
|
25
23
|
def o.has_sym?(*args)
|
26
24
|
raise "Funky exception"
|
@@ -1,96 +1,125 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
3
|
+
describe Micronaut::Matchers::ThrowSymbol do
|
4
|
+
|
5
|
+
describe "with no args" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@matcher = Micronaut::Matchers::ThrowSymbol.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should match if any Symbol is thrown" do
|
12
|
+
@matcher.matches?(lambda{ throw :sym }).should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should match if any Symbol is thrown with an arg" do
|
16
|
+
@matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not match if no Symbol is thrown" do
|
20
|
+
@matcher.matches?(lambda{ }).should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should provide a failure message" do
|
24
|
+
@matcher.matches?(lambda{})
|
25
|
+
@matcher.failure_message.should == "expected a Symbol but nothing was thrown"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should provide a negative failure message" do
|
29
|
+
@matcher.matches?(lambda{ throw :sym})
|
30
|
+
@matcher.negative_failure_message.should == "expected no Symbol, got :sym"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "with a symbol" do
|
36
|
+
|
37
|
+
before do
|
38
|
+
@matcher = Micronaut::Matchers::ThrowSymbol.new(:sym)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should match if correct Symbol is thrown" do
|
42
|
+
@matcher.matches?(lambda{ throw :sym }).should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should match if correct Symbol is thrown with an arg" do
|
46
|
+
@matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not match if no Symbol is thrown" do
|
50
|
+
@matcher.matches?(lambda{ }).should be_false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not match if correct Symbol is thrown" do
|
54
|
+
@matcher.matches?(lambda{ throw :other_sym }).should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should provide a failure message when no Symbol is thrown" do
|
58
|
+
@matcher.matches?(lambda{})
|
59
|
+
@matcher.failure_message.should == "expected :sym but nothing was thrown"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should provide a failure message when wrong Symbol is thrown" do
|
63
|
+
@matcher.matches?(lambda{ throw :other_sym })
|
64
|
+
@matcher.failure_message.should == "expected :sym, got :other_sym"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should provide a negative failure message" do
|
68
|
+
@matcher.matches?(lambda{ throw :sym })
|
69
|
+
@matcher.negative_failure_message.should == "expected :sym not to be thrown"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should only match NameErrors raised by uncaught throws" do
|
73
|
+
@matcher.matches?(lambda{ sym }).should be_false
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "with a symbol and an arg" do
|
62
79
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
it "should provide a failure message when no Symbol is thrown" do
|
79
|
-
@matcher.matches?(lambda{})
|
80
|
-
@matcher.failure_message.should == %q[expected :sym with "a" but nothing was thrown]
|
81
|
-
end
|
82
|
-
it "should provide a failure message when wrong Symbol is thrown" do
|
83
|
-
@matcher.matches?(lambda{ throw :other_sym })
|
84
|
-
@matcher.failure_message.should == %q[expected :sym with "a", got :other_sym]
|
85
|
-
end
|
86
|
-
it "should provide a negative failure message" do
|
87
|
-
@matcher.matches?(lambda{ throw :sym })
|
88
|
-
@matcher.negative_failure_message.should == %q[expected :sym with "a" not to be thrown]
|
89
|
-
end
|
90
|
-
it "should only match NameErrors raised by uncaught throws" do
|
91
|
-
@matcher.matches?(lambda{ sym }).should be_false
|
92
|
-
end
|
93
|
-
end
|
80
|
+
before do
|
81
|
+
@matcher = Micronaut::Matchers::ThrowSymbol.new(:sym, "a")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should match if correct Symbol and args are thrown" do
|
85
|
+
@matcher.matches?(lambda{ throw :sym, "a" }).should be_true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should not match if nothing is thrown" do
|
89
|
+
@matcher.matches?(lambda{ }).should be_false
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should not match if other Symbol is thrown" do
|
93
|
+
@matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
|
94
94
|
end
|
95
|
+
|
96
|
+
it "should not match if no arg is thrown" do
|
97
|
+
@matcher.matches?(lambda{ throw :sym }).should be_false
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not match if wrong arg is thrown" do
|
101
|
+
@matcher.matches?(lambda{ throw :sym, "b" }).should be_false
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should provide a failure message when no Symbol is thrown" do
|
105
|
+
@matcher.matches?(lambda{})
|
106
|
+
@matcher.failure_message.should == %q[expected :sym with "a" but nothing was thrown]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should provide a failure message when wrong Symbol is thrown" do
|
110
|
+
@matcher.matches?(lambda{ throw :other_sym })
|
111
|
+
@matcher.failure_message.should == %q[expected :sym with "a", got :other_sym]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should provide a negative failure message" do
|
115
|
+
@matcher.matches?(lambda{ throw :sym })
|
116
|
+
@matcher.negative_failure_message.should == %q[expected :sym with "a" not to be thrown]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should only match NameErrors raised by uncaught throws" do
|
120
|
+
@matcher.matches?(lambda{ sym }).should be_false
|
121
|
+
end
|
122
|
+
|
95
123
|
end
|
96
|
-
|
124
|
+
|
125
|
+
end
|
@@ -90,13 +90,6 @@ describe Micronaut::World do
|
|
90
90
|
|
91
91
|
describe '#filter_behaviours' do
|
92
92
|
|
93
|
-
it "should return immediately if there are no filters" do
|
94
|
-
filters = stub('filters', :any? => false)
|
95
|
-
filters.expects(:each).never
|
96
|
-
Micronaut.configuration.stubs(:filters).returns(filters)
|
97
|
-
Micronaut.world.filter_behaviours
|
98
|
-
end
|
99
|
-
|
100
93
|
end
|
101
94
|
|
102
95
|
end
|
data/lib/autotest/micronaut.rb
CHANGED
@@ -38,12 +38,8 @@ class Autotest::Micronaut < Autotest
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def make_test_cmd(files_to_test)
|
41
|
-
return '' if files_to_test.
|
42
|
-
|
43
|
-
examples = files_to_test.keys.flatten
|
44
|
-
|
45
|
-
|
46
|
-
"#{ruby} #{examples.join(" ")}"
|
41
|
+
return '' if files_to_test.size == 0
|
42
|
+
"bin/micronaut #{files_to_test.keys.join(' ')}"
|
47
43
|
end
|
48
44
|
|
49
45
|
end
|
data/lib/micronaut/behaviour.rb
CHANGED
@@ -158,7 +158,7 @@ module Micronaut
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def self.run(reporter)
|
161
|
-
return true if
|
161
|
+
return true if examples.size == 0
|
162
162
|
|
163
163
|
reporter.add_behaviour(self)
|
164
164
|
|
@@ -166,7 +166,7 @@ module Micronaut
|
|
166
166
|
eval_before_alls(group)
|
167
167
|
success = true
|
168
168
|
|
169
|
-
|
169
|
+
examples.each do |ex|
|
170
170
|
group.running_example = ex
|
171
171
|
reporter.example_started(ex)
|
172
172
|
|
@@ -11,8 +11,8 @@ module Micronaut
|
|
11
11
|
# An array of arrays to store before and after blocks
|
12
12
|
attr_reader :before_and_afters
|
13
13
|
|
14
|
-
#
|
15
|
-
attr_reader :
|
14
|
+
# Adding a filter allows you to exclude or include certain examples from running based on options you pass in
|
15
|
+
attr_reader :filter
|
16
16
|
|
17
17
|
# When this is true, if you have filters enabled and no examples match,
|
18
18
|
# all examples are added and run - defaults to true
|
@@ -26,7 +26,7 @@ module Micronaut
|
|
26
26
|
@backtrace_clean_patterns = [/\/lib\/ruby\//, /bin\/rcov:/, /vendor\/rails/]
|
27
27
|
@profile_examples = false
|
28
28
|
@run_all_when_everything_filtered = true
|
29
|
-
@
|
29
|
+
@filter = nil
|
30
30
|
@before_and_afters = []
|
31
31
|
end
|
32
32
|
|
@@ -54,13 +54,13 @@ module Micronaut
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def autorun!
|
57
|
-
Micronaut::Runner.autorun
|
57
|
+
Micronaut::Runner.autorun
|
58
58
|
end
|
59
59
|
|
60
60
|
# Determines whether or not any output should include ANSI color codes,
|
61
61
|
# defaults to true
|
62
62
|
def color_enabled?
|
63
|
-
@color_enabled
|
63
|
+
@color_enabled
|
64
64
|
end
|
65
65
|
|
66
66
|
def color_enabled=(on_or_off)
|
@@ -114,8 +114,8 @@ module Micronaut
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
def
|
118
|
-
|
117
|
+
def filter_run(options={})
|
118
|
+
@filter = options
|
119
119
|
end
|
120
120
|
|
121
121
|
def run_all_when_everything_filtered?
|
@@ -31,6 +31,18 @@ module Micronaut
|
|
31
31
|
def total_example_pending
|
32
32
|
@total_example_pending
|
33
33
|
end
|
34
|
+
|
35
|
+
def example_profiling_info
|
36
|
+
@example_profiling_info ||= []
|
37
|
+
end
|
38
|
+
|
39
|
+
def pending_examples
|
40
|
+
@pending_examples ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
def failed_examples
|
44
|
+
@failed_examples ||= []
|
45
|
+
end
|
34
46
|
|
35
47
|
# This method is invoked before any examples are run, right after
|
36
48
|
# they have all been collected. This can be useful for special
|
@@ -95,6 +107,27 @@ module Micronaut
|
|
95
107
|
# This method is invoked at the very end. Allows the formatter to clean up, like closing open streams.
|
96
108
|
def close
|
97
109
|
end
|
110
|
+
|
111
|
+
def format_backtrace(backtrace)
|
112
|
+
return "" if backtrace.nil?
|
113
|
+
cleansed = backtrace.map { |line| backtrace_line(line) }.compact
|
114
|
+
cleansed.empty? ? backtrace.join("\n") : cleansed.first
|
115
|
+
end
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
def backtrace_line(line)
|
120
|
+
return nil if configuration.cleaned_from_backtrace?(line)
|
121
|
+
line.sub!(/\A([^:]+:\d+)$/, '\\1')
|
122
|
+
return nil if line == '-e:1'
|
123
|
+
line
|
124
|
+
end
|
125
|
+
|
126
|
+
def read_failed_line(file_path_with_line_number)
|
127
|
+
file_path, line_number = file_path_with_line_number.split(':')
|
128
|
+
open(file_path, 'r') { |f| f.readlines[line_number.to_i + 1].strip }
|
129
|
+
end
|
130
|
+
|
98
131
|
end
|
99
132
|
|
100
133
|
end
|
@@ -3,18 +3,6 @@ module Micronaut
|
|
3
3
|
module Formatters
|
4
4
|
|
5
5
|
class BaseTextFormatter < BaseFormatter
|
6
|
-
|
7
|
-
def example_profiling_info
|
8
|
-
@example_profiling_info ||= []
|
9
|
-
end
|
10
|
-
|
11
|
-
def pending_examples
|
12
|
-
@pending_examples ||= []
|
13
|
-
end
|
14
|
-
|
15
|
-
def failed_examples
|
16
|
-
@failed_examples ||= []
|
17
|
-
end
|
18
6
|
|
19
7
|
def example_passed(example)
|
20
8
|
super
|
@@ -50,11 +38,6 @@ module Micronaut
|
|
50
38
|
output.flush
|
51
39
|
end
|
52
40
|
end
|
53
|
-
|
54
|
-
def read_failed_line(file_path_with_line_number)
|
55
|
-
file_path, line_number = file_path_with_line_number.split(':')
|
56
|
-
open(file_path, 'r') { |f| f.readlines[line_number.to_i + 1].strip }
|
57
|
-
end
|
58
41
|
|
59
42
|
def colorise(s, failure)
|
60
43
|
if failure.is_a?(Micronaut::Expectations::ExpectationNotMetError)
|
@@ -80,8 +63,9 @@ module Micronaut
|
|
80
63
|
output.puts red(summary)
|
81
64
|
end
|
82
65
|
|
83
|
-
if
|
84
|
-
|
66
|
+
# Don't print out profiled info if there are failures, it just clutters the output
|
67
|
+
if profile_examples? && failure_count == 0
|
68
|
+
sorted_examples = example_profiling_info.sort_by { |desc, time| time }.last(10)
|
85
69
|
output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
|
86
70
|
sorted_examples.reverse.each do |desc, time|
|
87
71
|
output.puts " (#{sprintf("%.7f", time)} seconds) #{desc}"
|
@@ -115,21 +99,8 @@ module Micronaut
|
|
115
99
|
end
|
116
100
|
end
|
117
101
|
|
118
|
-
def format_backtrace(backtrace)
|
119
|
-
return "" if backtrace.nil?
|
120
|
-
cleansed = backtrace.map { |line| backtrace_line(line) }.compact
|
121
|
-
cleansed.empty? ? backtrace.join("\n") : cleansed.first
|
122
|
-
end
|
123
|
-
|
124
102
|
protected
|
125
103
|
|
126
|
-
def backtrace_line(line)
|
127
|
-
return nil if Micronaut.configuration.cleaned_from_backtrace?(line)
|
128
|
-
line.sub!(/\A([^:]+:\d+)$/, '\\1')
|
129
|
-
return nil if line == '-e:1'
|
130
|
-
line
|
131
|
-
end
|
132
|
-
|
133
104
|
def color(text, color_code)
|
134
105
|
return text unless color_enabled?
|
135
106
|
"#{color_code}#{text}\e[0m"
|
@@ -5,7 +5,7 @@ module Micronaut
|
|
5
5
|
|
6
6
|
attr_reader :previous_nested_behaviours
|
7
7
|
|
8
|
-
def initialize
|
8
|
+
def initialize
|
9
9
|
super
|
10
10
|
@previous_nested_behaviours = []
|
11
11
|
end
|
@@ -33,11 +33,12 @@ module Micronaut
|
|
33
33
|
"#{current_indentation}#{example.description} (ERROR)"
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
output.puts(expectation_not_met ? red(message) : magenta(message))
|
37
|
+
output.flush
|
38
38
|
end
|
39
39
|
|
40
40
|
def example_passed(example)
|
41
|
+
super
|
41
42
|
output.puts green("#{current_indentation}#{example.description}")
|
42
43
|
output.flush
|
43
44
|
end
|
data/lib/micronaut/runner.rb
CHANGED
@@ -18,31 +18,24 @@ module Micronaut
|
|
18
18
|
def formatter
|
19
19
|
Micronaut.configuration.formatter
|
20
20
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def load_all_behaviours(files_from_args=[])
|
25
|
-
# TODO: Make this horrid looking line more readable by at least some humans
|
26
|
-
files_from_args.inject([]) { |files, arg| files.concat(Dir[arg].map { |g| Dir.glob(g) }.flatten) }.each do |file|
|
27
|
-
load file
|
28
|
-
end
|
21
|
+
|
22
|
+
def require_all_behaviours(files_from_args=[])
|
23
|
+
files_from_args.each { |file| require file }
|
29
24
|
end
|
30
25
|
|
31
26
|
def run(args = [])
|
32
|
-
|
27
|
+
require_all_behaviours(args)
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
total_examples = behaviours_to_run.inject(0) { |sum, b| sum + b.examples_to_run.size }
|
29
|
+
total_examples_to_run = Micronaut.world.total_examples_to_run
|
37
30
|
|
38
31
|
old_sync, formatter.output.sync = formatter.output.sync, true if formatter.output.respond_to?(:sync=)
|
39
32
|
|
40
|
-
formatter.start(
|
33
|
+
formatter.start(total_examples_to_run)
|
41
34
|
|
42
35
|
suite_success = true
|
43
36
|
|
44
37
|
starts_at = Time.now
|
45
|
-
behaviours_to_run.each do |behaviour|
|
38
|
+
Micronaut.world.behaviours_to_run.each do |behaviour|
|
46
39
|
suite_success &= behaviour.run(formatter)
|
47
40
|
end
|
48
41
|
duration = Time.now - starts_at
|
@@ -50,7 +43,7 @@ module Micronaut
|
|
50
43
|
formatter.start_dump
|
51
44
|
formatter.dump_failures
|
52
45
|
# TODO: Stop passing in the last two items, the formatter knows this info
|
53
|
-
formatter.dump_summary(duration,
|
46
|
+
formatter.dump_summary(duration, total_examples_to_run, formatter.failed_examples.size, formatter.pending_examples.size)
|
54
47
|
formatter.dump_pending
|
55
48
|
|
56
49
|
formatter.output.sync = old_sync if formatter.output.respond_to? :sync=
|
data/lib/micronaut/world.rb
CHANGED
@@ -1,47 +1,45 @@
|
|
1
1
|
module Micronaut
|
2
2
|
|
3
3
|
class World
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
attr_reader :behaviours
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@behaviours = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def filter
|
12
|
+
Micronaut.configuration.filter
|
7
13
|
end
|
8
14
|
|
9
15
|
def behaviours_to_run
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
puts "Filters matched no specs - your world is empty, desolate, and alone."
|
16
|
+
return @behaviours_to_run if @behaviours_to_run
|
17
|
+
|
18
|
+
if filter
|
19
|
+
@behaviours_to_run = filter_behaviours
|
20
|
+
puts "\nRun filtered using #{filter.inspect}"
|
21
|
+
if @behaviours_to_run.size == 0 && Micronaut.configuration.run_all_when_everything_filtered?
|
22
|
+
puts "No behaviours where matched, running all"
|
23
|
+
# reset the behaviour list to all behaviours, and add back all examples
|
24
|
+
@behaviours_to_run = @behaviours
|
25
|
+
@behaviours.each { |b| b.examples_to_run.replace(b.examples) }
|
21
26
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def sum_behaviours
|
28
|
-
behaviours.inject(0) { |sum, b| sum += b.examples_to_run.size }
|
27
|
+
else
|
28
|
+
@behaviours_to_run = @behaviours
|
29
|
+
end
|
30
|
+
|
31
|
+
@behaviours_to_run
|
29
32
|
end
|
30
|
-
|
31
|
-
def
|
32
|
-
|
33
|
-
behaviour.examples_to_run.concat(behaviour.examples)
|
34
|
-
end
|
33
|
+
|
34
|
+
def total_examples_to_run
|
35
|
+
@total_examples_to_run ||= behaviours_to_run.inject(0) { |sum, b| sum += b.examples_to_run.size }
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
def filter_behaviours
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
behaviours
|
39
|
+
behaviours.inject([]) do |list, b|
|
40
|
+
b.examples_to_run.replace(find(b.examples, filter))
|
41
|
+
list << (b.examples_to_run.size == 0 ? nil : b)
|
42
|
+
end.compact
|
45
43
|
end
|
46
44
|
|
47
45
|
def find(collection, conditions={})
|
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.1.4.
|
4
|
+
version: 0.1.4.3
|
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-
|
12
|
+
date: 2008-12-20 00:00:00 -08:00
|
13
13
|
default_executable: micronaut
|
14
14
|
dependencies: []
|
15
15
|
|