forked from mendicant-original/puzzlenode
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6daeaa
commit 69c2327
Showing
1 changed file
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |