Skip to content

Commit

Permalink
Cleaning & fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rymai committed Feb 20, 2013
1 parent 1b5c347 commit 76bb603
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
1 change: 0 additions & 1 deletion Guardfile
Expand Up @@ -3,4 +3,3 @@ guard 'minitest' do
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r|^spec/spec_helper\.rb|) { 'spec' } watch(%r|^spec/spec_helper\.rb|) { 'spec' }
end end

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -96,7 +96,7 @@ end
:drb => true # enable DRb support, default: false :drb => true # enable DRb support, default: false
:test_folders => ['tests'] # specify an array of paths that contain test files, default: %w[test spec] :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] :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 ## Development
Expand Down
18 changes: 9 additions & 9 deletions lib/guard/minitest.rb
@@ -1,6 +1,7 @@
# encoding: utf-8 # encoding: utf-8
require 'guard' require 'guard'
require 'guard/guard' require 'guard/guard'
require 'minitest/unit'


module Guard module Guard
class Minitest < Guard class Minitest < Guard
Expand All @@ -10,16 +11,17 @@ class Minitest < Guard


def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})
super 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) @inspector = Inspector.new(@runner.test_folders, @runner.test_file_patterns)
if options[:all_on_start]
run_all
end
end end


def start def start
true UI.info "Guard::Minitest is running, with Minitest::Unit #{::MiniTest::Unit::VERSION}!"
run_all if @options[:all_on_start]
end end


def stop def stop
Expand All @@ -32,14 +34,12 @@ def reload


def run_all def run_all
paths = @inspector.clean_all paths = @inspector.clean_all
return @runner.run(paths, :message => 'Running all tests') unless paths.empty? @runner.run(paths, :message => 'Running all tests')
true
end end


def run_on_changes(paths = []) def run_on_changes(paths = [])
paths = @inspector.clean(paths) paths = @inspector.clean(paths)
return @runner.run(paths) unless paths.empty? @runner.run(paths)
true
end end
end end
end end
2 changes: 1 addition & 1 deletion lib/guard/minitest/notifier.rb
Expand Up @@ -11,7 +11,7 @@ def self.guard_message(test_count, assertion_count, failure_count, error_count,
end end
message << "\n#{assertion_count} assertions, #{failure_count} failures, #{error_count} errors" message << "\n#{assertion_count} assertions, #{failure_count} failures, #{error_count} errors"
if test_count && assertion_count 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 end
message message
end end
Expand Down
6 changes: 3 additions & 3 deletions spec/guard/minitest/notifier_spec.rb
Expand Up @@ -7,12 +7,12 @@


it 'should format message without skipped test' do it 'should format message without skipped test' do
message = subject.guard_message(1, 2, 3, 4, 0, 10.0) 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 end


it 'should format message with skipped test' do it 'should format message with skipped test' do
message = subject.guard_message(1, 2, 3, 4, 5, 10.0) 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 end


it 'should select failed image' do it 'should select failed image' do
Expand All @@ -30,7 +30,7 @@


it 'should call Guard::Notifier' do it 'should call Guard::Notifier' do
::Guard::Notifier.expects(:notify).with( ::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', :title => 'MiniTest results',
:image => :success :image => :success
) )
Expand Down
22 changes: 14 additions & 8 deletions spec/guard/minitest_spec.rb
Expand Up @@ -21,15 +21,10 @@
describe 'initialization' do describe 'initialization' do


it 'should initialize runner with options' 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 subject.new
end 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 it 'should initialize inspector with options' do
Guard::Minitest::Inspector.expects(:new).with(runner.test_folders, runner.test_file_patterns).returns(inspector) Guard::Minitest::Inspector.expects(:new).with(runner.test_folders, runner.test_file_patterns).returns(inspector)
subject.new subject.new
Expand All @@ -39,10 +34,21 @@


describe 'start' do describe 'start' do


it 'should return true' do it 'should run all tests at start' do
guard.start.must_equal true subject.any_instance.expects(:run_all)

guard.start
end 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 end


describe 'stop' do describe 'stop' do
Expand Down
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Expand Up @@ -3,16 +3,15 @@
require 'mocha/setup' require 'mocha/setup'


require 'guard/minitest' require 'guard/minitest'
ENV["GUARD_ENV"] = 'test'


class MiniTest::Spec < MiniTest::Unit::TestCase class MiniTest::Spec < MiniTest::Unit::TestCase


before(:each) do before(:each) do
ENV['GUARD_ENV'] = 'test'
@real_minitest_version = MiniTest::Unit::VERSION.dup @real_minitest_version = MiniTest::Unit::VERSION.dup
end end


after(:each) do after(:each) do
ENV['GUARD_ENV'] = nil
@_memoized = nil @_memoized = nil


if MiniTest::Unit.const_defined?(:VERSION) if MiniTest::Unit.const_defined?(:VERSION)
Expand Down

0 comments on commit 76bb603

Please sign in to comment.