Permalink
Browse files

Cleaning & fix tests

  • Loading branch information...
1 parent 1b5c347 commit 76bb603b10e997f763f9f5ffab1b282b59386340 @rymai rymai committed Feb 20, 2013
Showing with 29 additions and 25 deletions.
  1. +0 −1 Guardfile
  2. +1 −1 README.md
  3. +9 −9 lib/guard/minitest.rb
  4. +1 −1 lib/guard/minitest/notifier.rb
  5. +3 −3 spec/guard/minitest/notifier_spec.rb
  6. +14 −8 spec/guard/minitest_spec.rb
  7. +1 −2 spec/spec_helper.rb
View
1 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
-
View
2 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
View
18 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
View
2 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
View
6 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
)
View
22 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
View
3 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)

0 comments on commit 76bb603

Please sign in to comment.