Sha256: c8bebb72f657bdcdb79446ec533ce700512e699ab69a0179c8e544b7b3f2ab18

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require "abstract_unit"

class StringInquirerTest < ActiveSupport::TestCase
  def setup
    @string_inquirer = ActiveSupport::StringInquirer.new("production")
  end

  def test_match
    assert @string_inquirer.production?
  end

  def test_miss
    assert_not @string_inquirer.development?
  end

  def test_missing_question_mark
    assert_raise(NoMethodError) { @string_inquirer.production }
  end

  def test_respond_to
    assert_respond_to @string_inquirer, :development?
  end

  def test_respond_to_fallback_to_string_respond_to
    String.class_eval do
      def respond_to_missing?(name, include_private = false)
        (name == :bar) || super
      end
    end
    str = ActiveSupport::StringInquirer.new("hello")

    assert_respond_to str, :are_you_ready?
    assert_respond_to str, :bar
    assert_not_respond_to str, :nope

  ensure
    String.class_eval do
      undef_method :respond_to_missing?
      def respond_to_missing?(name, include_private = false)
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-on-quails-0.1.0 activesupport/test/string_inquirer_test.rb