Permalink
Browse files

try out an inject instead

  • Loading branch information...
1 parent 5a5743c commit a8f7ba91a96b4b7d166f0ffee2c006efc89d10fd @qrush committed Jan 12, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/m/runner.rb
View
@@ -30,10 +30,11 @@ def run
message = "No tests found on line #{@line}. Valid tests to run:\n\n"
# For every test ordered by line number,
+ # spit out the test name and line number where it starts,
tests.by_line_number do |test|
- # spit out the test name and line number where it starts,
message << "#{sprintf("%0#{tests.column_size}s", test.name)}: m #{@file}:#{test.start_line}\n"
end
+
# fail like a good unix process should.
abort message
end
@@ -62,20 +63,19 @@ def suites
end
end
- # Shoves tests together in our custom container and collection classes
+ # Shoves tests together in our custom container and collection classes.
+ # Memoize it since it's unnecessary to do this more than one for a given file.
def tests
- # Memoize it since it's unnecessary to do this more than one for a given file
@tests ||= begin
- collection = TestCollection.new
# With each suite and array of tests,
- suites.each do |suite_class, test_methods|
- # And with each test method present in this test file,
+ # and with each test method present in this test file,
+ # shove a new test method into this collection.
+ suites.inject(TestCollection.new) do |collection, (suite_class, test_methods)|
test_methods.each do |test_method|
- # Shove a new test method into this collection
collection << TestMethod.create(suite_class, test_method)
end
+ collection
end
- collection
end
end
end

0 comments on commit a8f7ba9

Please sign in to comment.