<commit_before>describe ApplicationHelper::Button::AuthKeyPairCloudCreate do
  describe '#disabled?' do
    it "when the create action is available then the button is not disabled" do
      view_context = setup_view_context_with_sandbox({})
      button = described_class.new(view_context, {}, {}, {})
      ems = object_double(ManageIQ::Providers::CloudManager.new)
      allow(ems).to receive(:supports?).with(:auth_key_pair_create).and_return(true)
      allow(Rbac).to receive(:filtered).and_return([ems])
      expect(button.disabled?).to be false
    end

    it "when the create action is unavailable then the button is disabled" do
      view_context = setup_view_context_with_sandbox({})
      button = described_class.new(view_context, {}, {}, {})
      ems = object_double(ManageIQ::Providers::CloudManager.new)
      allow(ems).to receive(:supports?).with(:auth_key_pair_create).and_return(false)
      allow(Rbac).to receive(:filtered).and_return([ems])
      expect(button.disabled?).to be true
    end
  end

  describe '#calculate_properties' do
    it "when the create action is unavailable the button has the error in the title" do
      view_context = setup_view_context_with_sandbox({})
      button = described_class.new(view_context, {}, {}, {})
      ems = object_double(ManageIQ::Providers::CloudManager.new)
      allow(ems).to receive(:supports?).with(:auth_key_pair_create).and_return(false)
      allow(Rbac).to receive(:filtered).and_return([ems])
      button.calculate_properties
      expect(button[:title]).to eq("No cloud providers support key pair import or creation.")
    end

    it "when the create action is available, the button has no error in the title" do
      view_context = setup_view_context_with_sandbox({})
      button = described_class.new(view_context, {}, {}, {})
      ems = object_double(ManageIQ::Providers::CloudManager.new)
      allow(ems).to receive(:supports?).with(:auth_key_pair_create).and_return(true)
      allow(Rbac).to receive(:filtered).and_return([ems])
      button.calculate_properties
      expect(button[:title]).to be nil
    end
  end
end<commit_msg>rspec refactoring<commit_after>describe ApplicationHelper::Button::AuthKeyPairCloudCreate do
  let(:button) { described_class.new(setup_view_context_with_sandbox({}), {}, {}, {}) }

  def setup_ems(supports)
    ems = object_double(ManageIQ::Providers::CloudManager.new)
    allow(ems).to receive(:supports?).with(:auth_key_pair_create).and_return(supports)
    allow(Rbac).to receive(:filtered).and_return([ems])
  end

  describe '#disabled?' do
    it "when the create action is supported, then the button is not disabled" do
      setup_ems(true)
      expect(button.disabled?).to be false
    end

    it "when the create action is not supported, then the button is disabled" do
      setup_ems(false)
      expect(button.disabled?).to be true
    end
  end

  describe '#calculate_properties' do
    it "when the create action is not supported, then the button has the error in the title" do
      setup_ems(false)
      button.calculate_properties
      expect(button[:title]).to eq("No cloud providers support key pair import or creation.")
    end

    it "when the create action is supported, then the button has no error in the title" do
      setup_ems(true)
      button.calculate_properties
      expect(button[:title]).to be nil
    end
  end
end
{'fraction_non_alphanumeric': 0.1106521097668929, 'fraction_numerical': 0.0, 'mean_word_length': 4.1676829268292686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7592069', 'n_tokens_mistral': 1009, 'n_tokens_neox': 967, 'n_words': 251}