<commit_before>require File.dirname(__FILE__) + '/../test_helper'

class ErrorTest < Test::Unit::TestCase

  should "get an internal server error when return code is 500" do
    stub_login
    stub_get("/user/invalid", "blank.xml", 500)

    lambda { Gluestick.client.get("/user/invalid") }.should raise_error(Gluestick::InternalServerError)
  end

  should "get a MissingParameter error" do
    stub_login
    stub_get("/user/profile", "errors/missing_parameter.xml", 400);

    lambda { Gluestick.client.get("/user/profile") }.should raise_error(Gluestick::MissingParameter)
  end
  
  should "get a MissingObject error" do
    stub_login
    stub_get("/object/get?objectId=something", "errors/invalid_object.xml", 400);

    lambda { Gluestick.client.get("/object/get?objectId=something") }.should raise_error(Gluestick::InvalidObject)
  end

  context "error initialized with response" do
    setup do
      FakeWeb.clean_registry

      stub_login
      stub_get("/user/profile", "errors/missing_parameter.xml", 400);

    end

    should "respond to message, code, and name" do
      begin
        Gluestick.client.get("/user/profile")
      rescue Gluestick::MissingParameter => missing_object
        missing_object.should respond_to(:name)
        missing_object.should respond_to(:message)
        missing_object.should respond_to(:code)
      end
    end

    should "have the correct code and name" do
      begin
        Gluestick.client.get("/user/profile")
      rescue Gluestick::MissingParameter => missing_object
        missing_object.name.should == "MissingParameter"
        missing_object.code.should == 101
      end
    end

  end

end
<commit_msg>compressed the respond_tos into one statement<commit_after>require File.dirname(__FILE__) + '/../test_helper'

class ErrorTest < Test::Unit::TestCase

  should "get an internal server error when return code is 500" do
    stub_login
    stub_get("/user/invalid", "blank.xml", 500)

    lambda { Gluestick.client.get("/user/invalid") }.should raise_error(Gluestick::InternalServerError)
  end

  should "get a MissingParameter error" do
    stub_login
    stub_get("/user/profile", "errors/missing_parameter.xml", 400);

    lambda { Gluestick.client.get("/user/profile") }.should raise_error(Gluestick::MissingParameter)
  end
  
  should "get a MissingObject error" do
    stub_login
    stub_get("/object/get?objectId=something", "errors/invalid_object.xml", 400);

    lambda { Gluestick.client.get("/object/get?objectId=something") }.should raise_error(Gluestick::InvalidObject)
  end

  context "error initialized with response" do
    setup do
      FakeWeb.clean_registry

      stub_login
      stub_get("/user/profile", "errors/missing_parameter.xml", 400);

    end

    should "respond to message, code, and name" do
      begin
        Gluestick.client.get("/user/profile")
      rescue Gluestick::MissingParameter => missing_object
        missing_object.should respond_to(:name, :message, :code)
      end
    end

    should "have the correct code and name" do
      begin
        Gluestick.client.get("/user/profile")
      rescue Gluestick::MissingParameter => missing_object
        missing_object.name.should == "MissingParameter"
        missing_object.code.should == 101
      end
    end

  end

end

{'fraction_non_alphanumeric': 0.10686095931997572, 'fraction_numerical': 0.01092896174863388, 'mean_word_length': 3.4769021739130435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4305581', 'n_tokens_mistral': 1007, 'n_tokens_neox': 963, 'n_words': 229}