Sha256: c69ab937a037e0cbc8172377685e5d9e29411a0c4fc3ada54bd695725efba1f4

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

module IRT
  module Commands
    module Test

      extend self

      def add_desc(description)
        mode = context.irt_mode
        raise IRT::SessionModeError, "You cannot add a test description in #{mode} mode." unless mode == :interactive
        desc_str = %(desc "#{description}")
        context.current_line = desc_str
        puts
        puts IRT.dye(desc_str, :interactive_color)
        puts
      end
      alias_method :dd, :add_desc

      def add_test(description='')
        mode = context.irt_mode
        raise IRT::SessionModeError, "You cannot add a test in #{mode} mode." unless mode == :interactive
        last_value = context.last_value
        begin
          evaled = context.workspace.evaluate(self, last_value.inspect)
        rescue Exception
        end
        # the eval of the last_value.inspect == the last_value
        test_str = if evaled == last_value
                     # same as _? but easier to read for multiline strings
                     if last_value.is_a?(String) && last_value.match(/\n/)
                       str = last_value.split("\n").map{|l| l.inspect.sub(/^"(.*)"$/,'\1') }.join("\n")
                       last_value.match(/\n$/) ? "_eql? <<EOS\n#{str}\nEOS" : "_eql? %(#{str})"
                     else
                       "_eql?( #{last_value.inspect} )"
                     end
                   else # need YAML
                     "_yaml_eql? %(#{IRT.yaml_dump(last_value)})"
                   end
        desc_str = description.empty? ? '' : %(desc "#{description}"\n)
        str = desc_str + test_str
        context.current_line = str
        puts
        puts IRT.dye(str, :interactive_color)
        puts
      end
      alias_method :tt, :add_test

      def save_as(path)
        IRT::Utils.save_as(path) do |as_file|
          IRT::Session.run_file as_file
        end
      end
      alias_method :sa, :save_as

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
irt-1.2.0 lib/irt/commands/test.rb
irt-1.2.0.p02 lib/irt/commands/test.rb