lib/tryouts.rb in tryouts-0.7.2 vs lib/tryouts.rb in tryouts-0.7.3

- old
+ new

@@ -39,11 +39,11 @@ vdt = Tryouts::Drill.valid_dtypes "Tryout '#{@tname}' has no drill type. Should be: #{vdt.join(', ')}" end end - VERSION = "0.7.2" + VERSION = "0.7.3" require 'tryouts/mixins' require 'tryouts/tryout' require 'tryouts/drill' require 'tryouts/stats' @@ -138,19 +138,27 @@ end # Require +name+. If +path+ is supplied, it will "require path". # * +name+ The name of the library in question (required). Stored as a Symbol to +@library+. # * +path+ Add a path to the front of $LOAD_PATH (optional). Use this if you want to load - # a specific copy of the library. Otherwise, it loads from the system path. - def library(name=nil, path=nil) + # a specific copy of the library. Otherwise, it loads from the system path. If the path + # in specified in multiple arguments they are joined and expanded. + # + # library '/an/absolute/path' + # library __FILE__, '..', 'lib' + # + def library(name=nil, *path) return @library if name.nil? - @library = name.to_sym - @dtype = :api + @library, @dtype = name.to_sym, :api + path = File.expand_path(File.join *path) $LOAD_PATH.unshift path unless path.nil? begin require @library.to_s - rescue SyntaxError, LoadError, Exception, TypeError, + rescue LoadError => ex + @errors << ex.exception("Cannot load library: #{@library} (#{path})") + Tryouts.failed = true + rescue SyntaxError, Exception, TypeError, RuntimeError, NoMethodError, NameError => ex @errors << ex Tryouts.failed = true end end @@ -239,10 +247,20 @@ # An alias for Tryouts.tryout. def self.tryouts(*args, &block) tryout(args, &block) end + # This method does nothing. It provides a quick way to disable a tryout. + # + # NOTE: This is a DSL-only method and is not intended for OO use. + def xtryouts(*args, &block); end + # This method does nothing. It provides a quick way to disable a tryout. + # + # NOTE: this is a standalone DSL-syntax method. + def self.xtryouts(*args, &block); end + + # Parse a +_tryouts.rb+ file. See Tryouts::CLI::Run for an example. # # NOTE: this is an OO syntax method def self.parse_file(fpath) raise "No such file: #{fpath}" unless File.exists?(fpath) @@ -260,9 +278,15 @@ end rescue SyntaxError, LoadError, Exception, TypeError, RuntimeError, NoMethodError, NameError => ex to.errors << ex Tryouts.failed = true + # It's helpful to display the group name + file_content.match(/^group (.+?)$/) do |x,t| + # We use eval as a quick cheat so we don't have + # to parse all the various kinds of quotes. + to.group = eval x.captures.first + end end @@instances[to.group] = to to end