spicycode-micronaut 0.1.4 → 0.1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,10 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
  require 'rubygems/specification'
4
- require 'date'
5
4
 
6
5
  GEM = "micronaut"
7
- GEM_VERSION = "0.1.4"
6
+ GEM_VERSION = "0.1.4.1"
8
7
  AUTHOR = "Chad Humphries"
9
8
  EMAIL = "chad@spicycode.com"
10
9
  HOMEPAGE = "http://spicycode.com"
@@ -39,7 +38,7 @@ task :install => [:package] do
39
38
  end
40
39
 
41
40
  desc "create a gemspec file"
42
- task :make_spec do
41
+ task :make_gemspec do
43
42
  File.open("#{GEM}.gemspec", "w") do |file|
44
43
  file.puts spec.to_ruby
45
44
  end
@@ -72,7 +71,12 @@ namespace :micronaut do
72
71
  system "rcov --exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-report --sort coverage --no-validator-links #{examples.join(' ')}"
73
72
  end
74
73
 
74
+ desc "Delete coverage artifacts"
75
+ task :clean_coverage do
76
+ rm_rf Dir["coverage/**/*"]
77
+ end
78
+
75
79
  end
76
80
 
77
81
  task :default => 'micronaut:coverage'
78
-
82
+ task :clobber_package => 'micronaut:clean_coverage'
@@ -30,7 +30,7 @@ end
30
30
  Micronaut.configure do |config|
31
31
  config.mock_with :mocha
32
32
  config.options = Micronaut::RunnerOptions.new(:color => true, :formatter => :progress)
33
- config.profile_examples = true
34
- # config.add_filter :options => { :focused => true }
33
+ config.profile_examples = false
34
+ config.add_filter :options => { :focused => true }
35
35
  config.autorun!
36
36
  end
@@ -171,18 +171,24 @@ describe Micronaut::Behaviour do
171
171
 
172
172
  end
173
173
 
174
- before { @wee = 1 }
174
+ describe Foo, "describing nested behaviours" do
175
175
 
176
- describe "nested describes" do
177
-
178
- before { @wee += 5 }
176
+ describe "nested describes" do
179
177
 
180
- it "should set the described type to the parent described type (if it is not given)"
178
+ it "should set the described type to the parent described type if no described type is given" do
179
+ self.class.described_type.should == Foo
180
+ end
181
+
182
+ it "should set the description to the first parameter if no described type is given" do
183
+ self.class.description.should == 'nested describes'
184
+ end
185
+
186
+ it "should have access to all of it's ancestors before blocks"
187
+
188
+ it "should have access to all of it's ancestors after blocks"
181
189
 
182
- it "should have all of the parent before blocks" do
183
- @wee.should == 6
184
190
  end
185
191
 
186
192
  end
187
193
 
188
- end
194
+ end
@@ -45,13 +45,26 @@ describe Micronaut::Configuration do
45
45
 
46
46
  end
47
47
 
48
- focused "should extend the given module into each behaviour" do
49
- Micronaut.configuration.extend(ThatThingISentYou)
50
- group = Micronaut::Behaviour.describe(ThatThingISentYou, 'that thing i sent you') { }
51
- group.should respond_to(:that_thing)
48
+ it "should extend the given module into each behaviour group" do
49
+ Micronaut.configuration.extend(FocusedSupport)
50
+ group = Micronaut::Behaviour.describe(FocusedSupport, 'the focused support ') { }
51
+ group.should respond_to(:fit)
52
52
  remove_last_describe_from_world
53
53
  end
54
54
 
55
55
  end
56
56
 
57
+ describe "#run_all_when_everything_filtered" do
58
+
59
+ it "defaults to true" do
60
+ Micronaut::Configuration.new.run_all_when_everything_filtered.should == true
61
+ end
62
+
63
+ it "can be queried with question method" do
64
+ config = Micronaut::Configuration.new
65
+ config.run_all_when_everything_filtered = false
66
+ config.run_all_when_everything_filtered?.should == false
67
+ end
68
+ end
69
+
57
70
  end
@@ -43,4 +43,10 @@ describe Micronaut::Example do
43
43
 
44
44
  end
45
45
 
46
+ describe "accessing metadata within a running example" do
47
+
48
+ it "should be able to get the current example object"
49
+
50
+ end
51
+
46
52
  end
@@ -59,15 +59,11 @@ describe Micronaut::Formatters::ProgressFormatter do
59
59
  backtrace = ["/tmp/x.rb:1", "/tmp/x.rb:2", "/tmp/x.rb:3"]
60
60
  @formatter.format_backtrace(backtrace).should eql(<<-EOE.rstrip)
61
61
  /tmp/x.rb:1
62
- /tmp/x.rb:2
63
- /tmp/x.rb:3
64
62
  EOE
65
63
 
66
64
  backtrace = ["/tmp/x.rb:1: message", "/tmp/x.rb:2", "/tmp/x.rb:3"]
67
65
  @formatter.format_backtrace(backtrace).should eql(<<-EOE.rstrip)
68
66
  /tmp/x.rb:1: message
69
- /tmp/x.rb:2
70
- /tmp/x.rb:3
71
67
  EOE
72
68
  end
73
69
 
@@ -1,6 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
2
2
 
3
3
  class Bar; end
4
+ class Foo; end
4
5
 
5
6
  describe Micronaut::World do
6
7
 
@@ -23,13 +24,25 @@ describe Micronaut::World do
23
24
  @bg1 = Micronaut::Behaviour.describe(Bar, "find group-1", options_1) { }
24
25
  @bg2 = Micronaut::Behaviour.describe(Bar, "find group-2", options_2) { }
25
26
  @bg3 = Micronaut::Behaviour.describe(Bar, "find group-3", options_3) { }
26
- @behaviours = [@bg1, @bg2, @bg3]
27
+ @bg4 = Micronaut::Behaviour.describe(Foo, "find these examples") do
28
+ it('I have no options') {}
29
+ it("this is awesome", :awesome => true) {}
30
+ it("this is too", :awesome => true) {}
31
+ it("not so awesome", :awesome => false) {}
32
+ it("I also have no options") {}
33
+ end
34
+ @behaviours = [@bg1, @bg2, @bg3, @bg4]
27
35
  end
28
36
 
29
37
  after(:all) do
30
38
  Micronaut::World.behaviours.delete(@bg1)
31
39
  Micronaut::World.behaviours.delete(@bg2)
32
40
  Micronaut::World.behaviours.delete(@bg3)
41
+ Micronaut::World.behaviours.delete(@bg4)
42
+ end
43
+
44
+ it "should find awesome examples" do
45
+ Micronaut::World.find(@bg4.examples, :options => {:awesome => true}).should == [@bg4.examples[1], @bg4.examples[2]]
33
46
  end
34
47
 
35
48
  it "should find no groups when given no search parameters" do
@@ -91,5 +104,12 @@ describe Micronaut::World do
91
104
  end
92
105
 
93
106
  end
107
+
108
+ describe "filter_behaviours_to_run" do
109
+
110
+ it "does nothing if there are no filters"
111
+ # how do you spec this kind of behavior? It feels like we need to be able to create new instances of Micronaut to properly spec
112
+ # this kind of thing, so we can mock/stub or interrogate state without affecting the actual running instance.
113
+ end
94
114
 
95
115
  end
@@ -206,6 +206,6 @@ module Micronaut
206
206
  def self.to_s
207
207
  self == Micronaut::Behaviour ? 'Micronaut::Behaviour' : name
208
208
  end
209
-
209
+
210
210
  end
211
211
  end
@@ -1,12 +1,31 @@
1
1
  module Micronaut
2
2
 
3
3
  class Configuration
4
- attr_reader :mock_framework, :backtrace_clean_patterns, :behaviour_filters
4
+ # Destired mocking framework - expects the symbol name of the framework
5
+ # Currently supported: :mocha, :rr, or nothing (the default if this is not set at all)
6
+ attr_reader :mock_framework
7
+
8
+ # Array of regular expressions to scrub from backtrace
9
+ attr_reader :backtrace_clean_patterns
10
+
11
+ # An array of arrays to store before and after blocks
12
+ attr_reader :before_and_afters
13
+
14
+ # Filters allow you to exclude or include certain examples from running based on options you pass in
15
+ attr_reader :filters
16
+
17
+ # When this is true, if you have filters enabled and no examples match, all examples are added and run - defaults to true
18
+ attr_accessor :run_all_when_everything_filtered
19
+
20
+ # Enable profiling of the top 10 slowest examples - defaults to false
5
21
  attr_accessor :profile_examples
6
22
 
7
23
  def initialize
8
24
  @backtrace_clean_patterns = [/\/lib\/ruby\//, /bin\/rcov:/, /vendor\/rails/]
9
25
  @profile_examples = false
26
+ @run_all_when_everything_filtered = true
27
+ @filters = []
28
+ @before_and_afters = []
10
29
  end
11
30
 
12
31
  def cleaned_from_backtrace?(line)
@@ -75,18 +94,14 @@ module Micronaut
75
94
  end
76
95
  end
77
96
 
78
- def filters
79
- @filters ||= []
80
- end
81
-
82
97
  def add_filter(options={})
83
98
  filters << options
84
99
  end
85
100
 
86
- def before_and_afters
87
- @before_and_afters ||= []
101
+ def run_all_when_everything_filtered?
102
+ @run_all_when_everything_filtered
88
103
  end
89
-
104
+
90
105
  def before(type=:each, options={}, &block)
91
106
  before_and_afters << [:before, :each, options, block]
92
107
  end
@@ -37,13 +37,20 @@ module Micronaut
37
37
  @output.puts
38
38
  @failed_examples.each_with_index do |examples_with_exception, index|
39
39
  example, exception = examples_with_exception.first, examples_with_exception.last
40
+ padding = ' '
40
41
  @output.puts "#{index.next}) #{example}"
41
- @output.puts colorise(exception.message, exception)
42
- @output.puts format_backtrace(exception.backtrace)
42
+ # @output.puts "#{padding}failing statement: #{read_failed_line(example.options[:caller])}\n"
43
+ @output.puts "#{padding}#{colorise(exception.message, exception).strip}"
44
+ @output.puts grey("#{padding}# #{format_backtrace(exception.backtrace)}")
43
45
  @output.puts
44
46
  @output.flush
45
47
  end
46
48
  end
49
+
50
+ def read_failed_line(file_path_with_line_number)
51
+ file_path, line_number = file_path_with_line_number.split(':')
52
+ open(file_path, 'r') { |f| f.readlines[line_number.to_i + 1].strip }
53
+ end
47
54
 
48
55
  def colorise(s, failure)
49
56
  if failure.is_a?(Micronaut::Expectations::ExpectationNotMetError)
@@ -101,8 +108,8 @@ module Micronaut
101
108
 
102
109
  def format_backtrace(backtrace)
103
110
  return "" if backtrace.nil?
104
- cleansed = backtrace.map { |line| backtrace_line(line) }.compact.join("\n")
105
- cleansed.empty? ? backtrace : cleansed
111
+ cleansed = backtrace.map { |line| backtrace_line(line) }.compact
112
+ cleansed.empty? ? backtrace.join("\n") : cleansed.first
106
113
  end
107
114
 
108
115
  protected
@@ -41,11 +41,10 @@ module Micronaut
41
41
  duration = Time.now - starts_at
42
42
 
43
43
  options.formatter.start_dump
44
- options.formatter.dump_pending
45
44
  options.formatter.dump_failures
46
-
47
45
  # TODO: Stop passing in the last two items, the formatter knows this info
48
46
  options.formatter.dump_summary(duration, total_examples, options.formatter.failed_examples.size, options.formatter.pending_examples.size)
47
+ options.formatter.dump_pending
49
48
 
50
49
  options.formatter.output.sync = old_sync if options.formatter.output.respond_to? :sync=
51
50
 
@@ -13,22 +13,42 @@ module Micronaut
13
13
  end
14
14
 
15
15
  def self.behaviours_to_run
16
+ filter_behaviours
17
+ number_of_behaviours_left = sum_behaviours
18
+
19
+ if number_of_behaviours_left.zero?
20
+ if Micronaut.configuration.filters.empty?
21
+ add_all_examples
22
+ elsif Micronaut.configuration.run_all_when_everything_filtered?
23
+ puts " Filter(s) produced no matches - running everything"
24
+ add_all_examples
25
+ else
26
+ puts " Filter(s) matched no specs - your world is empty, desolate, and alone."
27
+ end
28
+ end
29
+
30
+ behaviours
31
+ end
32
+
33
+ def self.sum_behaviours
34
+ behaviours.inject(0) { |sum, b| sum += b.examples_to_run.size }
35
+ end
36
+
37
+ def self.add_all_examples
38
+ behaviours.each do |behaviour|
39
+ behaviour.examples_to_run.concat(behaviour.examples)
40
+ end
41
+ end
42
+
43
+ def self.filter_behaviours
44
+ return unless Micronaut.configuration.filters.any?
16
45
  Micronaut.configuration.filters.each do |filter|
17
46
  puts " Run filtered using: #{filter.inspect}"
18
47
  behaviours.each do |behaviour|
19
48
  behaviour.examples_to_run.concat find(behaviour.examples, filter)
20
49
  end
21
- end
22
-
23
- number_of_behaviours_left = behaviours.inject(0) { |sum, b| sum += b.examples_to_run.size }
24
-
25
- if number_of_behaviours_left.zero? && Micronaut.configuration.filters.size.zero?
26
- behaviours.each do |behaviour|
27
- behaviour.examples_to_run.concat(behaviour.examples)
28
- end
29
50
  end
30
-
31
- behaviours
51
+ behaviours
32
52
  end
33
53
 
34
54
  def self.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.1
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-17 00:00:00 -08:00
12
+ date: 2008-12-18 00:00:00 -08:00
13
13
  default_executable: micronaut
14
14
  dependencies: []
15
15