Sha256: 9faf7b461968512f481d82c4ec972881ca55ade62df8c9b5d2d9d03b9142b1ae

Contents?: true

Size: 1.88 KB

Versions: 14

Compression:

Stored size: 1.88 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
      alias_method :ad, :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
      alias_method :at, :add_test

      def save_as(file_path)
        IRT.save_as(file_path)
      end
      alias_method :sa, :save_as

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
irt-1.3.3 lib/irt/commands/test.rb
irt-1.3.2 lib/irt/commands/test.rb
irt-1.3.1 lib/irt/commands/test.rb
irt-1.3.0 lib/irt/commands/test.rb
irt-1.2.12 lib/irt/commands/test.rb
irt-1.2.11 lib/irt/commands/test.rb
irt-1.2.10 lib/irt/commands/test.rb
irt-1.2.9 lib/irt/commands/test.rb
irt-1.2.8 lib/irt/commands/test.rb
irt-1.2.7 lib/irt/commands/test.rb
irt-1.2.6 lib/irt/commands/test.rb
irt-1.2.5 lib/irt/commands/test.rb
irt-1.2.4 lib/irt/commands/test.rb
irt-1.2.3 lib/irt/commands/test.rb