spicycode-micronaut 0.1.8.2 → 0.1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,6 +39,22 @@ Micronaut is a light-weight BDD test framework.
39
39
 
40
40
  * Designed to be formatter compatible with RSpec (though this needs some real-world testing)
41
41
 
42
+ * Rake task for simple setup
43
+
44
+ require 'rubygems'
45
+ require 'micronaut/rake_task'
46
+
47
+ desc "Run all micronaut examples"
48
+ Micronaut::RakeTask.new :examples do |t|
49
+ t.pattern = "examples/**/*_example.rb"
50
+ end
51
+
52
+ desc "Run all micronaut examples using rcov"
53
+ Micronaut::RakeTask.new :coverage do |t|
54
+ t.pattern = "examples/**/*_example.rb"
55
+ t.rcov = true
56
+ t.rcov_opts = "--exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links"
57
+ end
42
58
  ## REQUIREMENTS:
43
59
 
44
60
  + Ruby 1.8.6+
data/Rakefile CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
  require 'rubygems/specification'
4
+ require 'lib/micronaut/rake_task'
4
5
 
5
6
  GEM = "micronaut"
6
- GEM_VERSION = "0.1.8.2"
7
+ GEM_VERSION = "0.1.8.3"
7
8
  AUTHOR = "Chad Humphries"
8
9
  EMAIL = "chad@spicycode.com"
9
10
  HOMEPAGE = "http://github.com/spicycode/micronaut"
@@ -44,12 +45,6 @@ task :make_gemspec do
44
45
  end
45
46
  end
46
47
 
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
48
  desc "List files that don't have examples"
54
49
  task :untested do
55
50
  code = Dir["lib/**/*.rb"].map { |g| Dir.glob(g) }.flatten
@@ -61,26 +56,20 @@ task :untested do
61
56
  end
62
57
  end
63
58
 
64
- desc "Run all examples using rcov"
65
- task :coverage do
66
- examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
67
- result = system "rcov --exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links #{examples.join(' ')}"
68
- fail_build unless result
59
+ desc "Run all micronaut examples"
60
+ Micronaut::RakeTask.new :examples do |t|
61
+ t.pattern = "examples/**/*_example.rb"
69
62
  end
70
63
 
71
- def fail_build
72
- puts
73
- puts "-" * 79
74
- puts "Build Failed"
75
- puts "-" * 79
76
- abort
77
- end
64
+ namespace :examples do
65
+
66
+ desc "Run all micronaut examples using rcov"
67
+ Micronaut::RakeTask.new :coverage do |t|
68
+ t.pattern = "examples/**/*_example.rb"
69
+ t.rcov = true
70
+ t.rcov_opts = "--exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links"
71
+ end
78
72
 
79
- desc "Delete coverage artifacts"
80
- task :clean_coverage do
81
- rm_rf Dir["coverage/**/*"]
82
73
  end
83
74
 
84
-
85
- task :default => 'coverage'
86
- task :clobber_package => 'clean_coverage'
75
+ task :default => 'examples:coverage'
@@ -7,7 +7,7 @@ gem :mocha
7
7
 
8
8
  require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
9
9
 
10
- module Micronaut
10
+ module Micronaut
11
11
  module Matchers
12
12
  def fail
13
13
  raise_error(::Micronaut::Expectations::ExpectationNotMetError)
@@ -19,12 +19,21 @@ module Micronaut
19
19
  end
20
20
  end
21
21
 
22
+ def with_ruby(version)
23
+ yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
24
+ end
25
+
22
26
  def remove_last_describe_from_world
23
27
  Micronaut.world.behaviours.pop
24
28
  end
25
29
 
30
+ def not_in_editor?
31
+ ['TM_MODE', 'EMACS', 'VIM'].all? { |k| !ENV.has_key?(k) }
32
+ end
33
+
26
34
  Micronaut.configure do |c|
35
+ #c.formatter = :documentation
27
36
  c.mock_with :mocha
28
- c.color_enabled = !ENV.has_key?('TM_MODE')
37
+ c.color_enabled = not_in_editor?
29
38
  c.filter_run :focused => true
30
- end
39
+ end
@@ -60,7 +60,7 @@ describe Micronaut::Behaviour do
60
60
  end
61
61
 
62
62
  it "should add the caller to metadata" do
63
- Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:caller].should == "#{__FILE__}:#{__LINE__}"
63
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:caller].should include("#{__FILE__}:#{__LINE__}")
64
64
  end
65
65
 
66
66
  it "should add the the file_path to metadata" do
@@ -78,7 +78,7 @@ describe Micronaut::Behaviour do
78
78
  it "should add file path and line number metadata for arbitrarily nested describes" do
79
79
  Micronaut::Behaviour.describe(Object) do
80
80
  Micronaut::Behaviour.describe("foo") do
81
- Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:caller].should == "#{__FILE__}:#{__LINE__}"
81
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
82
82
  Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
83
83
  end
84
84
  end
@@ -216,4 +216,4 @@ describe Micronaut::Behaviour do
216
216
 
217
217
  end
218
218
 
219
- end
219
+ end
@@ -7,7 +7,7 @@ describe Micronaut::KernelExtensions do
7
7
  end
8
8
 
9
9
  it "should add a describe method to Object" do
10
- Object.methods.should include("describe")
10
+ Object.should respond_to(:describe)
11
11
  end
12
12
 
13
- end
13
+ end
@@ -345,50 +345,48 @@ EOF
345
345
  end
346
346
  end
347
347
 
348
- module Micronaut
349
- module Matchers
350
- describe Have do
351
- it "should have method_missing as private" do
352
- # with_ruby '1.8' do
353
- Have.private_instance_methods.should include("method_missing")
354
- # end
355
- # with_ruby '1.9' do
356
- # Have.private_instance_methods.should include(:method_missing)
357
- # end
358
- end
359
-
360
- describe "respond_to?" do
361
- before :each do
362
- @have = Have.new(:foo)
363
- @a_method_which_have_defines = Have.instance_methods.first
364
- @a_method_which_object_defines = Object.instance_methods.first
365
- end
366
-
367
- it "should be true for a method which Have defines" do
368
- @have.should respond_to(@a_method_which_have_defines)
369
- end
370
-
371
- it "should be true for a method that it's superclass (Object) defines" do
372
- @have.should respond_to(@a_method_which_object_defines)
373
- end
374
-
375
- it "should be false for a method which neither Object nor nor Have defines" do
376
- @have.should_not respond_to(:foo_bar_baz)
377
- end
378
-
379
- it "should be false if the owner doesn't respond to the method" do
380
- have = Have.new(99)
381
- have.should_not respond_to(:problems)
382
- end
383
-
384
- it "should be true if the owner responds to the method" do
385
- have = Have.new(:a_symbol)
386
- have.should respond_to(:to_sym)
387
- end
388
- end
348
+ describe Micronaut::Matchers::Have do
349
+ it "should have method_missing as private" do
350
+ with_ruby '1.8' do
351
+ Micronaut::Matchers::Have.private_instance_methods.should include("method_missing")
352
+ end
353
+ with_ruby '1.9' do
354
+ Have.private_instance_methods.should include(:method_missing)
389
355
  end
390
356
  end
391
357
 
392
- end
358
+ describe "respond_to?" do
359
+
360
+ before do
361
+ @have = Micronaut::Matchers::Have.new(:foo)
362
+ @a_method_which_have_defines = Micronaut::Matchers::Have.instance_methods.first
363
+ @a_method_which_object_defines = Object.instance_methods.first
364
+ end
365
+
366
+ it "should be true for a method which Have defines" do
367
+ @have.should respond_to(@a_method_which_have_defines)
368
+ end
369
+
370
+ it "should be true for a method that it's superclass (Object) defines" do
371
+ @have.should respond_to(@a_method_which_object_defines)
372
+ end
373
+
374
+ it "should be false for a method which neither Object nor nor Have defines" do
375
+ @have.should_not respond_to(:foo_bar_baz)
376
+ end
377
+
378
+ it "should be false if the owner doesn't respond to the method" do
379
+ have = Micronaut::Matchers::Have.new(99)
380
+ have.should_not respond_to(:problems)
381
+ end
382
+
383
+ it "should be true if the owner responds to the method" do
384
+ have = Micronaut::Matchers::Have.new(:a_symbol)
385
+ have.should respond_to(:to_sym)
386
+ end
387
+
388
+ end
393
389
 
394
- end
390
+ end
391
+
392
+ end
@@ -2,8 +2,7 @@ require 'autotest'
2
2
 
3
3
  Autotest.add_hook :initialize do |at|
4
4
  at.clear_mappings
5
- # watch out: Ruby bug (1.8.6):
6
- # %r(/) != /\//
5
+
7
6
  at.add_mapping(%r%^examples/.*_example.rb$%) { |filename, _|
8
7
  filename
9
8
  }
@@ -39,7 +38,7 @@ class Autotest::Micronaut < Autotest
39
38
 
40
39
  def make_test_cmd(files_to_test)
41
40
  return '' if files_to_test.size == 0
42
- "bin/micronaut #{files_to_test.keys.join(' ')}"
41
+ "bin/micronaut #{files_to_test.keys.sort.join(' ')}"
43
42
  end
44
43
 
45
44
  end
@@ -38,4 +38,4 @@ module Micronaut
38
38
  @world ||= Micronaut::World.new
39
39
  end
40
40
 
41
- end
41
+ end
@@ -85,9 +85,9 @@ module Micronaut
85
85
  @metadata[:behaviour][:description] = args.shift || ''
86
86
  @metadata[:behaviour][:name] = "#{describes} #{description}".strip
87
87
  @metadata[:behaviour][:block] = extra_metadata.delete(:behaviour_block)
88
- @metadata[:behaviour][:caller] = eval("caller(0)[0]", @metadata[:behaviour][:block].binding)
89
- @metadata[:behaviour][:file_path] = @metadata[:behaviour][:caller].split(":")[0].strip
90
- @metadata[:behaviour][:line_number] = @metadata[:behaviour][:caller].split(":")[1].to_i
88
+ @metadata[:behaviour][:caller] = caller(1)
89
+ @metadata[:behaviour][:file_path] = @metadata[:behaviour][:caller][4].split(":")[0].strip
90
+ @metadata[:behaviour][:line_number] = @metadata[:behaviour][:caller][4].split(":")[1].to_i
91
91
 
92
92
  @metadata.update(extra_metadata)
93
93
 
@@ -243,4 +243,4 @@ module Micronaut
243
243
  end
244
244
 
245
245
  end
246
- end
246
+ end
@@ -1,6 +1,6 @@
1
1
  module Micronaut
2
2
  module Expectations
3
- # rspec adds #should and #should_not to every Object (and, implicitly, every Class).
3
+ # We add #should and #should_not to every Object (and, implicitly, every Class).
4
4
  module ObjectExpectations
5
5
  # :call-seq:
6
6
  # should(matcher)
@@ -27,11 +27,6 @@ module Micronaut
27
27
  # end
28
28
  # end
29
29
  #
30
- # You might be wondering "why would I do this if I could just say"
31
- # assert_eats_cheese?", a fair question, indeed. You might prefer
32
- # to replace the word assert with something more aligned with the
33
- # rest of your code examples. You are using rspec, after all.
34
- #
35
30
  # The other benefit you get is that you can use the negative version
36
31
  # of the matcher:
37
32
  #
@@ -118,7 +118,7 @@ module Micronaut
118
118
 
119
119
  cleansed = backtrace.select { |line| backtrace_line(line) }
120
120
  # Kick the describe stack info off the list, just keep the line the problem happened on from that file
121
- cleansed = cleansed.detect { |line| line.split(':').first == example.metadata[:caller].split(':').first } if cleansed.size > 1
121
+ cleansed = [cleansed.detect { |line| line.split(':').first == example.metadata[:caller].split(':').first }] if cleansed.size > 1
122
122
  cleansed.empty? ? backtrace : cleansed
123
123
  end
124
124
 
@@ -148,4 +148,4 @@ module Micronaut
148
148
  end
149
149
 
150
150
  end
151
- end
151
+ end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake'
4
+ require 'rake/tasklib'
5
+
6
+ module Micronaut
7
+
8
+ class RakeTask < ::Rake::TaskLib
9
+
10
+ # Name of task. (default is :examples)
11
+ attr_accessor :name
12
+
13
+ # If true, requests that the specs be run with the warning flag set.
14
+ # E.g. warning=true implies "ruby -w" used to run the specs. Defaults to false.
15
+ attr_accessor :warning
16
+
17
+ # Glob pattern to match example files. (default is 'examples/**/*_example.rb')
18
+ attr_accessor :pattern
19
+
20
+ # Array of commandline options to pass to ruby. Defaults to [].
21
+ attr_accessor :ruby_opts
22
+
23
+ # Whether or not to fail Rake when an error occurs (typically when examples fail).
24
+ # Defaults to true.
25
+ attr_accessor :fail_on_error
26
+
27
+ # A message to print to stderr when there are failures.
28
+ attr_accessor :failure_message
29
+
30
+ # Use verbose output. If this is set to true, the task will print
31
+ # the executed spec command to stdout. Defaults to false.
32
+ attr_accessor :verbose
33
+
34
+ # Use rcov for code coverage? defaults to false
35
+ attr_accessor :rcov
36
+
37
+ # The options to pass to rcov. Defaults to blank
38
+ attr_accessor :rcov_opts
39
+
40
+ def initialize(*args)
41
+ @name = args.shift || :examples
42
+ @pattern, @rcov_opts = nil, nil
43
+ @warning, @rcov = false, false
44
+ @ruby_opts = []
45
+ @fail_on_error = true
46
+
47
+ yield self if block_given?
48
+ @pattern ||= 'examples/**/*_example.rb'
49
+ define
50
+ end
51
+
52
+ def define # :nodoc:
53
+ actual_name = Hash === name ? name.keys.first : name
54
+ desc("Run all examples") unless ::Rake.application.last_comment
55
+
56
+ task name do
57
+ RakeFileUtils.verbose(verbose) do
58
+ if examples_to_run.empty?
59
+ puts "No examples matching #{pattern} could be found"
60
+ else
61
+ cmd_parts = [rcov ? 'rcov' : RUBY]
62
+ cmd_parts += rcov ? [rcov_opts] : ruby_opts
63
+ cmd_parts << "-w" if warning
64
+ cmd_parts += examples_to_run.collect { |fn| %["#{fn}"] }
65
+ cmd = cmd_parts.join(" ")
66
+ puts cmd if verbose
67
+ unless system(cmd)
68
+ STDERR.puts failure_message if failure_message
69
+ raise("Command #{cmd} failed") if fail_on_error
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ self
76
+ end
77
+
78
+ def examples_to_run # :nodoc:
79
+ FileList[ pattern ].to_a
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -38,9 +38,11 @@ module Micronaut
38
38
 
39
39
  formatter.start(total_examples_to_run) # start the clock
40
40
  start = Time.now
41
+
41
42
  Micronaut.world.behaviours_to_run.each do |behaviour|
42
43
  suite_success &= behaviour.run(formatter)
43
44
  end
45
+
44
46
  formatter.start_dump(Time.now - start)
45
47
 
46
48
  formatter.dump_failures
@@ -55,4 +57,4 @@ module Micronaut
55
57
 
56
58
  end
57
59
 
58
- end
60
+ 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.8.2
4
+ version: 0.1.8.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-30 00:00:00 -08:00
12
+ date: 2009-01-03 00:00:00 -08:00
13
13
  default_executable: micronaut
14
14
  dependencies: []
15
15
 
@@ -72,6 +72,7 @@ files:
72
72
  - lib/micronaut/mocking/with_absolutely_nothing.rb
73
73
  - lib/micronaut/mocking/with_mocha.rb
74
74
  - lib/micronaut/mocking/with_rr.rb
75
+ - lib/micronaut/rake_task.rb
75
76
  - lib/micronaut/runner.rb
76
77
  - lib/micronaut/world.rb
77
78
  - lib/micronaut.rb