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 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.2"
6
+ GEM_VERSION = "0.1.4.3"
7
7
  AUTHOR = "Chad Humphries"
8
8
  EMAIL = "chad@spicycode.com"
9
9
  HOMEPAGE = "http://spicycode.com"
data/bin/micronaut CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
3
3
  require 'micronaut'
4
- Micronaut::Runner.autorun
4
+ Micronaut.configuration.autorun!
@@ -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 = true
37
+ config.color_enabled = use_color?
33
38
  config.formatter = :progress
34
- config.profile_examples = true
35
- config.add_filter :options => { :focused => true }
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(Foo, 'Empty Behaviour Group') { }
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(Foo) { }.name.should == 'Foo'
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(Foo) { }.described_type.should == Foo
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(Foo, "my desc") { }.description.should == 'my desc'
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(Foo, nil) { }.description.size.should == 0
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(Foo, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
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(Foo, nil) { }.options.should == {}
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 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" }
170
+ describe Object, "describing nested behaviours" do
180
171
 
181
- describe "nested describes", :just_testing => 'yep' do
172
+ describe "A sample nested describe", :just_testing => 'yep' do
182
173
 
183
- it "should set the described type to the parent described type if no described type is given" do
184
- self.class.described_type.should == Foo
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 options to the last parameter if it is a hash" do
192
- self.class.options.should include(:just_testing => 'yep')
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 the caller in the options hash" do
196
- self.class.options.should include(:caller)
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::Behaviour.expects(:send).with(:include, Micronaut::Mocking::WithMocha)
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 eql("\n")
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 =~ /\nFinished in 3 seconds\n2 examples, 1 failures\n/i
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
- 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")
23
+ @formatter.example_pending(running_example, "message")
30
24
  @output.rewind
31
25
  @formatter.dump_summary(3, 2, 1, 1)
32
- @output.string.should =~ /\nFinished in 3 seconds\n2 examples, 1 failures, 1 pending\n/i
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 push green dot for passing spec" do
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 eql("\e[31mF\e[0m")
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 eql("\e[35mF\e[0m")
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 eql("")
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 eql(<<-EOE.rstrip)
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 eql(<<-EOE.rstrip)
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 reraise an exception thrown in #has_sym?(*args)" do
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
- module Micronaut
4
- module Matchers
5
- describe ThrowSymbol do
6
- describe "with no args" do
7
- before { @matcher = ThrowSymbol.new }
8
-
9
- it "should match if any Symbol is thrown" do
10
- @matcher.matches?(lambda{ throw :sym }).should be_true
11
- end
12
- it "should match if any Symbol is thrown with an arg" do
13
- @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
14
- end
15
- it "should not match if no Symbol is thrown" do
16
- @matcher.matches?(lambda{ }).should be_false
17
- end
18
- it "should provide a failure message" do
19
- @matcher.matches?(lambda{})
20
- @matcher.failure_message.should == "expected a Symbol but nothing was thrown"
21
- end
22
- it "should provide a negative failure message" do
23
- @matcher.matches?(lambda{ throw :sym})
24
- @matcher.negative_failure_message.should == "expected no Symbol, got :sym"
25
- end
26
- end
27
-
28
- describe "with a symbol" do
29
- before { @matcher = ThrowSymbol.new(:sym) }
30
-
31
- it "should match if correct Symbol is thrown" do
32
- @matcher.matches?(lambda{ throw :sym }).should be_true
33
- end
34
- it "should match if correct Symbol is thrown with an arg" do
35
- @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
36
- end
37
- it "should not match if no Symbol is thrown" do
38
- @matcher.matches?(lambda{ }).should be_false
39
- end
40
- it "should not match if correct Symbol is thrown" do
41
- @matcher.matches?(lambda{ throw :other_sym }).should be_false
42
- end
43
- it "should provide a failure message when no Symbol is thrown" do
44
- @matcher.matches?(lambda{})
45
- @matcher.failure_message.should == "expected :sym but nothing was thrown"
46
- end
47
- it "should provide a failure message when wrong Symbol is thrown" do
48
- @matcher.matches?(lambda{ throw :other_sym })
49
- @matcher.failure_message.should == "expected :sym, got :other_sym"
50
- end
51
- it "should provide a negative failure message" do
52
- @matcher.matches?(lambda{ throw :sym })
53
- @matcher.negative_failure_message.should == "expected :sym not to be thrown"
54
- end
55
- it "should only match NameErrors raised by uncaught throws" do
56
- @matcher.matches?(lambda{ sym }).should be_false
57
- end
58
- end
59
-
60
- describe "with a symbol and an arg" do
61
- before { @matcher = ThrowSymbol.new(:sym, "a") }
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
- it "should match if correct Symbol and args are thrown" do
64
- @matcher.matches?(lambda{ throw :sym, "a" }).should be_true
65
- end
66
- it "should not match if nothing is thrown" do
67
- @matcher.matches?(lambda{ }).should be_false
68
- end
69
- it "should not match if other Symbol is thrown" do
70
- @matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
71
- end
72
- it "should not match if no arg is thrown" do
73
- @matcher.matches?(lambda{ throw :sym }).should be_false
74
- end
75
- it "should not match if wrong arg is thrown" do
76
- @matcher.matches?(lambda{ throw :sym, "b" }).should be_false
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
- end
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
@@ -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.empty?
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
@@ -158,7 +158,7 @@ module Micronaut
158
158
  end
159
159
 
160
160
  def self.run(reporter)
161
- return true if examples_to_run.empty?
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
- examples_to_run.each do |ex|
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
- # Filters allow you to exclude or include certain examples from running based on options you pass in
15
- attr_reader :filters
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
- @filters = []
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 unless Micronaut::Runner.installed_at_exit?
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 || true
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 add_filter(options={})
118
- filters << options
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 profile_examples?
84
- sorted_examples = example_profiling_info.sort_by { |desc, time| time }.last(5)
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(options, output_to)
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
- @output.puts(expectation_not_met ? red(message) : magenta(message))
37
- @output.flush
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
@@ -18,31 +18,24 @@ module Micronaut
18
18
  def formatter
19
19
  Micronaut.configuration.formatter
20
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
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
- load_all_behaviours(args)
27
+ require_all_behaviours(args)
33
28
 
34
- behaviours_to_run = Micronaut.world.behaviours_to_run
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(total_examples)
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, total_examples, formatter.failed_examples.size, formatter.pending_examples.size)
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=
@@ -1,47 +1,45 @@
1
1
  module Micronaut
2
2
 
3
3
  class World
4
-
5
- def behaviours
6
- @behaviours ||= []
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
- filter_behaviours
11
- number_of_behaviours_left = sum_behaviours
12
-
13
- if number_of_behaviours_left.zero?
14
- if Micronaut.configuration.filters.empty?
15
- add_all_examples
16
- elsif Micronaut.configuration.run_all_when_everything_filtered?
17
- puts "Filters produced no matches - running everything"
18
- add_all_examples
19
- else
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
- end
23
-
24
- behaviours
25
- end
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 add_all_examples
32
- behaviours.each do |behaviour|
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
- return unless Micronaut.configuration.filters.any?
39
- Micronaut.configuration.filters.each do |filter|
40
- behaviours.each do |behaviour|
41
- behaviour.examples_to_run.concat find(behaviour.examples, filter)
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.2
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-19 00:00:00 -08:00
12
+ date: 2008-12-20 00:00:00 -08:00
13
13
  default_executable: micronaut
14
14
  dependencies: []
15
15