Sha256: ed59c339e950969e71b03dde2a16c40c985120d37626cca753757896f8d9c1bb

Contents?: true

Size: 1.33 KB

Versions: 47

Compression:

Stored size: 1.33 KB

Contents

#! /usr/bin/ruby
#encoding: utf-8

require 'test/unit'
require 'shoulda'

class RespondToTest < Test::Unit::TestCase
  context "Object" do
    setup do
      require 'y_support/respond_to'
    end

    should "have RespondTo() constructor" do
      assert_equal RespondTo, RespondTo( :inspect ).class
    end
  end # context Object

  context "RespondTo" do
    should "work" do
      assert_respond_to( RespondTo.new(:hello), :=== )
      assert RespondTo.new(:each_char) === "arbitrary string"
      assert ! ( RespondTo.new(:each_char) === Object.new )
      assert ! ( RespondTo.new(:improbab_method_name) === Object.new )
      # Now testing the intended RespondTo usage in case statements.
      assert case ?x
             when RespondTo.new(:each_char) then 1
             else false end
      assert ! case ?x
               when RespondTo.new(:improbab_method_name) then 1
               else false end
    end
  end # context RespondTo

  context "Symbol" do
    should "have Symbol#~@ for .respond_to? case statements" do
      assert_kind_of RespondTo, ~:hello
      assert RespondTo(:<<) === "testing"
      assert case ?x
             when ~:each_char then 1
             else false end
      assert ! case ?x
               when ~:improbab_method_name then 1
               else false end
    end
  end # context Symbol
end # class RespondToTest

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
y_support-2.1.5 test/respond_to_test.rb
y_support-2.1.4 test/respond_to_test.rb
y_support-2.1.3 test/respond_to_test.rb
y_support-2.1.2 test/respond_to_test.rb
y_support-2.1.1 test/respond_to_test.rb
y_support-2.1.0 test/respond_to_test.rb
y_support-2.0.43 test/respond_to_test.rb
y_support-2.0.42 test/respond_to_test.rb
y_support-2.0.41 test/respond_to_test.rb
y_support-2.0.39 test/respond_to_test.rb
y_support-2.0.38 test/respond_to_test.rb
y_support-2.0.37 test/respond_to_test.rb
y_support-2.0.36 test/respond_to_test.rb
y_support-2.0.35 test/respond_to_test.rb
y_support-2.0.34 test/respond_to_test.rb
y_support-2.0.33 test/respond_to_test.rb
y_support-2.0.31 test/respond_to_test.rb
y_support-2.0.30 test/respond_to_test.rb
y_support-2.0.29 test/respond_to_test.rb
y_support-2.0.28 test/respond_to_test.rb