stripe-ruby/test/stripe_test.rb
Brandur 863da48398 Add frozen_string_literal to every file and enforce Rubocop rule
Adds the magic `frozen_string_literal: true` comment to every file and
enables a Rubocop rule to make sure that it's always going to be there
going forward as well.

See here for more background [1], but the basic idea is that unlike many
other languages, static strings in code are mutable by default. This has
since been acknowledged as not a particularly good idea, and the
intention is to rectify the mistake when Ruby 3 comes out, where all
string literals will be frozen. The `frozen_string_literal` magic
comment was introduced in Ruby 2.3 as a way of easing the transition,
and allows libraries and projects to freeze their literals in advance.

I don't think this is breaking in any way: it's possible that users
might've been pulling out one of are literals somehow and mutating it,
but that would probably not have been useful for anything and would
certainly not be recommended, so I'm quite comfortable pushing this
change through as a minor version.

As discussed in #641.

[1] https://stackoverflow.com/a/37799399
2018-05-10 14:56:14 -07:00

62 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require File.expand_path("../test_helper", __FILE__)
class StripeTest < Test::Unit::TestCase
should "warn that #refresh_from is deprecated" do
old_stderr = $stderr
$stderr = StringIO.new
begin
Stripe.uri_encode({})
message = "NOTE: Stripe.uri_encode is deprecated; use " \
"Stripe::Util#encode_parameters instead"
assert_match Regexp.new(message), $stderr.string
ensure
$stderr = old_stderr
end
end
should "allow app_info to be configured" do
begin
old = Stripe.app_info
Stripe.set_app_info(
"MyAwesomePlugin",
url: "https://myawesomeplugin.info",
version: "1.2.34"
)
assert_equal({
name: "MyAwesomePlugin",
url: "https://myawesomeplugin.info",
version: "1.2.34",
}, Stripe.app_info)
ensure
Stripe.app_info = old
end
end
should "allow ca_bundle_path to be configured" do
begin
old = Stripe.ca_bundle_path
Stripe.ca_bundle_path = "path/to/ca/bundle"
assert_equal "path/to/ca/bundle", Stripe.ca_bundle_path
ensure
Stripe.ca_bundle_path = old
end
end
should "allow max_network_retries to be configured" do
begin
old = Stripe.max_network_retries
Stripe.max_network_retries = 99
assert_equal 99, Stripe.max_network_retries
ensure
Stripe.max_network_retries = old
end
end
should "have default open and read timeouts" do
assert_equal Stripe.open_timeout, 30
assert_equal Stripe.read_timeout, 80
end
end