2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2016-08-06 12:03:25 -04:00
|
|
|
require "abstract_unit"
|
2008-06-04 16:06:32 -04:00
|
|
|
|
2012-01-05 20:12:46 -05:00
|
|
|
class StringInquirerTest < ActiveSupport::TestCase
|
2012-08-05 15:30:01 -04:00
|
|
|
def setup
|
2016-08-06 12:03:25 -04:00
|
|
|
@string_inquirer = ActiveSupport::StringInquirer.new("production")
|
2012-08-05 15:30:01 -04:00
|
|
|
end
|
|
|
|
|
2008-06-04 16:06:32 -04:00
|
|
|
def test_match
|
2012-08-05 15:30:01 -04:00
|
|
|
assert @string_inquirer.production?
|
2008-06-04 16:06:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_miss
|
2012-12-28 18:49:41 -05:00
|
|
|
assert_not @string_inquirer.development?
|
2008-06-04 16:06:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_missing_question_mark
|
2012-08-05 15:30:01 -04:00
|
|
|
assert_raise(NoMethodError) { @string_inquirer.production }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_respond_to
|
|
|
|
assert_respond_to @string_inquirer, :development?
|
2008-06-04 16:06:32 -04:00
|
|
|
end
|
2017-01-14 13:36:27 -05:00
|
|
|
|
|
|
|
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
|
2017-01-14 14:29:31 -05:00
|
|
|
String.class_eval do
|
|
|
|
undef_method :respond_to_missing?
|
|
|
|
def respond_to_missing?(name, include_private = false)
|
2017-01-15 22:33:37 -05:00
|
|
|
super
|
2017-01-14 14:29:31 -05:00
|
|
|
end
|
|
|
|
end
|
2017-01-14 13:36:27 -05:00
|
|
|
end
|
2008-06-04 16:06:32 -04:00
|
|
|
end
|