spec/spec_helper.rb in optimus-ep-0.6.91 vs spec/spec_helper.rb in optimus-ep-0.8.0
- old
+ new
@@ -1,47 +1,110 @@
# Part of the Optimus package for managing E-Prime data
#
-# Copyright (C) 2008 Board of Regents of the University of Wisconsin System
+# Copyright (C) 2008-09 Board of Regents of the University of Wisconsin System
#
# Written by Nathan Vack <njvack@wisc.edu>, at the Waisman Laborotory for Brain
# Imaging and Behavior, University of Wisconsin - Madison
-module EprimeTestHelper
+module OptimusTestHelper
- class RoundTrip
- def initialize(expected)
+ class ParseAs
+ def initialize(parse_str, expected)
+ @parse_str = parse_str
@expected = expected
end
def matches?(target)
- @parsed = target.parse(@expected).to_s
- @parsed == @expected
+ @parsed = target.parse(@parse_str).to_s
+ return (@parsed == @expected)
end
def failure_message
- "expected #{@parsed} to parse to #{@expected}"
+ "expected #{@parse_str} to parse to #{@expected}, got #{@parsed}"
end
def negative_failure_message
- "Expected #{@parsed} to not parse to #{@expected}"
+ "expected #{@parse_str} not to parse to #{@expected}."
end
end
+ def parse_as(parse_str, expected)
+ ParseAs.new(parse_str, expected)
+ end
+
def round_trip(expected)
- RoundTrip.new(expected)
+ ParseAs.new(expected, expected)
end
+ class ParseSuccessfully
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(target)
+ begin
+ @parsed = target.parse(@expected)
+ rescue RParsec::ParserException => e
+ @message = e.message
+ return false
+ end
+ return true
+ end
+
+ def failure_message
+ "expected #{@expected} to parse; raised #{@message}"
+ end
+
+ def negative_failure_message
+ "expected #{@expected} not to parse"
+ end
+ end
+
+ def parse_successfully(expected)
+ ParseSuccessfully.new(expected)
+ end
+
+ class EvaluateTo
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(target)
+ @target = target
+ @result = target.evaluate
+ return ((@result == @expected) or (is_NaN(@result) and is_NaN(@expected)))
+ end
+
+ def failure_message
+ "#{@target.to_s} expected to evaluate to #{@expected.inspect}; actual: #{@result.inspect}"
+ end
+
+ def negative_failure_message
+ "#{@target.to_s} expected to NOT evaluate to #{@expected}"
+ end
+
+ private
+ def is_NaN(obj)
+ obj.respond_to? :nan? and obj.nan?
+ end
+ end
+
+ def evaluate_to(expected)
+ EvaluateTo.new(expected)
+ end
+
unless constants.include?('SAMPLE_DIR')
SAMPLE_DIR = File.join(File.dirname(__FILE__), 'samples')
LOG_FILE = File.join(SAMPLE_DIR, 'optimus_log.txt')
EXCEL_FILE = File.join(SAMPLE_DIR, 'excel_tsv.txt')
BAD_EXCEL_FILE = File.join(SAMPLE_DIR, 'bad_excel_tsv.txt')
EPRIME_FILE = File.join(SAMPLE_DIR, 'eprime_tsv.txt')
RAW_TSV_FILE = File.join(SAMPLE_DIR, 'raw_tsv.txt')
UNKNOWN_FILE = File.join(SAMPLE_DIR, 'unknown_type.txt')
UNREADABLE_FILE = File.join(SAMPLE_DIR, 'unreadable_file')
CORRUPT_LOG_FILE = File.join(SAMPLE_DIR, 'corrupt_log_file.txt')
+ UTF16LE_FILE = File.join(SAMPLE_DIR, 'optimus_log_utf16le.txt')
STD_COLUMNS = ["ExperimentName", "Subject", "Session", "RFP.StartTime", "BlockTitle", "PeriodA", "CarriedVal[Session]", "BlockList", "Trial",
"NameOfPeriodList", "NumPeriods", "PeriodB", "Procedure[Block]", "Block", "Group",
"CarriedVal[Block]", "BlockList.Sample", "SessionTime", "Clock.Scale", "BlockList.Cycle",
@@ -73,12 +136,12 @@
}
end
- def mock_eprime(col_count, row_count)
- data = Eprime::Data.new()
+ def mock_optimus(col_count, row_count)
+ data = Optimus::Data.new()
1.upto(row_count) do |rownum|
row = data.add_row
1.upto(col_count) do |colnum|
unless (rownum == row_count and colnum > 1)
# Leave some blanks in the last row
@@ -88,10 +151,10 @@
end
return data
end
def mock_edata
- data = Eprime::Data.new()
+ data = Optimus::Data.new()
row = data.add_row
row['stim_time'] = '3188'
row['run_start'] = '2400'
row['fix_time'] = '2803'
row = data.add_row
\ No newline at end of file