spicycode-micronaut 0.1.7.4 → 0.1.8.0

Sign up to get free protection for your applications and to get access to all the features.
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.7.4"
6
+ GEM_VERSION = "0.1.8.0"
7
7
  AUTHOR = "Chad Humphries"
8
8
  EMAIL = "chad@spicycode.com"
9
9
  HOMEPAGE = "http://spicycode.com"
@@ -67,5 +67,44 @@ describe Micronaut::Configuration do
67
67
  config.run_all_when_everything_filtered?.should == false
68
68
  end
69
69
  end
70
+
71
+ describe '#trace?' do
72
+
73
+ it "is false by default" do
74
+ Micronaut::Configuration.new.trace?.should == false
75
+ end
76
+
77
+ it "is true if configuration.trace is true", :full_backtrace => true do
78
+ config = Micronaut::Configuration.new
79
+ config.trace = true
80
+ config.trace?.should == true
81
+ end
82
+
83
+ end
84
+
85
+ describe '#trace' do
86
+
87
+ it "requires a block" do
88
+ config = Micronaut::Configuration.new
89
+ config.trace = true
90
+ lambda { config.trace(true) }.should raise_error(ArgumentError)
91
+ end
92
+
93
+ it "does nothing if trace is false" do
94
+ config = Micronaut::Configuration.new
95
+ config.trace = false
96
+ config.output.expects(:puts).never
97
+ config.trace { "my trace string is awesome" }
98
+ end
99
+
100
+ it "allows overriding tracing an optional param" do
101
+ config = Micronaut::Configuration.new
102
+ config.trace = false
103
+ config.output.expects(:puts).with(includes("my trace string is awesome"))
104
+ config.trace(true) { "my trace string is awesome" }
105
+ end
106
+
107
+
108
+ end
70
109
 
71
110
  end
@@ -122,4 +122,16 @@ describe Micronaut::Formatters::BaseFormatter do
122
122
 
123
123
  end
124
124
 
125
+ describe '#trace' do
126
+
127
+ it "outputs trace message if behaviour metadata has :trace => true" do
128
+ Micronaut.configuration.output.expects(:puts).with(includes("Starting example: example"))
129
+ behaviour = Micronaut::Behaviour.describe("foo", :trace => true) {}
130
+ @formatter.behaviour = behaviour
131
+ @formatter.example_started("example")
132
+ end
133
+
134
+ end
135
+
136
+
125
137
  end
@@ -32,6 +32,7 @@ describe Micronaut::Formatters::ProgressFormatter do
32
32
  describe "when color is enabled" do
33
33
 
34
34
  before do
35
+ @formatter.stubs(:trace?).returns(false)
35
36
  @formatter.stubs(:color_enabled?).returns(true)
36
37
  end
37
38
 
@@ -92,11 +92,13 @@ module Micronaut
92
92
  @metadata.update(extra_metadata)
93
93
 
94
94
  Micronaut.configuration.find_modules(self).each do |include_or_extend, mod, opts|
95
- if include_or_extend == :extend
95
+ if include_or_extend == :extend
96
+ Micronaut.configuration.trace { "Extending module #{mod} on #{self}" }
96
97
  send(:extend, mod) unless extended_modules.include?(mod)
97
- else
98
- send(:include, mod) unless included_modules.include?(mod)
99
- end
98
+ else
99
+ Micronaut.configuration.trace { "Including module #{mod} on #{self}" }
100
+ send(:include, mod) unless included_modules.include?(mod)
101
+ end
100
102
  end
101
103
  end
102
104
 
@@ -19,12 +19,16 @@ module Micronaut
19
19
  # Enable profiling of example run - defaults to false
20
20
  attr_accessor :profile_examples
21
21
 
22
+ # Enable verbose interal logging of the framework - defaults to false
23
+ attr_accessor :trace
24
+
22
25
  attr_reader :mock_framework
23
26
 
24
27
  def initialize
25
28
  @backtrace_clean_patterns = [/\/lib\/ruby\//, /bin\/rcov:/, /vendor\/rails/, /bin\/micronaut/, /#{::Micronaut::InstallDirectory}/]
26
- @profile_examples = false
27
29
  @run_all_when_everything_filtered = true
30
+ @trace = false
31
+ @profile_examples = false
28
32
  @color_enabled = false
29
33
  @before_and_afters = { :before => { :each => [], :all => [] }, :after => { :each => [], :all => [] } }
30
34
  @include_or_extend_modules = []
@@ -96,6 +100,21 @@ module Micronaut
96
100
  def output
97
101
  $stdout
98
102
  end
103
+
104
+ # Output some string for debugging/tracing assistance if trace is enabled
105
+ # The trace string should be sent as a block, which means it will only be interpolated if trace is actually enabled
106
+ # We allow an override here so that trace can be set at lower levels (such as the describe or example level)
107
+ def trace(override = false)
108
+ raise(ArgumentError, "Must yield a block with your string to trace.") unless block_given?
109
+ return unless trace? || override
110
+ Micronaut.configuration.output.puts("[TRACE] #{yield}")
111
+ end
112
+
113
+ # If true, Micronaut will provide detailed trace output of its self as it runs.
114
+ # Can be turned on at the global (configuration) level or at the individual behaviour (describe) level.
115
+ def trace?
116
+ @trace == true
117
+ end
99
118
 
100
119
  # RJS I think we should rename include/extend so they don't conflict or confuse with the ruby builtin
101
120
  # maybe register_include, setup_include, add_include, or just _include ?
@@ -18,6 +18,15 @@ module Micronaut
18
18
  Micronaut.configuration.output
19
19
  end
20
20
 
21
+ def trace(&blk)
22
+ Micronaut.configuration.trace(trace_override_flag, &blk)
23
+ end
24
+
25
+ # Allow setting trace at the behaviour level as well globally
26
+ def trace_override_flag
27
+ behaviour && behaviour.metadata[:trace]
28
+ end
29
+
21
30
  def profile_examples?
22
31
  Micronaut.configuration.profile_examples
23
32
  end
@@ -58,11 +67,12 @@ module Micronaut
58
67
 
59
68
  # This method is invoked when an +example+ starts.
60
69
  def example_started(example)
61
-
70
+ trace { "Starting example: #{example}" }
62
71
  end
63
72
 
64
73
  # This method is invoked when an +example+ passes.
65
74
  def example_passed(example)
75
+ trace { "Example passed: #{example}" }
66
76
  end
67
77
 
68
78
  # This method is invoked when an +example+ fails, i.e. an exception occurred
@@ -13,6 +13,7 @@ module Micronaut
13
13
  end
14
14
 
15
15
  def example_started(example)
16
+ super
16
17
  @start_time = Time.now
17
18
  end
18
19
 
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.7.4
4
+ version: 0.1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries