Sha256: 241479d5e793f2780effaa5047ea434476969c8de507ed8232ee6aa201117180

Contents?: true

Size: 1.67 KB

Versions: 133

Compression:

Stored size: 1.67 KB

Contents

require "spec"
require "file_utils"
require "webmock"
require "../src/remote_data_file"

TEST_URL = [RemoteDataFile::BASE_URL, "test-exercise", RemoteDataFile::DATA_FILE].join("/")
TEST_DIR = File.expand_path(File.join("..", "..", "cache", "test-exercise"), __FILE__)

describe "RemoteDataFile" do
  describe "#path" do
    context "when successful" do
      Spec.before_each do
        clean_test_files
        WebMock.reset
      end

      Spec.after_each do
        clean_test_files
      end

      it "returns the response body if status is 200" do
        WebMock.stub(:get, TEST_URL).to_return(status: 200, body: "file body")

        remote_data_file = RemoteDataFile.new("test-exercise")

        File.read(remote_data_file.path).should eq("file body")
      end
    end

    context "when successful" do
      it "raises a not found exception if status is 404" do
        WebMock.stub(:get, TEST_URL).to_return(status: 404, body: "")

        error_message = "A #{RemoteDataFile::DATA_FILE} doesn't exist for test-exercise in problem-specifications. " +
                        "Go make one!"

        expect_raises(Exception, error_message) do
          RemoteDataFile.new("test-exercise").path
        end
      end

      it "raises a unexpected exception if status is other than 200 or 404" do
        WebMock.stub(:get, TEST_URL).to_return(status: 500, body: "")

        error_message = "Error while requesting the test-exercise data file from GitHub... " +
                        "Status was 500"
        expect_raises(Exception, error_message) do
          RemoteDataFile.new("test-exercise").path
        end
      end
    end
  end
end

def clean_test_files
  FileUtils.rm_rf(TEST_DIR)
end

Version data entries

133 entries across 133 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.77 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.76 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.75 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.74 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.73 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.72 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.71 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.70 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.69 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.68 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.67 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.66 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.65 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.64 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.63 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.62 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.61 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.60 tracks/crystal/generator/spec/remote_data_file_spec.cr
trackler-2.2.1.59 tracks/crystal/generator/spec/remote_data_file_spec.cr