From 76bb603b10e997f763f9f5ffab1b282b59386340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 21 Feb 2013 00:21:08 +0100 Subject: [PATCH] Cleaning & fix tests --- Guardfile | 1 - README.md | 2 +- lib/guard/minitest.rb | 18 +++++++++--------- lib/guard/minitest/notifier.rb | 2 +- spec/guard/minitest/notifier_spec.rb | 6 +++--- spec/guard/minitest_spec.rb | 22 ++++++++++++++-------- spec/spec_helper.rb | 3 +-- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Guardfile b/Guardfile index 012b7d1..2b32422 100644 --- a/Guardfile +++ b/Guardfile @@ -3,4 +3,3 @@ guard 'minitest' do watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } watch(%r|^spec/spec_helper\.rb|) { 'spec' } end - diff --git a/README.md b/README.md index 13aab11..218c4a9 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ end :drb => true # enable DRb support, default: false :test_folders => ['tests'] # specify an array of paths that contain test files, default: %w[test spec] :test_file_patterns => true # specify an array of patterns that test files must match in order to be run, default: %w[*_test.rb test_*.rb *_spec.rb] -:all_on_start => true # run all tests in group on startup, default: false +:all_on_start => false # run all tests in group on startup, default: true ``` ## Development diff --git a/lib/guard/minitest.rb b/lib/guard/minitest.rb index f8fe794..43d1f57 100644 --- a/lib/guard/minitest.rb +++ b/lib/guard/minitest.rb @@ -1,6 +1,7 @@ # encoding: utf-8 require 'guard' require 'guard/guard' +require 'minitest/unit' module Guard class Minitest < Guard @@ -10,16 +11,17 @@ class Minitest < Guard def initialize(watchers = [], options = {}) super + @options = { + :all_on_start => true + }.merge(options) - @runner = Runner.new(options) + @runner = Runner.new(@options) @inspector = Inspector.new(@runner.test_folders, @runner.test_file_patterns) - if options[:all_on_start] - run_all - end end def start - true + UI.info "Guard::Minitest is running, with Minitest::Unit #{::MiniTest::Unit::VERSION}!" + run_all if @options[:all_on_start] end def stop @@ -32,14 +34,12 @@ def reload def run_all paths = @inspector.clean_all - return @runner.run(paths, :message => 'Running all tests') unless paths.empty? - true + @runner.run(paths, :message => 'Running all tests') end def run_on_changes(paths = []) paths = @inspector.clean(paths) - return @runner.run(paths) unless paths.empty? - true + @runner.run(paths) end end end diff --git a/lib/guard/minitest/notifier.rb b/lib/guard/minitest/notifier.rb index 3887df1..ef76d8d 100644 --- a/lib/guard/minitest/notifier.rb +++ b/lib/guard/minitest/notifier.rb @@ -11,7 +11,7 @@ def self.guard_message(test_count, assertion_count, failure_count, error_count, end message << "\n#{assertion_count} assertions, #{failure_count} failures, #{error_count} errors" if test_count && assertion_count - message << "\n\n%.2f tests/s \n%.2f assertions/s.\n\nFinished in %.6f seconds" % [ test_count / duration, assertion_count / duration, duration] + message << "\n\n%.2f tests/s, %.2f assertions/s\n\nFinished in %.4f seconds" % [ test_count / duration, assertion_count / duration, duration] end message end diff --git a/spec/guard/minitest/notifier_spec.rb b/spec/guard/minitest/notifier_spec.rb index fd02c34..b8a0976 100644 --- a/spec/guard/minitest/notifier_spec.rb +++ b/spec/guard/minitest/notifier_spec.rb @@ -7,12 +7,12 @@ it 'should format message without skipped test' do message = subject.guard_message(1, 2, 3, 4, 0, 10.0) - message.must_equal "1 examples, 2 assertions, 3 failures, 4 errors\nin 10.000000 seconds, 0.1000 tests/s, 0.2000 assertions/s." + message.must_equal "1 tests\n2 assertions, 3 failures, 4 errors\n\n0.10 tests/s, 0.20 assertions/s\n\nFinished in 10.0000 seconds" end it 'should format message with skipped test' do message = subject.guard_message(1, 2, 3, 4, 5, 10.0) - message.must_equal "1 examples, 2 assertions, 3 failures, 4 errors (5 skips)\nin 10.000000 seconds, 0.1000 tests/s, 0.2000 assertions/s." + message.must_equal "1 tests (5 skipped)\n2 assertions, 3 failures, 4 errors\n\n0.10 tests/s, 0.20 assertions/s\n\nFinished in 10.0000 seconds" end it 'should select failed image' do @@ -30,7 +30,7 @@ it 'should call Guard::Notifier' do ::Guard::Notifier.expects(:notify).with( - "1 examples, 2 assertions, 0 failures, 0 errors\nin 10.000000 seconds, 0.1000 tests/s, 0.2000 assertions/s.", + "1 tests\n2 assertions, 0 failures, 0 errors\n\n0.10 tests/s, 0.20 assertions/s\n\nFinished in 10.0000 seconds", :title => 'MiniTest results', :image => :success ) diff --git a/spec/guard/minitest_spec.rb b/spec/guard/minitest_spec.rb index c6c2e77..5f55aae 100644 --- a/spec/guard/minitest_spec.rb +++ b/spec/guard/minitest_spec.rb @@ -21,15 +21,10 @@ describe 'initialization' do it 'should initialize runner with options' do - Guard::Minitest::Runner.expects(:new).with({}).returns(runner) + Guard::Minitest::Runner.expects(:new).with({ :all_on_start => true }).returns(runner) subject.new end - it 'should run all tests if you pass options[:run_all_on_start]' do - subject.any_instance.expects(:run_all) - subject.new([], {all_on_start: true}) - end - it 'should initialize inspector with options' do Guard::Minitest::Inspector.expects(:new).with(runner.test_folders, runner.test_file_patterns).returns(inspector) subject.new @@ -39,10 +34,21 @@ describe 'start' do - it 'should return true' do - guard.start.must_equal true + it 'should run all tests at start' do + subject.any_instance.expects(:run_all) + + guard.start end + # FIXME + # it 'should not run all tests if you pass :run_all_on_start => false' do + # subject.any_instance.expects(:run_all) + # subject.new([], { :all_on_start => false }) + # assert_raises(MockExpectationError, "update should not be called") do + # subject.any_instance.verify + # end + # end + end describe 'stop' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4804a2..e057220 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,16 +3,15 @@ require 'mocha/setup' require 'guard/minitest' +ENV["GUARD_ENV"] = 'test' class MiniTest::Spec < MiniTest::Unit::TestCase before(:each) do - ENV['GUARD_ENV'] = 'test' @real_minitest_version = MiniTest::Unit::VERSION.dup end after(:each) do - ENV['GUARD_ENV'] = nil @_memoized = nil if MiniTest::Unit.const_defined?(:VERSION)