<commit_before>require 'spec_helper'

describe LinuxAdmin::RegistrationSystem do
  context ".registration_type" do
    it "when registered Subscription Manager" do
      stub_registered_to_system(:sm)
      expect(described_class.registration_type).to eq(LinuxAdmin::SubscriptionManager)
    end

    it "when registered RHN" do
      stub_registered_to_system(:rhn)
      expect(described_class.registration_type).to eq(LinuxAdmin::Rhn)
    end

    it "when unregistered" do
      stub_registered_to_system(nil)
      expect(described_class.registration_type).to eq(described_class)
    end

    it "should memoize results" do
      described_class.should_receive(:registration_type_uncached).once.and_return("anything_non_nil")
      described_class.registration_type
      described_class.registration_type
    end

    it "with reload should refresh results" do
      described_class.should_receive(:registration_type_uncached).twice.and_return("anything_non_nil")
      described_class.registration_type
      described_class.registration_type(true)
    end
  end

  it "#registered? when unregistered" do
    stub_registered_to_system(nil)
    expect(described_class.registered?).to be_false
  end

  context ".method_missing" do
    before do
      stub_registered_to_system(:rhn)
    end

    it "exists on the subclass" do
      expect(LinuxAdmin::RegistrationSystem.registered?).to be_true
    end

    it "does not exist on the subclass" do
      expect { LinuxAdmin::RegistrationSystem.organizations }.to raise_error(NotImplementedError)
    end

    it "is an unknown method" do
      expect { LinuxAdmin::RegistrationSystem.method_does_not_exist }.to be_true
    end
  end

  def stub_registered_to_system(system)
    LinuxAdmin::SubscriptionManager.any_instance.stub(:registered? => (system == :sm))
    LinuxAdmin::Rhn.any_instance.stub(:registered? => data_file_path("rhn/systemid")) if system == :rhn
  end
end<commit_msg>Enhance test to reproduce .registered?<commit_after>require 'spec_helper'

describe LinuxAdmin::RegistrationSystem do
  context ".registration_type" do
    it "when registered Subscription Manager" do
      stub_registered_to_system(:sm)
      expect(described_class.registration_type).to eq(LinuxAdmin::SubscriptionManager)
    end

    it "when registered RHN" do
      stub_registered_to_system(:sm, :rhn)
      expect(described_class.registration_type).to eq(LinuxAdmin::Rhn)
    end

    it "when unregistered" do
      stub_registered_to_system(nil)
      expect(described_class.registration_type).to eq(described_class)
    end

    it "should memoize results" do
      described_class.should_receive(:registration_type_uncached).once.and_return("anything_non_nil")
      described_class.registration_type
      described_class.registration_type
    end

    it "with reload should refresh results" do
      described_class.should_receive(:registration_type_uncached).twice.and_return("anything_non_nil")
      described_class.registration_type
      described_class.registration_type(true)
    end
  end

  it "#registered? when unregistered" do
    stub_registered_to_system(nil)
    expect(described_class.registered?).to be_false
  end

  context ".method_missing" do
    before do
      stub_registered_to_system(:rhn)
    end

    it "exists on the subclass" do
      expect(LinuxAdmin::RegistrationSystem.registered?).to be_true
    end

    it "does not exist on the subclass" do
      expect { LinuxAdmin::RegistrationSystem.organizations }.to raise_error(NotImplementedError)
    end

    it "is an unknown method" do
      expect { LinuxAdmin::RegistrationSystem.method_does_not_exist }.to be_true
    end
  end

  def stub_registered_to_system(*system)
    LinuxAdmin::SubscriptionManager.any_instance.stub(:registered? => (system.include?(:sm)))
    LinuxAdmin::Rhn.any_instance.stub(:registered? => (system.include?(:rhn)))
  end
end
{'fraction_non_alphanumeric': 0.08112965340179717, 'fraction_numerical': 0.0, 'mean_word_length': 4.3224043715847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4206472', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1120, 'n_words': 236}