mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-05 00:02:50 -04:00
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
72 lines
2.0 KiB
Ruby
72 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "coveralls"
|
|
Coveralls.wear!("test_frameworks")
|
|
|
|
require "stripe"
|
|
require "test/unit"
|
|
require "mocha/setup"
|
|
require "stringio"
|
|
require "shoulda/context"
|
|
require "timecop"
|
|
require "webmock/test_unit"
|
|
|
|
PROJECT_ROOT = File.expand_path("../../", __FILE__)
|
|
|
|
require File.expand_path("../test_data", __FILE__)
|
|
|
|
# If changing this number, please also change it in `.travis.yml`.
|
|
MOCK_MINIMUM_VERSION = "0.16.0".freeze
|
|
MOCK_PORT = ENV["STRIPE_MOCK_PORT"] || 12_111
|
|
|
|
# Disable all real network connections except those that are outgoing to
|
|
# stripe-mock.
|
|
WebMock.disable_net_connect!(allow: "localhost:#{MOCK_PORT}")
|
|
|
|
# Try one initial test connection to stripe-mock so that if there's a problem
|
|
# we can print one error and fail fast so that it's more clear to the user how
|
|
# they should fix the problem.
|
|
begin
|
|
resp = Faraday.get("http://localhost:#{MOCK_PORT}/")
|
|
version = resp.headers["Stripe-Mock-Version"]
|
|
if version != "master" &&
|
|
Gem::Version.new(version) < Gem::Version.new(MOCK_MINIMUM_VERSION)
|
|
abort("Your version of stripe-mock (#{version}) is too old. The minimum " \
|
|
"version to run this test suite is #{MOCK_MINIMUM_VERSION}. Please " \
|
|
"see its repository for upgrade instructions.")
|
|
end
|
|
rescue Faraday::ConnectionFailed
|
|
abort("Couldn't reach stripe-mock at `localhost:#{MOCK_PORT}`. Is " \
|
|
"it running? Please see README for setup instructions.")
|
|
end
|
|
|
|
module Test
|
|
module Unit
|
|
class TestCase
|
|
include Stripe::TestData
|
|
include Mocha
|
|
|
|
setup do
|
|
Stripe.api_key = "sk_test_123"
|
|
Stripe.api_base = "http://localhost:#{MOCK_PORT}"
|
|
|
|
# We don't point to the same host for the API and uploads in
|
|
# production, but `stripe-mock` supports both APIs.
|
|
Stripe.uploads_base = Stripe.api_base
|
|
|
|
stub_connect
|
|
end
|
|
|
|
teardown do
|
|
Stripe.api_key = nil
|
|
end
|
|
|
|
private
|
|
|
|
def stub_connect
|
|
stub_request(:any, /^#{Stripe.connect_base}/).to_return(body: "{}")
|
|
end
|
|
end
|
|
end
|
|
end
|