Class: Test::Spec::Should

### Home Classes Methods

### In Files

- lib/test/spec/should-output.rb
- lib/test/spec.rb

### Parent

Object

### Methods

- ::new
- #<
- #<=
- #==
- #===
- #=~
- #>
- #>=
- #_raise
- #a
- #add_assertion
- #an
- #be
- #blaming
- #close
- #equal
- #include
- #instance_of
- #kind_of
- #match
- #messaging
- #method_missing
- #nil
- #not
- #output
- #pass
- #respond_to
- #satisfy
- #throw

### Included Modules

- Test::Unit::Assertions

### Files

- README
- ROADMAP
- SPECS

### Class/Module Index

Quicksearch

- Test
- Test::Spec
- Test::Spec::CustomShould
- Test::Spec::DefinitionError
- Test::Spec::Should
- Test::Spec::ShouldNot
- Test::Spec::TestCase
- Test::Spec::TestCase::ClassMethods
- Test::Spec::TestCase::InstanceMethods
- Test::Unit
- Test::Unit::UI
- Test::Unit::UI::RDox
- Test::Unit::UI::RDox::TestRunner
- Test::Unit::UI::SpecDox
- Test::Unit::UI::SpecDox::TestRunner
- Object

No matching classes.

# Test::Spec::Should

### Public Class Methods

new(object, message=nil) click to toggle source

    # File lib/test/spec.rb, line 45
    def initialize(object, message=nil)
      @object = object
      @message = message
    end

### Public Instance Methods

<(value) click to toggle source

    # File lib/test/spec.rb, line 162
    def <(value)
      assert_operator @object, :<, value, @message
    end

<=(value) click to toggle source

    # File lib/test/spec.rb, line 166
    def <=(value)
      assert_operator @object, :<=, value, @message
    end

==(value) click to toggle source
Alias for: equal
===(value) click to toggle source

    # File lib/test/spec.rb, line 170
    def ===(value)
      assert_operator @object, :===, value, @message
    end

=~(value) click to toggle source
Alias for: match
>(value) click to toggle source

    # File lib/test/spec.rb, line 154
    def >(value)
      assert_operator @object, :>, value, @message
    end

>=(value) click to toggle source

    # File lib/test/spec.rb, line 158
    def >=(value)
      assert_operator @object, :>=, value, @message
    end

_raise(*args, &block) click to toggle source

    # File lib/test/spec.rb, line 131
    def _raise(*args, &block)
      args = [RuntimeError]  if args.empty?
      block ||= @object
      args << @message  if @message
      assert_raise(*args, &block)
    end

a() click to toggle source

    # File lib/test/spec.rb, line 60
    def a
      self
    end

add_assertion() click to toggle source

    # File lib/test/spec.rb, line 51
    def add_assertion
      $TEST_SPEC_TESTCASE && $TEST_SPEC_TESTCASE.__send__(:add_assertion)
    end

an() click to toggle source

    # File lib/test/spec.rb, line 56
    def an
      self
    end

be(*value) click to toggle source

    # File lib/test/spec.rb, line 97
    def be(*value)
      case value.size
      when 0
        self
      when 1
        if CustomShould === value.first
          pass value.first
        else
          assert_same value.first, @object, @message
        end
      else
        raise ArgumentError, "should.be needs zero or one argument"
      end
    end

blaming(message) click to toggle source
Alias for: messaging
close(value, delta) click to toggle source

    # File lib/test/spec.rb, line 92
    def close(value, delta)
      assert_in_delta value, @object, delta, @message
    end

equal(value) click to toggle source

    # File lib/test/spec.rb, line 87
    def equal(value)
      assert_equal value, @object, @message
    end

Also aliased as: ==
include(value) click to toggle source

    # File lib/test/spec.rb, line 148
    def include(value)
      msg = build_message(@message, "<?> expected to include ?, but it didn't.",
                          @object, value)
      assert_block(msg) { @object.include?(value) }
    end

instance_of(klass) click to toggle source

    # File lib/test/spec.rb, line 117
    def instance_of(klass)
      assert_instance_of klass, @object, @message
    end

kind_of(klass) click to toggle source

    # File lib/test/spec.rb, line 122
    def kind_of(klass)
      assert_kind_of klass, @object, @message
    end

match(value) click to toggle source

    # File lib/test/spec.rb, line 112
    def match(value)
      assert_match value, @object, @message
    end

Also aliased as: =~
messaging(message) click to toggle source

    # File lib/test/spec.rb, line 75
    def messaging(message)
      @message = message.to_s
      self
    end

Also aliased as: blaming
method_missing(name, *args, &block) click to toggle source

    # File lib/test/spec.rb, line 183
    def method_missing(name, *args, &block)
      # This will make raise call Kernel.raise, and self.raise call _raise.
      return _raise(*args, &block)  if name == :raise

      if @object.respond_to?("#{name}?")
        assert @object.__send__("#{name}?", *args),
          "#{name}? expected to be true. #{@message}"
      else
        if @object.respond_to?(name)
          assert @object.__send__(name, *args),
          "#{name} expected to be true. #{@message}"
        else
          super
        end
      end
    end

nil() click to toggle source

    # File lib/test/spec.rb, line 142
    def nil
      assert_nil @object, @message
    end

not(*args) click to toggle source

    # File lib/test/spec.rb, line 64
    def not(*args)
      case args.size
      when 0
        ShouldNot.new(@object, @message)
      when 1
        ShouldNot.new(@object, @message).pass(args.first)
      else
        raise ArgumentError, "#not takes zero or one argument(s)."
      end
    end

output(expected, to = STDOUT) click to toggle source

Captures output from the IO given as the second argument (STDIN by default) and matches it against a String or Regexp given as the first argument.

    # File lib/test/spec/should-output.rb, line 10
    def output(expected, to = STDOUT)
      # Store the old stream
      old_to = to.dup

      # Obtain a filehandle to replace (works with Readline)
      to.reopen File.open(File.join(Dir.tmpdir, "should_output_#{$$}"), "w+")

      # Execute
      @object.call

      # Restore
      out = to.dup
      to.reopen old_to

      # Grab the data
      out.rewind
      output = out.read

      # Match up
      case expected
        when Regexp
          output.should.match expected
        else
          output.should.equal expected
      end                               # case expected

    # Clean up
    ensure
      out.close

      # STDIO redirection will break else
      begin
        to.seek 0, IO::SEEK_END
      rescue Errno::ESPIPE
      rescue Errno::EPIPE
      end

      FileUtils.rm_f out.path
    end

pass(custom) click to toggle source

    # File lib/test/spec.rb, line 174
    def pass(custom)
      _wrap_assertion {
        assert_nothing_raised(Test::Unit::AssertionFailedError,
                              @message || custom.failure_message) {
          assert custom.matches?(@object), @message || custom.failure_message
        }
      }
    end

respond_to(method) click to toggle source

    # File lib/test/spec.rb, line 127
    def respond_to(method)
      assert_respond_to @object, method, @message
    end

satisfy(&block) click to toggle source

    # File lib/test/spec.rb, line 81
    def satisfy(&block)
      assert_block(@message || "satisfy block failed.") {
        yield @object
      }
    end

throw(sym) click to toggle source

    # File lib/test/spec.rb, line 138
    def throw(sym)
      assert_throws(sym, @message, &@object)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.