spicycode-micronaut 0.1.4.1 → 0.1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +11 -2
- data/examples/example_helper.rb +4 -3
- data/examples/lib/micronaut/behaviour_example.rb +13 -4
- data/examples/lib/micronaut/configuration_example.rb +3 -3
- data/examples/lib/micronaut/example_example.rb +5 -3
- data/examples/lib/micronaut/formatters/base_formatter_example.rb +1 -1
- data/examples/lib/micronaut/formatters/progress_formatter_example.rb +31 -25
- data/examples/lib/micronaut/world_example.rb +26 -39
- data/examples/lib/micronaut_example.rb +16 -0
- data/lib/autotest/micronaut.rb +2 -0
- data/lib/micronaut.rb +4 -1
- data/lib/micronaut/behaviour.rb +6 -2
- data/lib/micronaut/configuration.rb +28 -8
- data/lib/micronaut/formatters/base_formatter.rb +24 -5
- data/lib/micronaut/formatters/base_text_formatter.rb +48 -43
- data/lib/micronaut/formatters/progress_formatter.rb +8 -8
- data/lib/micronaut/runner.rb +20 -13
- data/lib/micronaut/world.rb +10 -17
- metadata +2 -4
- data/examples/lib/micronaut/runner_options_example.rb +0 -5
- data/lib/micronaut/runner_options.rb +0 -33
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
|
|
3
3
|
require 'rubygems/specification'
|
4
4
|
|
5
5
|
GEM = "micronaut"
|
6
|
-
GEM_VERSION = "0.1.4.
|
6
|
+
GEM_VERSION = "0.1.4.2"
|
7
7
|
AUTHOR = "Chad Humphries"
|
8
8
|
EMAIL = "chad@spicycode.com"
|
9
9
|
HOMEPAGE = "http://spicycode.com"
|
@@ -68,9 +68,18 @@ namespace :micronaut do
|
|
68
68
|
desc "Run all examples using rcov"
|
69
69
|
task :coverage do
|
70
70
|
examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
|
71
|
-
system "rcov --exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-
|
71
|
+
result = system "rcov --exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links #{examples.join(' ')}"
|
72
|
+
fail_build unless result
|
72
73
|
end
|
73
74
|
|
75
|
+
def fail_build
|
76
|
+
puts
|
77
|
+
puts "-" * 79
|
78
|
+
puts "Build Failed"
|
79
|
+
puts "-" * 79
|
80
|
+
abort
|
81
|
+
end
|
82
|
+
|
74
83
|
desc "Delete coverage artifacts"
|
75
84
|
task :clean_coverage do
|
76
85
|
rm_rf Dir["coverage/**/*"]
|
data/examples/example_helper.rb
CHANGED
@@ -18,7 +18,7 @@ module Micronaut
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def remove_last_describe_from_world
|
21
|
-
Micronaut
|
21
|
+
Micronaut.world.behaviours.pop
|
22
22
|
end
|
23
23
|
|
24
24
|
class DummyFormatter < Micronaut::Formatters::BaseTextFormatter; end
|
@@ -29,8 +29,9 @@ end
|
|
29
29
|
|
30
30
|
Micronaut.configure do |config|
|
31
31
|
config.mock_with :mocha
|
32
|
-
config.
|
33
|
-
config.
|
32
|
+
config.color_enabled = true
|
33
|
+
config.formatter = :progress
|
34
|
+
config.profile_examples = true
|
34
35
|
config.add_filter :options => { :focused => true }
|
35
36
|
config.autorun!
|
36
37
|
end
|
@@ -172,8 +172,13 @@ describe Micronaut::Behaviour do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
describe Foo, "describing nested behaviours" do
|
175
|
+
|
176
|
+
before { "before_each_1" }
|
177
|
+
before(:all) { "before_all_1" }
|
178
|
+
after { "after_each_1" }
|
179
|
+
after(:all) { "after_all_1" }
|
175
180
|
|
176
|
-
describe "nested describes" do
|
181
|
+
describe "nested describes", :just_testing => 'yep' do
|
177
182
|
|
178
183
|
it "should set the described type to the parent described type if no described type is given" do
|
179
184
|
self.class.described_type.should == Foo
|
@@ -182,10 +187,14 @@ describe Micronaut::Behaviour do
|
|
182
187
|
it "should set the description to the first parameter if no described type is given" do
|
183
188
|
self.class.description.should == 'nested describes'
|
184
189
|
end
|
185
|
-
|
186
|
-
it "should have access to all of it's ancestors before blocks"
|
187
190
|
|
188
|
-
it "should
|
191
|
+
it "should set the options to the last parameter if it is a hash" do
|
192
|
+
self.class.options.should include(:just_testing => 'yep')
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should have the caller in the options hash" do
|
196
|
+
self.class.options.should include(:caller)
|
197
|
+
end
|
189
198
|
|
190
199
|
end
|
191
200
|
|
@@ -46,9 +46,9 @@ describe Micronaut::Configuration do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should extend the given module into each behaviour group" do
|
49
|
-
Micronaut.configuration.extend(
|
50
|
-
group = Micronaut::Behaviour.describe(
|
51
|
-
group.should respond_to(:
|
49
|
+
Micronaut.configuration.extend(ThatThingISentYou)
|
50
|
+
group = Micronaut::Behaviour.describe(ThatThingISentYou, 'the focused support ') { }
|
51
|
+
group.should respond_to(:that_thing)
|
52
52
|
remove_last_describe_from_world
|
53
53
|
end
|
54
54
|
|
@@ -44,9 +44,11 @@ describe Micronaut::Example do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "accessing metadata within a running example" do
|
47
|
-
|
48
|
-
it "should
|
49
|
-
|
47
|
+
|
48
|
+
it "should have a reference to itself when running" do
|
49
|
+
running_example.description.should == "should have a reference to itself when running"
|
50
|
+
end
|
51
|
+
|
50
52
|
end
|
51
53
|
|
52
54
|
end
|
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
|
3
3
|
describe Micronaut::Formatters::BaseFormatter do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
-
@formatter = Micronaut::Formatters::BaseFormatter.new
|
6
|
+
@formatter = Micronaut::Formatters::BaseFormatter.new
|
7
7
|
end
|
8
8
|
|
9
9
|
class HaveInterfaceMatcher
|
@@ -3,21 +3,21 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
|
3
3
|
describe Micronaut::Formatters::ProgressFormatter do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@formatter
|
6
|
+
@output = StringIO.new
|
7
|
+
@formatter = Micronaut::Formatters::ProgressFormatter.new
|
8
|
+
@formatter.stubs(:color_enabled?).returns(false)
|
9
|
+
@formatter.stubs(:output).returns(@output)
|
10
10
|
@original_profile_setting = Micronaut.configuration.profile_examples
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should produce line break on start dump" do
|
14
14
|
@formatter.start_dump
|
15
|
-
@
|
15
|
+
@output.string.should eql("\n")
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should produce standard summary without pending when pending has a 0 count" do
|
19
19
|
@formatter.dump_summary(3, 2, 1, 0)
|
20
|
-
@
|
20
|
+
@output.string.should =~ /\nFinished in 3 seconds\n2 examples, 1 failures\n/i
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should produce standard summary" do
|
@@ -27,32 +27,38 @@ describe Micronaut::Formatters::ProgressFormatter do
|
|
27
27
|
remove_last_describe_from_world
|
28
28
|
example = behaviour.examples.first
|
29
29
|
@formatter.example_pending(example, "message")
|
30
|
-
@
|
30
|
+
@output.rewind
|
31
31
|
@formatter.dump_summary(3, 2, 1, 1)
|
32
|
-
@
|
32
|
+
@output.string.should =~ /\nFinished in 3 seconds\n2 examples, 1 failures, 1 pending\n/i
|
33
33
|
end
|
34
|
+
|
35
|
+
describe "when color is enabled" do
|
36
|
+
|
37
|
+
before do
|
38
|
+
@formatter.stubs(:color_enabled?).returns(true)
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
it "should push green dot for passing spec" do
|
42
|
+
@formatter.color_enabled?.should == true
|
43
|
+
@formatter.example_passed("spec")
|
44
|
+
@output.string.should == "\e[32m.\e[0m"
|
45
|
+
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
47
|
+
it "should push red F for failure spec" do
|
48
|
+
@formatter.example_failed("spec", Micronaut::Expectations::ExpectationNotMetError.new)
|
49
|
+
@output.string.should eql("\e[31mF\e[0m")
|
50
|
+
end
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
it "should push magenta F for error spec" do
|
53
|
+
@formatter.example_failed("spec", RuntimeError.new)
|
54
|
+
@output.string.should eql("\e[35mF\e[0m")
|
55
|
+
end
|
56
|
+
|
51
57
|
end
|
52
|
-
|
58
|
+
|
53
59
|
it "should push nothing on start" do
|
54
60
|
@formatter.start(4)
|
55
|
-
@
|
61
|
+
@output.string.should eql("")
|
56
62
|
end
|
57
63
|
|
58
64
|
it "should ensure two ':' in the first backtrace" do
|
@@ -64,7 +70,7 @@ EOE
|
|
64
70
|
backtrace = ["/tmp/x.rb:1: message", "/tmp/x.rb:2", "/tmp/x.rb:3"]
|
65
71
|
@formatter.format_backtrace(backtrace).should eql(<<-EOE.rstrip)
|
66
72
|
/tmp/x.rb:1: message
|
67
|
-
EOE
|
73
|
+
EOE
|
68
74
|
end
|
69
75
|
|
70
76
|
end
|
@@ -4,13 +4,17 @@ class Bar; end
|
|
4
4
|
class Foo; end
|
5
5
|
|
6
6
|
describe Micronaut::World do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@world = Micronaut::World.new
|
10
|
+
Micronaut.stubs(:world).returns(@world)
|
11
|
+
end
|
7
12
|
|
8
13
|
describe "behaviour groups" do
|
9
14
|
|
10
15
|
it "should contain all defined behaviour groups" do
|
11
16
|
behaviour_group = Micronaut::Behaviour.describe(Bar, 'Empty Behaviour Group') { }
|
12
|
-
|
13
|
-
remove_last_describe_from_world
|
17
|
+
@world.behaviours.should include(behaviour_group)
|
14
18
|
end
|
15
19
|
|
16
20
|
end
|
@@ -34,82 +38,65 @@ describe Micronaut::World do
|
|
34
38
|
@behaviours = [@bg1, @bg2, @bg3, @bg4]
|
35
39
|
end
|
36
40
|
|
37
|
-
after(:all) do
|
38
|
-
Micronaut::World.behaviours.delete(@bg1)
|
39
|
-
Micronaut::World.behaviours.delete(@bg2)
|
40
|
-
Micronaut::World.behaviours.delete(@bg3)
|
41
|
-
Micronaut::World.behaviours.delete(@bg4)
|
42
|
-
end
|
43
|
-
|
44
41
|
it "should find awesome examples" do
|
45
|
-
|
42
|
+
@world.find(@bg4.examples, :options => {:awesome => true}).should == [@bg4.examples[1], @bg4.examples[2]]
|
46
43
|
end
|
47
44
|
|
48
45
|
it "should find no groups when given no search parameters" do
|
49
|
-
|
46
|
+
@world.find([]).should == []
|
50
47
|
end
|
51
48
|
|
52
49
|
it "should find three groups when searching for :described_type => Bar" do
|
53
|
-
|
50
|
+
@world.find(@behaviours, :described_type => Bar).should == [@bg1, @bg2, @bg3]
|
54
51
|
end
|
55
52
|
|
56
53
|
it "should find one group when searching for :description => 'find group-1'" do
|
57
|
-
|
54
|
+
@world.find(@behaviours, :description => 'find group-1').should == [@bg1]
|
58
55
|
end
|
59
56
|
|
60
57
|
it "should find two groups when searching for :description => lambda { |v| v.include?('-1') || v.include?('-3') }" do
|
61
|
-
|
58
|
+
@world.find(@behaviours, :description => lambda { |v| v.include?('-1') || v.include?('-3') }).should == [@bg1, @bg3]
|
62
59
|
end
|
63
60
|
|
64
61
|
it "should find three groups when searching for :description => /find group/" do
|
65
|
-
|
62
|
+
@world.find(@behaviours, :description => /find group/).should == [@bg1, @bg2, @bg3]
|
66
63
|
end
|
67
64
|
|
68
65
|
it "should find one group when searching for :options => { :foo => 1 }" do
|
69
|
-
|
66
|
+
@world.find(@behaviours, :options => { :foo => 1 }).should == [@bg1]
|
70
67
|
end
|
71
68
|
|
72
69
|
it "should find one group when searching for :options => { :pending => true }" do
|
73
|
-
|
70
|
+
@world.find(@behaviours, :options => { :pending => true }).should == [@bg2]
|
74
71
|
end
|
75
72
|
|
76
73
|
it "should find one group when searching for :options => { :array => [1,2,3,4] }" do
|
77
|
-
|
74
|
+
@world.find(@behaviours, :options => { :array => [1,2,3,4] }).should == [@bg3]
|
78
75
|
end
|
79
76
|
|
80
77
|
it "should find no group when searching for :options => { :array => [4,3,2,1] }" do
|
81
|
-
|
78
|
+
@world.find(@behaviours, :options => { :array => [4,3,2,1] }).should be_empty
|
82
79
|
end
|
83
80
|
|
84
81
|
it "should find two groups when searching for :options => { :color => 'blue' }" do
|
85
|
-
|
82
|
+
@world.find(@behaviours, :options => { :color => 'blue' }).should == [@bg1, @bg3]
|
86
83
|
end
|
87
84
|
|
88
85
|
it "should find two groups when searching for :options => { :feature => 'reporting' }" do
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "reset" do
|
95
|
-
|
96
|
-
it "should clear the list of behaviour groups" do
|
97
|
-
original_groups = Micronaut::World.behaviours
|
98
|
-
|
99
|
-
Micronaut::World.behaviours.should_not be_empty
|
100
|
-
Micronaut::World.reset
|
101
|
-
Micronaut::World.behaviours.should be_empty
|
102
|
-
|
103
|
-
Micronaut::World.behaviours.concat(original_groups)
|
86
|
+
@world.find(@behaviours, :options => { :feature => 'reporting' }).should == [@bg1, @bg2]
|
104
87
|
end
|
105
88
|
|
106
89
|
end
|
107
90
|
|
108
|
-
describe
|
91
|
+
describe '#filter_behaviours' do
|
109
92
|
|
110
|
-
it "
|
111
|
-
|
112
|
-
|
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
|
+
|
113
100
|
end
|
114
101
|
|
115
102
|
end
|
@@ -20,4 +20,20 @@ describe Micronaut do
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
+
describe "world" do
|
24
|
+
|
25
|
+
it "should return the Micronaut::World instance the current run is using" do
|
26
|
+
Micronaut.world.should be_instance_of(Micronaut::World)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "InstallDirectory" do
|
32
|
+
|
33
|
+
it "should be the expanded version of the install directory" do
|
34
|
+
Micronaut::InstallDirectory.should == File.expand_path(File.dirname(__FILE__) + "/../../lib")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
23
39
|
end
|
data/lib/autotest/micronaut.rb
CHANGED
@@ -7,9 +7,11 @@ Autotest.add_hook :initialize do |at|
|
|
7
7
|
at.add_mapping(%r%^examples/.*_example.rb$%) { |filename, _|
|
8
8
|
filename
|
9
9
|
}
|
10
|
+
|
10
11
|
at.add_mapping(%r%^lib/(.*)\.rb$%) { |filename, m|
|
11
12
|
["examples/lib/#{m[1]}_example.rb"]
|
12
13
|
}
|
14
|
+
|
13
15
|
at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) {
|
14
16
|
at.files_matching %r%^examples/.*_example\.rb$%
|
15
17
|
}
|
data/lib/micronaut.rb
CHANGED
@@ -4,7 +4,6 @@ require 'micronaut/expectations'
|
|
4
4
|
require 'micronaut/world'
|
5
5
|
require 'micronaut/configuration'
|
6
6
|
require 'micronaut/runner'
|
7
|
-
require 'micronaut/runner_options'
|
8
7
|
require 'micronaut/example'
|
9
8
|
require 'micronaut/behaviour'
|
10
9
|
require 'micronaut/kernel_extensions'
|
@@ -34,4 +33,8 @@ module Micronaut
|
|
34
33
|
yield configuration
|
35
34
|
end
|
36
35
|
|
36
|
+
def self.world
|
37
|
+
@world ||= Micronaut::World.new
|
38
|
+
end
|
39
|
+
|
37
40
|
end
|
data/lib/micronaut/behaviour.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Micronaut
|
2
2
|
class Behaviour
|
3
3
|
include Micronaut::Matchers
|
4
|
-
|
4
|
+
|
5
|
+
attr_accessor :running_example
|
6
|
+
|
5
7
|
def self.inherited(klass)
|
6
8
|
super
|
7
|
-
Micronaut
|
9
|
+
Micronaut.world.behaviours << klass
|
8
10
|
end
|
9
11
|
|
10
12
|
def self.extended_modules #:nodoc:
|
@@ -165,6 +167,7 @@ module Micronaut
|
|
165
167
|
success = true
|
166
168
|
|
167
169
|
examples_to_run.each do |ex|
|
170
|
+
group.running_example = ex
|
168
171
|
reporter.example_started(ex)
|
169
172
|
|
170
173
|
execution_error = nil
|
@@ -190,6 +193,7 @@ module Micronaut
|
|
190
193
|
success &= execution_error.nil?
|
191
194
|
end
|
192
195
|
eval_after_alls(group)
|
196
|
+
group.running_example = nil
|
193
197
|
success
|
194
198
|
end
|
195
199
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Micronaut
|
2
2
|
|
3
3
|
class Configuration
|
4
|
-
#
|
4
|
+
# Desired mocking framework - expects the symbol name of the framework
|
5
5
|
# Currently supported: :mocha, :rr, or nothing (the default if this is not set at all)
|
6
6
|
attr_reader :mock_framework
|
7
7
|
|
@@ -14,12 +14,14 @@ module Micronaut
|
|
14
14
|
# Filters allow you to exclude or include certain examples from running based on options you pass in
|
15
15
|
attr_reader :filters
|
16
16
|
|
17
|
-
# When this is true, if you have filters enabled and no examples match,
|
17
|
+
# When this is true, if you have filters enabled and no examples match,
|
18
|
+
# all examples are added and run - defaults to true
|
18
19
|
attr_accessor :run_all_when_everything_filtered
|
19
20
|
|
20
21
|
# Enable profiling of the top 10 slowest examples - defaults to false
|
21
22
|
attr_accessor :profile_examples
|
22
23
|
|
24
|
+
|
23
25
|
def initialize
|
24
26
|
@backtrace_clean_patterns = [/\/lib\/ruby\//, /bin\/rcov:/, /vendor\/rails/]
|
25
27
|
@profile_examples = false
|
@@ -55,16 +57,34 @@ module Micronaut
|
|
55
57
|
Micronaut::Runner.autorun unless Micronaut::Runner.installed_at_exit?
|
56
58
|
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
# Determines whether or not any output should include ANSI color codes,
|
61
|
+
# defaults to true
|
62
|
+
def color_enabled?
|
63
|
+
@color_enabled || true
|
64
|
+
end
|
65
|
+
|
66
|
+
def color_enabled=(on_or_off)
|
67
|
+
@color_enabled = on_or_off
|
61
68
|
end
|
62
69
|
|
63
|
-
|
64
|
-
|
65
|
-
@
|
70
|
+
# The formatter to use. Defaults to the documentation formatter
|
71
|
+
def formatter=(formatter_to_use)
|
72
|
+
@formatter_to_use = formatter_to_use.to_s
|
66
73
|
end
|
67
74
|
|
75
|
+
def formatter
|
76
|
+
@formatter ||= case @formatter_to_use
|
77
|
+
when 'documentation'
|
78
|
+
Micronaut::Formatters::DocumentationFormatter.new
|
79
|
+
else
|
80
|
+
Micronaut::Formatters::ProgressFormatter.new
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def output
|
85
|
+
$stdout
|
86
|
+
end
|
87
|
+
|
68
88
|
def extra_modules
|
69
89
|
@extra_modules ||= []
|
70
90
|
end
|
@@ -1,17 +1,36 @@
|
|
1
1
|
module Micronaut
|
2
2
|
module Formatters
|
3
|
-
|
3
|
+
|
4
4
|
class BaseFormatter
|
5
|
-
attr_accessor :behaviour
|
5
|
+
attr_accessor :behaviour
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@total_example_failed, @total_example_pending, @behaviour = 0, 0, nil
|
9
|
+
end
|
6
10
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
11
|
+
def configuration
|
12
|
+
Micronaut.configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
def output
|
16
|
+
Micronaut.configuration.output
|
10
17
|
end
|
11
18
|
|
12
19
|
def profile_examples?
|
13
20
|
Micronaut.configuration.profile_examples
|
14
21
|
end
|
22
|
+
|
23
|
+
def color_enabled?
|
24
|
+
configuration.color_enabled?
|
25
|
+
end
|
26
|
+
|
27
|
+
def total_example_failed
|
28
|
+
@total_example_failed
|
29
|
+
end
|
30
|
+
|
31
|
+
def total_example_pending
|
32
|
+
@total_example_pending
|
33
|
+
end
|
15
34
|
|
16
35
|
# This method is invoked before any examples are run, right after
|
17
36
|
# they have all been collected. This can be useful for special
|
@@ -3,20 +3,24 @@ module Micronaut
|
|
3
3
|
module Formatters
|
4
4
|
|
5
5
|
class BaseTextFormatter < BaseFormatter
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
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 ||= []
|
13
17
|
end
|
14
18
|
|
15
19
|
def example_passed(example)
|
16
20
|
super
|
17
21
|
# Why && @start_time
|
18
22
|
if profile_examples? && @start_time
|
19
|
-
|
23
|
+
example_profiling_info << [example, Time.now - @start_time]
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
@@ -25,25 +29,25 @@ module Micronaut
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def example_pending(example, message)
|
28
|
-
|
32
|
+
pending_examples << [example, message]
|
29
33
|
end
|
30
34
|
|
31
35
|
def example_failed(example, exception)
|
32
36
|
super
|
33
|
-
|
37
|
+
failed_examples << [example, exception]
|
34
38
|
end
|
35
39
|
|
36
40
|
def dump_failures
|
37
|
-
|
38
|
-
|
41
|
+
output.puts
|
42
|
+
failed_examples.each_with_index do |examples_with_exception, index|
|
39
43
|
example, exception = examples_with_exception.first, examples_with_exception.last
|
40
44
|
padding = ' '
|
41
|
-
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
output.puts "#{index.next}) #{example}"
|
46
|
+
# output.puts "#{padding}failing statement: #{read_failed_line(example.options[:caller])}\n"
|
47
|
+
output.puts "#{padding}#{colorise(exception.message, exception).strip}"
|
48
|
+
output.puts grey("#{padding}# #{format_backtrace(exception.backtrace)}")
|
49
|
+
output.puts
|
50
|
+
output.flush
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
@@ -61,48 +65,53 @@ module Micronaut
|
|
61
65
|
end
|
62
66
|
|
63
67
|
def dump_summary(duration, example_count, failure_count, pending_count)
|
64
|
-
|
68
|
+
output.puts "\nFinished in #{duration} seconds\n"
|
65
69
|
|
66
|
-
summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count}
|
70
|
+
summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failures"
|
67
71
|
summary << ", #{pending_count} pending" if pending_count > 0
|
68
72
|
|
69
73
|
if failure_count == 0
|
70
74
|
if pending_count > 0
|
71
|
-
|
75
|
+
output.puts yellow(summary)
|
72
76
|
else
|
73
|
-
|
77
|
+
output.puts green(summary)
|
74
78
|
end
|
75
79
|
else
|
76
|
-
|
80
|
+
output.puts red(summary)
|
77
81
|
end
|
78
82
|
|
79
83
|
if profile_examples?
|
80
|
-
sorted_examples =
|
81
|
-
|
82
|
-
sorted_examples.
|
83
|
-
|
84
|
-
|
84
|
+
sorted_examples = example_profiling_info.sort_by { |desc, time| time }.last(5)
|
85
|
+
output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
|
86
|
+
sorted_examples.reverse.each do |desc, time|
|
87
|
+
output.puts " (#{sprintf("%.7f", time)} seconds) #{desc}"
|
88
|
+
output.puts grey(" # #{desc.options[:caller]}")
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
88
|
-
|
92
|
+
output.flush
|
89
93
|
end
|
94
|
+
|
95
|
+
# def textmate_link_backtrace(path)
|
96
|
+
# file, line = path.split(':')
|
97
|
+
# "txmt://open/?url=file://#{File.expand_path(file)}&line=#{line}"
|
98
|
+
# end
|
90
99
|
|
91
100
|
def dump_pending
|
92
|
-
unless
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
101
|
+
unless pending_examples.empty?
|
102
|
+
output.puts
|
103
|
+
output.puts "Pending:"
|
104
|
+
pending_examples.each do |pending_example, message|
|
105
|
+
output.puts "\n #{pending_example.behaviour}\n - #{pending_example.description}"
|
106
|
+
output.puts grey(" # #{pending_example.options[:caller]}")
|
98
107
|
end
|
99
108
|
end
|
100
|
-
|
109
|
+
output.flush
|
101
110
|
end
|
102
111
|
|
103
112
|
def close
|
104
|
-
if IO ===
|
105
|
-
|
113
|
+
if IO === output && output != $stdout
|
114
|
+
output.close
|
106
115
|
end
|
107
116
|
end
|
108
117
|
|
@@ -114,10 +123,6 @@ module Micronaut
|
|
114
123
|
|
115
124
|
protected
|
116
125
|
|
117
|
-
def enable_color_in_output?
|
118
|
-
@options.enable_color_in_output?
|
119
|
-
end
|
120
|
-
|
121
126
|
def backtrace_line(line)
|
122
127
|
return nil if Micronaut.configuration.cleaned_from_backtrace?(line)
|
123
128
|
line.sub!(/\A([^:]+:\d+)$/, '\\1')
|
@@ -126,7 +131,7 @@ module Micronaut
|
|
126
131
|
end
|
127
132
|
|
128
133
|
def color(text, color_code)
|
129
|
-
return text unless
|
134
|
+
return text unless color_enabled?
|
130
135
|
"#{color_code}#{text}\e[0m"
|
131
136
|
end
|
132
137
|
|
@@ -5,25 +5,25 @@ module Micronaut
|
|
5
5
|
|
6
6
|
def example_failed(example, exception)
|
7
7
|
super
|
8
|
-
|
9
|
-
|
8
|
+
output.print colorise('F', exception)
|
9
|
+
output.flush
|
10
10
|
end
|
11
11
|
|
12
12
|
def example_passed(example)
|
13
13
|
super
|
14
|
-
|
15
|
-
|
14
|
+
output.print green('.')
|
15
|
+
output.flush
|
16
16
|
end
|
17
17
|
|
18
18
|
def example_pending(example, message)
|
19
19
|
super
|
20
|
-
|
21
|
-
|
20
|
+
output.print yellow('*')
|
21
|
+
output.flush
|
22
22
|
end
|
23
23
|
|
24
24
|
def start_dump
|
25
|
-
|
26
|
-
|
25
|
+
output.puts
|
26
|
+
output.flush
|
27
27
|
end
|
28
28
|
|
29
29
|
def method_missing(sym, *args)
|
data/lib/micronaut/runner.rb
CHANGED
@@ -10,12 +10,19 @@ module Micronaut
|
|
10
10
|
at_exit { Micronaut::Runner.new.run(ARGV) ? exit(0) : exit(1) } unless installed_at_exit?
|
11
11
|
@installed_at_exit = true
|
12
12
|
end
|
13
|
-
|
14
|
-
def
|
15
|
-
Micronaut.configuration
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
Micronaut.configuration
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
def formatter
|
19
|
+
Micronaut.configuration.formatter
|
20
|
+
end
|
21
|
+
|
22
|
+
# This method takes command line args like examples/**/*_example.rb and
|
23
|
+
# uses globbing to grab all the files specified and load them
|
18
24
|
def load_all_behaviours(files_from_args=[])
|
25
|
+
# TODO: Make this horrid looking line more readable by at least some humans
|
19
26
|
files_from_args.inject([]) { |files, arg| files.concat(Dir[arg].map { |g| Dir.glob(g) }.flatten) }.each do |file|
|
20
27
|
load file
|
21
28
|
end
|
@@ -24,29 +31,29 @@ module Micronaut
|
|
24
31
|
def run(args = [])
|
25
32
|
load_all_behaviours(args)
|
26
33
|
|
27
|
-
behaviours_to_run = Micronaut
|
34
|
+
behaviours_to_run = Micronaut.world.behaviours_to_run
|
28
35
|
|
29
36
|
total_examples = behaviours_to_run.inject(0) { |sum, b| sum + b.examples_to_run.size }
|
30
37
|
|
31
|
-
old_sync,
|
38
|
+
old_sync, formatter.output.sync = formatter.output.sync, true if formatter.output.respond_to?(:sync=)
|
32
39
|
|
33
|
-
|
40
|
+
formatter.start(total_examples)
|
34
41
|
|
35
42
|
suite_success = true
|
36
43
|
|
37
44
|
starts_at = Time.now
|
38
45
|
behaviours_to_run.each do |behaviour|
|
39
|
-
suite_success &= behaviour.run(
|
46
|
+
suite_success &= behaviour.run(formatter)
|
40
47
|
end
|
41
48
|
duration = Time.now - starts_at
|
42
49
|
|
43
|
-
|
44
|
-
|
50
|
+
formatter.start_dump
|
51
|
+
formatter.dump_failures
|
45
52
|
# TODO: Stop passing in the last two items, the formatter knows this info
|
46
|
-
|
47
|
-
|
53
|
+
formatter.dump_summary(duration, total_examples, formatter.failed_examples.size, formatter.pending_examples.size)
|
54
|
+
formatter.dump_pending
|
48
55
|
|
49
|
-
|
56
|
+
formatter.output.sync = old_sync if formatter.output.respond_to? :sync=
|
50
57
|
|
51
58
|
suite_success
|
52
59
|
end
|
data/lib/micronaut/world.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
1
|
module Micronaut
|
2
2
|
|
3
3
|
class World
|
4
|
-
|
5
|
-
def
|
6
|
-
@behaviours
|
7
|
-
end
|
8
|
-
|
9
|
-
reset
|
10
|
-
|
11
|
-
def self.behaviours
|
12
|
-
@behaviours
|
4
|
+
|
5
|
+
def behaviours
|
6
|
+
@behaviours ||= []
|
13
7
|
end
|
14
8
|
|
15
|
-
def
|
9
|
+
def behaviours_to_run
|
16
10
|
filter_behaviours
|
17
11
|
number_of_behaviours_left = sum_behaviours
|
18
12
|
|
@@ -20,30 +14,29 @@ module Micronaut
|
|
20
14
|
if Micronaut.configuration.filters.empty?
|
21
15
|
add_all_examples
|
22
16
|
elsif Micronaut.configuration.run_all_when_everything_filtered?
|
23
|
-
puts "
|
17
|
+
puts "Filters produced no matches - running everything"
|
24
18
|
add_all_examples
|
25
19
|
else
|
26
|
-
puts "
|
20
|
+
puts "Filters matched no specs - your world is empty, desolate, and alone."
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
24
|
behaviours
|
31
25
|
end
|
32
26
|
|
33
|
-
def
|
27
|
+
def sum_behaviours
|
34
28
|
behaviours.inject(0) { |sum, b| sum += b.examples_to_run.size }
|
35
29
|
end
|
36
30
|
|
37
|
-
def
|
31
|
+
def add_all_examples
|
38
32
|
behaviours.each do |behaviour|
|
39
33
|
behaviour.examples_to_run.concat(behaviour.examples)
|
40
34
|
end
|
41
35
|
end
|
42
36
|
|
43
|
-
def
|
37
|
+
def filter_behaviours
|
44
38
|
return unless Micronaut.configuration.filters.any?
|
45
39
|
Micronaut.configuration.filters.each do |filter|
|
46
|
-
puts " Run filtered using: #{filter.inspect}"
|
47
40
|
behaviours.each do |behaviour|
|
48
41
|
behaviour.examples_to_run.concat find(behaviour.examples, filter)
|
49
42
|
end
|
@@ -51,7 +44,7 @@ module Micronaut
|
|
51
44
|
behaviours
|
52
45
|
end
|
53
46
|
|
54
|
-
def
|
47
|
+
def find(collection, conditions={})
|
55
48
|
return [] if conditions.empty?
|
56
49
|
|
57
50
|
collection.select do |item|
|
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.2
|
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-19 00:00:00 -08:00
|
13
13
|
default_executable: micronaut
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -74,7 +74,6 @@ files:
|
|
74
74
|
- lib/micronaut/mocking/with_rr.rb
|
75
75
|
- lib/micronaut/mocking.rb
|
76
76
|
- lib/micronaut/runner.rb
|
77
|
-
- lib/micronaut/runner_options.rb
|
78
77
|
- lib/micronaut/world.rb
|
79
78
|
- lib/micronaut.rb
|
80
79
|
- examples/example_helper.rb
|
@@ -113,7 +112,6 @@ files:
|
|
113
112
|
- examples/lib/micronaut/matchers/simple_matcher_example.rb
|
114
113
|
- examples/lib/micronaut/matchers/throw_symbol_example.rb
|
115
114
|
- examples/lib/micronaut/runner_example.rb
|
116
|
-
- examples/lib/micronaut/runner_options_example.rb
|
117
115
|
- examples/lib/micronaut/world_example.rb
|
118
116
|
- examples/lib/micronaut_example.rb
|
119
117
|
- examples/resources
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Micronaut
|
2
|
-
class RunnerOptions
|
3
|
-
|
4
|
-
attr_accessor :color, :formatter
|
5
|
-
|
6
|
-
def initialize(options={})
|
7
|
-
@color = options.delete(:color)
|
8
|
-
@formatter = options.delete(:formatter)
|
9
|
-
end
|
10
|
-
|
11
|
-
def enable_color_in_output?
|
12
|
-
!textmate? && @color
|
13
|
-
end
|
14
|
-
|
15
|
-
def textmate?
|
16
|
-
ENV.has_key?('TM_RUBY')
|
17
|
-
end
|
18
|
-
|
19
|
-
def output
|
20
|
-
$stdout
|
21
|
-
end
|
22
|
-
|
23
|
-
def formatter
|
24
|
-
@formatter_instance ||= case @formatter.to_s
|
25
|
-
when 'documentation'
|
26
|
-
Micronaut::Formatters::DocumentationFormatter.new(self, output)
|
27
|
-
else
|
28
|
-
Micronaut::Formatters::ProgressFormatter.new(self, output)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|