Skip to content

Commit

Permalink
These tests, they suck
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Feb 2, 2011
1 parent f6daeaa commit 69c2327
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions test/unit/puzzle_test.rb
@@ -1,8 +1,45 @@
require 'test_helper'

class PuzzleTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
test "Puzzle#file= should write a SHA1 fingerprint" do
tempfile = Tempfile.new("puzzle_sample")
tempfile << "Sample Text"
tempfile.rewind

expected_fingerprint = Digest::SHA1.hexdigest(tempfile.read)
tempfile.rewind

puzzle = Puzzle.new(:file => tempfile)

assert_equal expected_fingerprint, puzzle.fingerprint
end

test "puzzle#valid_solution? should return true if contents match" do
seed_tempfile = Tempfile.new("puzzle_sample")
seed_tempfile << "sample text"
seed_tempfile.rewind

test_tempfile = Tempfile.new("puzzle_sample2")
test_tempfile << "sample text"
test_tempfile.rewind

puzzle = Puzzle.new(:file => seed_tempfile)

assert puzzle.valid_solution?(test_tempfile)
end

test "puzzle#valid_solution? should return false if contents don't match" do
seed_tempfile = Tempfile.new("puzzle_sample")
seed_tempfile << "sample text"
seed_tempfile.rewind

test_tempfile = Tempfile.new("puzzle_sample2")
test_tempfile << "wow, this totally doesn't match, buddy"
test_tempfile.rewind

puzzle = Puzzle.new(:file => seed_tempfile)

assert !puzzle.valid_solution?(test_tempfile)
end

end

0 comments on commit 69c2327

Please sign in to comment.