Skip to content

Commit

Permalink
AboutUsingBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Aug 31, 2010
1 parent 838c92a commit 6585ab0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions koans/about_sandwich_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def count_lines(file_name)
end

def test_counting_lines
assert_equal __, count_lines("example_file.txt")
assert_equal 4, count_lines("example_file.txt")
end

# ------------------------------------------------------------------
Expand All @@ -29,7 +29,7 @@ def find_line(file_name)
end

def test_finding_lines
assert_equal __, find_line("example_file.txt")
assert_equal "test\n", find_line("example_file.txt")
end

# ------------------------------------------------------------------
Expand Down Expand Up @@ -74,17 +74,22 @@ def count_lines2(file_name)
end

def test_counting_lines2
assert_equal __, count_lines2("example_file.txt")
assert_equal 4, count_lines2("example_file.txt")
end

# ------------------------------------------------------------------

def find_line2(file_name)
# Rewrite find_line using the file_sandwich library function.
file_sandwich(file_name) do |file|
while line = file.gets
return line if line.match(/e/)
end
end
end

def test_finding_lines2
assert_equal __, find_line2("example_file.txt")
assert_equal "test\n", find_line2("example_file.txt")
end

# ------------------------------------------------------------------
Expand All @@ -100,7 +105,7 @@ def count_lines3(file_name)
end

def test_open_handles_the_file_sandwich_when_given_a_block
assert_equal __, count_lines3("example_file.txt")
assert_equal 4, count_lines3("example_file.txt")
end

end

0 comments on commit 6585ab0

Please sign in to comment.