浏览代码

update minitest testcase class

Jon G 5 年之前
父节点
当前提交
f08e00438c
共有 1 个文件被更改,包括 80 次插入81 次删除
  1. 80 81
      test/test_helper.rb

+ 80 - 81
test/test_helper.rb

@@ -14,102 +14,101 @@ WebMock.disable_net_connect!
 # setup ShopifyAPI with fake api_key and secret
 module Test
   module Unit
-  end
-end
-
-class Test::Unit::TestCase < Minitest::Unit::TestCase
-  def self.test(string, &block)
-    define_method("test_#{string}", &block)
-  end
-
-  def self.should(string, &block)
-    self.test("should_#{string}", &block)
-  end
+    class TestCase < Minitest::Test
+      def self.test(string, &block)
+        define_method("test_#{string}", &block)
+      end
 
-  def self.context(string)
-    yield
-  end
+      def self.should(string, &block)
+        self.test("should_#{string}", &block)
+      end
 
-  def setup
-    ActiveResource::Base.format = :json
-    ShopifyAPI.constants.each do |const|
-      begin
-        const = mod.const_get(const)
-        const.format = :json if const.respond_to?(:format=)
-      rescue NameError
+      def self.context(string)
+        yield
       end
-    end
 
-    ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2019-01'))
+      def setup
+        ActiveResource::Base.format = :json
+        ShopifyAPI.constants.each do |const|
+          begin
+            const = mod.const_get(const)
+            const.format = :json if const.respond_to?(:format=)
+          rescue NameError
+          end
+        end
+
+        ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2019-01'))
+
+        ShopifyAPI::Base.clear_session
+        session = ShopifyAPI::Session.new(
+          domain: "https://this-is-my-test-shop.myshopify.com",
+          token: "token_test_helper",
+          api_version: '2019-01',
+        )
+
+        ShopifyAPI::Base.activate_session(session)
+      end
 
-    ShopifyAPI::Base.clear_session
-    session = ShopifyAPI::Session.new(
-      domain: "https://this-is-my-test-shop.myshopify.com",
-      token: "token_test_helper",
-      api_version: '2019-01',
-    )
+      def teardown
+        ShopifyAPI::Base.clear_session
+        ShopifyAPI::Base.site = nil
+        ShopifyAPI::Base.password = nil
+        ShopifyAPI::Base.user = nil
 
-    ShopifyAPI::Base.activate_session(session)
-  end
+        ShopifyAPI::ApiVersion.clear_defined_versions
+        ShopifyAPI::ApiVersion.define_known_versions
+      end
 
-  def teardown
-    ShopifyAPI::Base.clear_session
-    ShopifyAPI::Base.site = nil
-    ShopifyAPI::Base.password = nil
-    ShopifyAPI::Base.user = nil
+      # Custom Assertions
+      def assert_not(expression)
+        refute expression, "Expected <#{expression}> to be false!"
+      end
 
-    ShopifyAPI::ApiVersion.clear_defined_versions
-    ShopifyAPI::ApiVersion.define_known_versions
-  end
+      def assert_nothing_raised
+        yield
+      end
 
-  # Custom Assertions
-  def assert_not(expression)
-    refute expression, "Expected <#{expression}> to be false!"
-  end
+      def assert_not_includes(array, value)
+        refute array.include?(value)
+      end
 
-  def assert_nothing_raised
-    yield
-  end
+      def assert_includes(array, value)
+        assert array.include?(value)
+      end
 
-  def assert_not_includes(array, value)
-    refute array.include?(value)
-  end
+      def load_fixture(name, format=:json)
+        File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
+      end
 
-  def assert_includes(array, value)
-    assert array.include?(value)
-  end
+      def assert_request_body(expected)
+        assert_equal expected, WebMock.last_request.body
+      end
 
-  def load_fixture(name, format=:json)
-    File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
-  end
+      def fake(endpoint, options={})
+        body   = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
+        format = options.delete(:format) || :json
+        method = options.delete(:method) || :get
+        api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.coerce_to_version('2019-01')
+        extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
+
+        url = if options.has_key?(:url)
+          options[:url]
+        else
+          "https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
+        end
+
+        WebMock.stub_request(method, url).to_return(
+          body: body, status: 200, headers: { content_type: "text/#{format}", content_length: 1 }.merge(options)
+        )
+      end
 
-  def assert_request_body(expected)
-    assert_equal expected, WebMock.last_request.body
-  end
+      def ar_version_before?(version_string)
+        Gem::Version.new(ActiveResource::VERSION::STRING) < Gem::Version.new(version_string)
+      end
 
-  def fake(endpoint, options={})
-    body   = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
-    format = options.delete(:format) || :json
-    method = options.delete(:method) || :get
-    api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.coerce_to_version('2019-01')
-    extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
-
-    url = if options.has_key?(:url)
-      options[:url]
-    else
-      "https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
+      def ar_version_after?(version_string)
+        Gem::Version.new(version_string) < Gem::Version.new(ActiveResource::VERSION::STRING)
+      end
     end
-
-    WebMock.stub_request(method, url).to_return(
-      body: body, status: 200, headers: { content_type: "text/#{format}", content_length: 1 }.merge(options)
-    )
-  end
-
-  def ar_version_before?(version_string)
-    Gem::Version.new(ActiveResource::VERSION::STRING) < Gem::Version.new(version_string)
-  end
-
-  def ar_version_after?(version_string)
-    Gem::Version.new(version_string) < Gem::Version.new(ActiveResource::VERSION::STRING)
   end
 end