spicycode-micronaut 0.1.5.2 → 0.1.6

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.5.2"
6
+ GEM_VERSION = "0.1.6"
7
7
  AUTHOR = "Chad Humphries"
8
8
  EMAIL = "chad@spicycode.com"
9
9
  HOMEPAGE = "http://spicycode.com"
@@ -44,48 +44,45 @@ task :make_gemspec do
44
44
  end
45
45
  end
46
46
 
47
- namespace :micronaut do
48
-
49
- desc 'Run all examples'
50
- task :examples do
51
- examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
52
- ruby examples.join(" ")
53
- end
54
-
55
- desc "List files that don't have examples"
56
- task :untested do
57
- code = Dir["lib/**/*.rb"].map { |g| Dir.glob(g) }.flatten
58
- examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
59
- examples.map! { |f| f =~ /examples\/(.*)_example/; "#{$1}.rb" }
60
- missing_examples = (code - examples)
61
- puts
62
- puts "The following files seem to be missing their examples:"
63
- missing_examples.each do |missing|
64
- puts " #{missing}"
65
- end
66
- end
67
-
68
- desc "Run all examples using rcov"
69
- task :coverage do
70
- examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
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
73
- end
74
-
75
- def fail_build
76
- puts
77
- puts "-" * 79
78
- puts "Build Failed"
79
- puts "-" * 79
80
- abort
81
- end
82
-
83
- desc "Delete coverage artifacts"
84
- task :clean_coverage do
85
- rm_rf Dir["coverage/**/*"]
47
+ desc 'Run all examples'
48
+ task :examples do
49
+ examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
50
+ ruby examples.join(" ")
51
+ end
52
+
53
+ desc "List files that don't have examples"
54
+ task :untested do
55
+ code = Dir["lib/**/*.rb"].map { |g| Dir.glob(g) }.flatten
56
+ examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
57
+ examples.map! { |f| f =~ /examples\/(.*)_example/; "#{$1}.rb" }
58
+ missing_examples = (code - examples)
59
+ puts
60
+ puts "The following files seem to be missing their examples:"
61
+ missing_examples.each do |missing|
62
+ puts " #{missing}"
86
63
  end
87
-
88
64
  end
89
65
 
90
- task :default => 'micronaut:coverage'
91
- task :clobber_package => 'micronaut:clean_coverage'
66
+ desc "Run all examples using rcov"
67
+ task :coverage do
68
+ examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
69
+ result = system "rcov --exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links #{examples.join(' ')}"
70
+ fail_build unless result
71
+ end
72
+
73
+ def fail_build
74
+ puts
75
+ puts "-" * 79
76
+ puts "Build Failed"
77
+ puts "-" * 79
78
+ abort
79
+ end
80
+
81
+ desc "Delete coverage artifacts"
82
+ task :clean_coverage do
83
+ rm_rf Dir["coverage/**/*"]
84
+ end
85
+
86
+
87
+ task :default => 'coverage'
88
+ task :clobber_package => 'clean_coverage'
@@ -36,7 +36,7 @@ Micronaut.configure do |config|
36
36
  config.mock_with :mocha
37
37
  config.color_enabled = use_color?
38
38
  config.formatter = :progress
39
- config.profile_examples = false
40
- config.filter_run :options => { :focused => true }
39
+ config.profile_examples = true
40
+ config.filter_run :focused => true
41
41
  config.autorun!
42
42
  end
@@ -9,12 +9,12 @@ describe Micronaut::Behaviour do
9
9
 
10
10
  describe "describing behaviour with #describe" do
11
11
 
12
- it "should raise an ArgumentError if no name is given" do
13
- lambda { Micronaut::Behaviour.describe() {} }.should raise_error(ArgumentError)
12
+ example "an ArgumentError is raised if no name is given" do
13
+ lambda { Micronaut::Behaviour.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
14
14
  end
15
15
 
16
- it "should raise an ArgumentError if no block is given" do
17
- lambda { Micronaut::Behaviour.describe('foo') }.should raise_error(ArgumentError)
16
+ example "an ArgumentError is raised if no block is given" do
17
+ lambda { Micronaut::Behaviour.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe")
18
18
  end
19
19
 
20
20
  describe '#name' do
@@ -46,23 +46,19 @@ describe Micronaut::Behaviour do
46
46
  it "should expose the second parameter as description" do
47
47
  Micronaut::Behaviour.describe(Object, "my desc") { }.description.should == 'my desc'
48
48
  end
49
-
49
+
50
50
  it "should allow the second parameter to be nil" do
51
51
  Micronaut::Behaviour.describe(Object, nil) { }.description.size.should == 0
52
52
  end
53
53
 
54
54
  end
55
55
 
56
- describe '#options' do
57
-
58
- it "should expose the third parameter as options" do
59
- Micronaut::Behaviour.describe(Object, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
60
- end
61
-
62
- it "should be an empty hash if no options are supplied" do
63
- Micronaut::Behaviour.describe(Object, nil) { }.options.should == {}
56
+ describe '#metadata' do
57
+
58
+ it "should add the third parameter to the metadata" do
59
+ Micronaut::Behaviour.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
64
60
  end
65
-
61
+
66
62
  end
67
63
 
68
64
  describe "adding before and after hooks" do
@@ -179,8 +175,8 @@ describe Micronaut::Behaviour do
179
175
  running_example.behaviour.description.should == 'A sample nested describe'
180
176
  end
181
177
 
182
- it "should have :just_testing => 'yep' in the options" do
183
- running_example.behaviour.options.should include(:just_testing => 'yep')
178
+ it "should have :just_testing => 'yep' in the metadata" do
179
+ running_example.behaviour.metadata.should include(:just_testing => 'yep')
184
180
  end
185
181
 
186
182
  end
@@ -3,28 +3,28 @@ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
3
3
  describe Micronaut::Configuration do
4
4
 
5
5
  describe "#mock_with" do
6
-
6
+
7
7
  it "should require and include the mocha adapter when called with :mocha" do
8
8
  Micronaut.configuration.expects(:require).with('micronaut/mocking/with_mocha')
9
9
  Micronaut::Behaviour.expects(:send)
10
10
  Micronaut.configuration.mock_with :mocha
11
11
  end
12
-
12
+
13
13
  it "should include the do absolutely nothing mocking adapter for all other cases" do
14
14
  Micronaut::Behaviour.expects(:send).with(:include, Micronaut::Mocking::WithAbsolutelyNothing)
15
15
  Micronaut.configuration.mock_with
16
16
  end
17
-
18
- end
19
-
17
+
18
+ end
19
+
20
20
  describe "#include" do
21
-
21
+
22
22
  module InstanceLevelMethods
23
23
  def you_call_this_a_blt?
24
24
  "egad man, where's the mayo?!?!?"
25
25
  end
26
26
  end
27
-
27
+
28
28
  it "should include the given module into each behaviour group" do
29
29
  Micronaut.configuration.include(InstanceLevelMethods)
30
30
  group = Micronaut::Behaviour.describe(Object, 'does like, stuff and junk') { }
@@ -33,39 +33,38 @@ describe Micronaut::Configuration do
33
33
 
34
34
  group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
35
35
  end
36
-
36
+
37
37
  end
38
38
 
39
39
  describe "#extend" do
40
-
40
+
41
41
  module ThatThingISentYou
42
-
43
- def that_thing(desc, options={}, &block)
44
- it(desc, options.update(:that_thing => true), &block)
42
+
43
+ def that_thing
45
44
  end
46
-
45
+
47
46
  end
48
-
47
+
49
48
  it "should extend the given module into each behaviour group" do
50
49
  Micronaut.configuration.extend(ThatThingISentYou)
51
- group = Micronaut::Behaviour.describe(ThatThingISentYou, 'the focused support ') { }
50
+ group = Micronaut::Behaviour.describe(ThatThingISentYou) { }
52
51
  group.should respond_to(:that_thing)
53
52
  remove_last_describe_from_world
54
53
  end
55
-
54
+
56
55
  end
57
-
56
+
58
57
  describe "#run_all_when_everything_filtered" do
59
-
58
+
60
59
  it "defaults to true" do
61
60
  Micronaut::Configuration.new.run_all_when_everything_filtered.should == true
62
61
  end
63
-
62
+
64
63
  it "can be queried with question method" do
65
64
  config = Micronaut::Configuration.new
66
65
  config.run_all_when_everything_filtered = false
67
66
  config.run_all_when_everything_filtered?.should == false
68
67
  end
69
68
  end
70
-
69
+
71
70
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
3
3
  describe Micronaut::Example do
4
4
 
5
5
  before do
6
- behaviour = stub('behaviour', :name => 'behaviour_name')
6
+ behaviour = stub('behaviour', :name => 'behaviour_name', :metadata => {})
7
7
  @example = Micronaut::Example.new(behaviour, 'description', {}, (lambda {}))
8
8
  end
9
9
 
@@ -17,8 +17,8 @@ describe Micronaut::Example do
17
17
  @example.should respond_to(:description)
18
18
  end
19
19
 
20
- it "should have one for it's options" do
21
- @example.should respond_to(:options)
20
+ it "should have one for it's metadata" do
21
+ @example.should respond_to(:metadata)
22
22
  end
23
23
 
24
24
  it "should have one for it's block" do
@@ -108,10 +108,10 @@ describe Micronaut::Formatters::BaseFormatter do
108
108
 
109
109
  it "should ensure ':' in the first backtrace" do
110
110
  backtrace = ["/tmp/x.rb:1", "/tmp/x.rb:2", "/tmp/x.rb:3"]
111
- @formatter.format_backtrace(backtrace).should == backtrace
111
+ @formatter.format_backtrace(backtrace, running_example).should == backtrace
112
112
 
113
113
  backtrace = ["/tmp/x.rb:1: message", "/tmp/x.rb:2", "/tmp/x.rb:3"]
114
- @formatter.format_backtrace(backtrace).first.should == "/tmp/x.rb:1: message"
114
+ @formatter.format_backtrace(backtrace, running_example).first.should == "/tmp/x.rb:1: message"
115
115
  end
116
116
 
117
117
  end
@@ -39,7 +39,7 @@ describe Micronaut::World do
39
39
  end
40
40
 
41
41
  it "should find awesome examples" do
42
- @world.find(@bg4.examples, :options => {:awesome => true}).should == [@bg4.examples[1], @bg4.examples[2]]
42
+ @world.find(@bg4.examples, :awesome => true).should == [@bg4.examples[1], @bg4.examples[2]]
43
43
  end
44
44
 
45
45
  it "should find no groups when given no search parameters" do
@@ -62,28 +62,28 @@ describe Micronaut::World do
62
62
  @world.find(@behaviours, :description => /find group/).should == [@bg1, @bg2, @bg3]
63
63
  end
64
64
 
65
- it "should find one group when searching for :options => { :foo => 1 }" do
66
- @world.find(@behaviours, :options => { :foo => 1 }).should == [@bg1]
65
+ it "should find one group when searching for :foo => 1" do
66
+ @world.find(@behaviours, :foo => 1 ).should == [@bg1]
67
67
  end
68
68
 
69
- it "should find one group when searching for :options => { :pending => true }" do
70
- @world.find(@behaviours, :options => { :pending => true }).should == [@bg2]
69
+ it "should find one group when searching for :pending => true" do
70
+ @world.find(@behaviours, :pending => true ).should == [@bg2]
71
71
  end
72
72
 
73
- it "should find one group when searching for :options => { :array => [1,2,3,4] }" do
74
- @world.find(@behaviours, :options => { :array => [1,2,3,4] }).should == [@bg3]
73
+ it "should find one group when searching for :array => [1,2,3,4]" do
74
+ @world.find(@behaviours, :array => [1,2,3,4]).should == [@bg3]
75
75
  end
76
76
 
77
- it "should find no group when searching for :options => { :array => [4,3,2,1] }" do
78
- @world.find(@behaviours, :options => { :array => [4,3,2,1] }).should be_empty
77
+ it "should find no group when searching for :array => [4,3,2,1]" do
78
+ @world.find(@behaviours, :array => [4,3,2,1]).should be_empty
79
79
  end
80
80
 
81
- it "should find two groups when searching for :options => { :color => 'blue' }" do
82
- @world.find(@behaviours, :options => { :color => 'blue' }).should == [@bg1, @bg3]
81
+ it "should find two groups when searching for :color => 'blue'" do
82
+ @world.find(@behaviours, :color => 'blue').should == [@bg1, @bg3]
83
83
  end
84
84
 
85
- it "should find two groups when searching for :options => { :feature => 'reporting' }" do
86
- @world.find(@behaviours, :options => { :feature => 'reporting' }).should == [@bg1, @bg2]
85
+ it "should find two groups when searching for :feature => 'reporting' }" do
86
+ @world.find(@behaviours, :feature => 'reporting').should == [@bg1, @bg2]
87
87
  end
88
88
 
89
89
  end
@@ -46,14 +46,24 @@ module Micronaut
46
46
  afters[type] << [options, block]
47
47
  end
48
48
 
49
- def self.it(desc=nil, options={}, &block)
49
+ def self.example(desc=nil, options={}, &block)
50
50
  examples << Micronaut::Example.new(self, desc, options.update(:caller => caller[0]), block)
51
51
  end
52
-
53
- def self.focused(desc=nil, options={}, &block)
54
- it(desc, options.update(:focused => true), &block)
55
- end
56
52
 
53
+ def self.alias_example_to(new_alias, extra_options={})
54
+ new_alias = <<-END_RUBY
55
+ def self.#{new_alias}(desc=nil, options={}, &block)
56
+ updated_options = options.update(:caller => caller[0])
57
+ updated_options.update(#{extra_options.inspect})
58
+ examples << Micronaut::Example.new(self, desc, updated_options, block)
59
+ end
60
+ END_RUBY
61
+ module_eval(new_alias, __FILE__, __LINE__)
62
+ end
63
+
64
+ alias_example_to :it
65
+ alias_example_to :focused, :focused => true
66
+
57
67
  def self.examples
58
68
  @_examples ||= []
59
69
  end
@@ -62,13 +72,23 @@ module Micronaut
62
72
  @_examples_to_run ||= []
63
73
  end
64
74
 
75
+ # This method is friggin' gigantic, and must be stopped
76
+ #
65
77
  def self.set_it_up(*args)
66
- metadata[:options] = args.last.is_a?(Hash) ? args.pop : {}
67
- metadata[:described_type] = args.first.is_a?(String) ? self.superclass.described_type : args.shift
68
- metadata[:description] = args.shift || ''
69
- metadata[:name] = "#{metadata[:described_type]} #{metadata[:description]}".strip
70
- metadata[:describe_block] = metadata[:options].delete(:describe_block)
71
- metadata[:file_path] = eval("caller(0)[0]", metadata[:describe_block].binding)
78
+ @metadata = {}
79
+ extra_metadata = args.last.is_a?(Hash) ? args.pop : {}
80
+ if args.first.is_a?(String)
81
+ @metadata[:described_type] = self.superclass.metadata && self.superclass.metadata[:described_type]
82
+ else
83
+ @metadata[:described_type] = args.shift
84
+ end
85
+ @metadata[:description] = args.shift || ''
86
+ @metadata[:name] = "#{@metadata[:described_type]} #{@metadata[:description]}".strip
87
+ extra_metadata.each do |k,v|
88
+ @metadata[k] = v unless @metadata.has_key?(k)
89
+ end
90
+ @metadata[:file_path] = eval("caller(0)[0]", @metadata[:describe_block].binding)
91
+
72
92
  Micronaut.configuration.find_modules(self).each do |include_or_extend, mod, opts|
73
93
  if include_or_extend == :extend
74
94
  send(:extend, mod) unless extended_modules.include?(mod)
@@ -79,27 +99,25 @@ module Micronaut
79
99
  end
80
100
 
81
101
  def self.metadata
82
- @_metadata ||= {}
102
+ @metadata
83
103
  end
84
104
 
85
105
  def self.name
86
- metadata[:name]
106
+ @metadata[:name]
87
107
  end
88
108
 
89
109
  def self.described_type
90
- metadata[:described_type]
110
+ @metadata[:described_type]
91
111
  end
92
112
 
93
113
  def self.description
94
- metadata[:description]
95
- end
96
-
97
- def self.options
98
- metadata[:options]
114
+ @metadata[:description]
99
115
  end
100
-
116
+
101
117
  def self.describe(*args, &describe_block)
102
- raise ArgumentError if args.empty? || describe_block.nil?
118
+ raise(ArgumentError, "No arguments given. You must a least supply a type or description") if args.empty?
119
+ raise(ArgumentError, "You must supply a block when calling describe") if describe_block.nil?
120
+
103
121
  subclass('NestedLevel') do
104
122
  args << {} unless args.last.is_a?(Hash)
105
123
  args.last.update(:describe_block => describe_block)
@@ -20,8 +20,7 @@ module Micronaut
20
20
 
21
21
  # Enable profiling of the top 10 slowest examples - defaults to false
22
22
  attr_accessor :profile_examples
23
-
24
-
23
+
25
24
  def initialize
26
25
  @backtrace_clean_patterns = [/\/lib\/ruby\//, /bin\/rcov:/, /vendor\/rails/, /bin\/micronaut/]
27
26
  @profile_examples = false
@@ -30,6 +29,10 @@ module Micronaut
30
29
  @before_and_afters = []
31
30
  end
32
31
 
32
+ def alias_example_to(new_name, extra_options={})
33
+ Micronaut::Behaviour.alias_example_to(new_name, extra_options)
34
+ end
35
+
33
36
  def cleaned_from_backtrace?(line)
34
37
  return true if line =~ /#{::Micronaut::InstallDirectory}/
35
38
 
@@ -150,4 +153,4 @@ module Micronaut
150
153
 
151
154
  end
152
155
 
153
- end
156
+ end
@@ -2,19 +2,28 @@ module Micronaut
2
2
 
3
3
  class Example
4
4
 
5
- attr_reader :behaviour, :description, :options, :example_block
5
+ attr_reader :behaviour, :description, :metadata, :example_block
6
6
 
7
7
  def initialize(behaviour, desc, options, example_block=nil)
8
8
  @behaviour, @description, @options, @example_block = behaviour, desc, options, example_block
9
- end
10
-
11
- def metadata
12
- @metadata ||= behaviour.metadata.dup
9
+ @metadata = {}
10
+ behaviour.metadata.each do |k, v|
11
+ @metadata[k] = v
12
+ end
13
13
  @metadata[:description] = description
14
- @metadata[:options].update(options)
15
- @metadata
14
+ options.each do |k,v|
15
+ @metadata[k] = v
16
+ end
17
+ #
18
+ # if @metadata[:options].has_key?(:focused)
19
+ # puts "self.inspect => #{self.inspect}"
20
+ # puts "@metadata[:description] => #{@metadata[:description]}"
21
+ # puts "@options.has_key?(:focused) => #{@options.has_key?(:focused)}"
22
+ # puts "@metadata[:options].has_key?(:focused) => #{@metadata[:options].has_key?(:focused)}"
23
+ # puts
24
+ # end
16
25
  end
17
-
26
+
18
27
  def inspect
19
28
  "#{behaviour.name} - #{description}"
20
29
  end
@@ -126,7 +126,7 @@ module Micronaut
126
126
  end
127
127
 
128
128
  def read_failed_line(exception, example)
129
- original_file = example.options[:caller].split(':').first.strip
129
+ original_file = example.metadata[:caller].split(':').first.strip
130
130
  matching_line = exception.backtrace.find do |line|
131
131
  line.split(':').first.downcase == original_file.downcase
132
132
  end
@@ -74,9 +74,9 @@ module Micronaut
74
74
  if profile_examples? && failure_count == 0
75
75
  sorted_examples = example_profiling_info.sort_by { |desc, time| time }.last(10)
76
76
  output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
77
- sorted_examples.reverse.each do |desc, time|
78
- output.puts " (#{sprintf("%.7f", time)} seconds) #{desc}"
79
- output.puts grey(" # #{desc.options[:caller]}")
77
+ sorted_examples.reverse.each do |ex, time|
78
+ output.puts " (#{sprintf("%.7f", time)} seconds) #{ex}"
79
+ output.puts grey(" # #{ex.metadata[:caller]}")
80
80
  end
81
81
  end
82
82
 
@@ -37,7 +37,7 @@ module Micronaut
37
37
 
38
38
  def filter_behaviours
39
39
  behaviours.inject([]) do |list, b|
40
- b.examples_to_run.replace(find(b.examples, filter))
40
+ b.examples_to_run.replace(find(b.examples, filter).uniq)
41
41
  list << (b.examples_to_run.size == 0 ? nil : b)
42
42
  end.compact
43
43
  end
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.5.2
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries