Skip to content

Commit

Permalink
Changed 'context' to 'contexts'
Browse files Browse the repository at this point in the history
  • Loading branch information
bhb committed Oct 2, 2010
1 parent 65b5a36 commit a7ef507
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 38 deletions.
6 changes: 3 additions & 3 deletions lib/tack/adapters/shoulda_adapter.rb
Expand Up @@ -77,9 +77,9 @@ def tests_for(file)
tests += tests_for_class
end
tests.each do |test|
_, context, _ = test
context.first.sub!(Tack::Sandbox.prefix,'')
context.delete("")
_, contexts, _ = test
contexts.first.sub!(Tack::Sandbox.prefix,'')
contexts.delete("")
end
tests
ensure
Expand Down
18 changes: 9 additions & 9 deletions lib/tack/adapters/test_unit_adapter.rb
Expand Up @@ -26,41 +26,41 @@ def tests_for(file)
tests
end

def run(path, context, description)
def run(path, contexts, description)
results = Tack::ResultSet.new
test_classes_for(path).each do |klass|
if klass.to_s==context.first
run_tests_for_class(klass, path, context, description, results)
if klass.to_s==contexts.first
run_tests_for_class(klass, path, contexts, description, results)
end
end
basics(results)
end

private

def run_tests_for_class(klass, path, context, description, results)
def run_tests_for_class(klass, path, contexts, description, results)
begin
test = klass.new(description)
rescue NameError
raise NoMatchingTestError, Tack::Util::Test.new(path,context,description)
raise NoMatchingTestError, Tack::Util::Test.new(path,contexts,description)
end
result = ::Test::Unit::TestResult.new

result.add_listener(::Test::Unit::TestResult::FAULT) do |failure|
results.failed << build_result(path, context, description, failure)
results.failed << build_result(path, contexts, description, failure)
end

test.run(result) do |started,name|
# We do nothing here
# but this method requires a block
end
if result.passed?
results.passed << build_result(path, context, description)
results.passed << build_result(path, contexts, description)
end
end

def build_result(file, context, description, failure=nil)
{ :test => [file.to_s, context, description],
def build_result(file, contexts, description, failure=nil)
{ :test => [file.to_s, contexts, description],
:failure => build_failure(failure) }
end

Expand Down
5 changes: 3 additions & 2 deletions lib/tack/formatters/print_pending.rb
Expand Up @@ -8,8 +8,9 @@ class PrintPending
def run_suite(tests)
returning @app.run_suite(tests) do |results|
results[:pending].each do |result|
file, context, description = result[:test]
@output.puts "PENDING: #{[context<<description].join(" ")}"
file, contexts, description = result[:test]
# TODO - use Test#name
@output.puts "PENDING: #{[contexts<<description].join(" ")}"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tack/formatters/profiler.rb
Expand Up @@ -24,9 +24,9 @@ def run_suite(tests)
end
end

def run_test(file, context, description)
def run_test(file, contexts, description)
time = Time.now
returning @app.run_test(file, context, description) do
returning @app.run_test(file, contexts, description) do
@times << [description, Time.now - time]
end
end
Expand Down
7 changes: 4 additions & 3 deletions lib/tack/formatters/progress_bar.rb
Expand Up @@ -16,10 +16,11 @@ def run_suite(tests)
end
end

def run_test(file, context, description)
returning @app.run_test(file, context, description) do |result|
def run_test(file, contexts, description)
returning @app.run_test(file, contexts, description) do |result|
if @verbose
@output.print("#{context.join(' ')} #{description}: ")
# TODO - replace with Test#name
@output.print("#{contexts.join(' ')} #{description}: ")
end
print_char_for_results(result[:passed], '.')
print_char_for_results(result[:pending], 'P')
Expand Down
4 changes: 2 additions & 2 deletions lib/tack/middleware/base.rb
Expand Up @@ -13,8 +13,8 @@ def run_suite(tests)
@app.run_suite(tests)
end

def run_test(file, context, description)
@app.run_test(file, context, description)
def run_test(file, contexts, description)
@app.run_test(file, contexts, description)
end

# not necessary for the middleware API, but handy for
Expand Down
8 changes: 4 additions & 4 deletions lib/tack/middleware/fork.rb
Expand Up @@ -5,20 +5,20 @@ module Middleware
class Fork
include Middleware::Base

def run_test(file, context, description)
def run_test(file, contexts, description)
@reader, @writer = IO.pipe
if @child = fork
proceed_as_parent
else
proceed_as_child(file,context, description)
proceed_as_child(file,contexts, description)
end
end

private

def proceed_as_child(file, context, description)
def proceed_as_child(file, contexts, description)
@reader.close
result = @app.run_test(file, context, description)
result = @app.run_test(file, contexts, description)
Marshal.dump([:ok, result], @writer)
rescue Object => error
Marshal.dump([
Expand Down
4 changes: 2 additions & 2 deletions lib/tack/runner.rb
Expand Up @@ -27,8 +27,8 @@ def run(tests)

def run_suite(tests)
results = ResultSet.new
tests.each do |path, context, description|
result = @start_app.run_test(path, context, description)
tests.each do |path, contexts, description|
result = @start_app.run_test(path, contexts, description)
results.merge(result)
end
basics(results)
Expand Down
12 changes: 6 additions & 6 deletions lib/tack/test.rb
Expand Up @@ -4,29 +4,29 @@ module Util

class Test

attr_accessor :file, :context, :description
attr_accessor :file, :contexts, :description

def initialize(*args)
if args.length == 1
if args.first.is_a?(Hash)
opts = args.first
@file = opts.fetch(:file) {''}
@context = opts.fetch(:context) {[]}
@contexts = opts.fetch(:contexts) {[]}
@description = opts.fetch(:description) {''}
elsif args.first.is_a?(Enumerable)
@file, @context, @description = args.first
@file, @contexts, @description = args.first
end
else
@file, @context, @description = args
@file, @contexts, @description = args
end
end

def to_basics
[file, context, description].map {|x| basics(x)}
[file, contexts, description].map {|x| basics(x)}
end

def name
"#{context.join(' ')} #{description}"
"#{contexts.join(' ')} #{description}"
end

end
Expand Down
2 changes: 1 addition & 1 deletion test/blueprints.rb
Expand Up @@ -3,7 +3,7 @@

Tack::Util::Test.blueprint do
file 'foo.rb'
context ['FooTest']
contexts ['FooTest']
description 'test1'
end

Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_test.rb
Expand Up @@ -9,23 +9,23 @@ class TestTest < Test::Unit::TestCase
should "work with args" do
test = Test.new('file',['Class','context'],'description')
assert_equal 'file', test.file
assert_equal ['Class','context'], test.context
assert_equal ['Class','context'], test.contexts
assert_equal 'description', test.description
end

should "work with args array" do
test = Test.new(['file',['Class','context'],'description'])
assert_equal 'file', test.file
assert_equal ['Class','context'], test.context
assert_equal ['Class','context'], test.contexts
assert_equal 'description', test.description
end

should "work with args hash" do
test = Test.new(:file => 'file',
:context => ['Class','context'],
:contexts => ['Class','context'],
:description => 'description')
assert_equal 'file', test.file
assert_equal ['Class','context'], test.context
assert_equal ['Class','context'], test.contexts
assert_equal 'description', test.description
end

Expand Down

0 comments on commit a7ef507

Please sign in to comment.