# frozen_string_literal: true # DeployRubygem - deploy a gem using rake # Containing a class module DeployRubygem # Using Project to deploy and manage Project module RSpecTesting def help_rspec(helper) helper.extend DeployRubygem RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! config.expect_with :rspec do |c| c.syntax = :expect end yield(config) if block_given? end end def check_current_version(gem_name, version) RSpec.describe gem_name do it 'has a version number' do expect(version).not_to be nil end it 'has not the actual version publish' do gem_version = Gem::Version.new(version) version_to_check = "#{gem_name} (#{gem_version})" expect(`gem list -r #{gem_name}`).not_to include(version_to_check) end end end def testing_gem(gem_obj) RSpec.describe "Testing #{gem_obj}" do it 'has a Project Name' do expect(gem_obj.project_name).not_to be nil end it 'has Project Options' do expect(gem_obj.project_options).not_to be nil end end end def testing_project(gem_obj) RSpec.describe "Testing gem #{gem_obj.project_name}" do it 'should not be null' do expect(gem_obj).not_to be nil end it 'should be a Project' do expect(gem_obj).to be_kind_of(DeployRubygem::Project) end it 'should get a Project Name' do expect(gem_obj.project_name).to eq(gem_obj.project_name) end end end def testing_workstation(gem_obj) RSpec.describe "Install #{gem_obj.project_name}" do it "Change to #{gem_obj} folder" do change_repo = gem_obj.change_to_project_folder expect(change_repo).not_to be nil expect(Dir.pwd).to eq(gem_obj.path) end it 'Change to Chef repo folder' do change_repo = gem_obj.change_to_chefrepo expect(change_repo).not_to be nil expect(change_repo).to eq(gem_obj.chefrepo_path) expect(Dir.pwd).to eq(gem_obj.chefrepo_path) end unless gem_obj.cookbooks.nil? it 'Should list his cookbooks dependencies' do cookbooks = gem_obj.cookbooks expect(cookbooks).not_to be nil expect(cookbooks).to be_kind_of(Array) end end end end def install_gem_via_git(gem_obj) RSpec.describe "Install #{gem_obj.project_name}" do it "Change to #{gem_obj} folder" do change_repo = gem_obj.change_to_project_folder expect(change_repo).not_to be nil expect(Dir.pwd).to eq(gem_obj.path) end end end def testing_inspec(inspector) inspect_test = InspecTestor.new(inspector[:inspec_path], inspector[:input_file], inspector[:waiver_file]) RSpec.describe "Testing #{inspect_test} at #{Dir.pwd}" do it 'Should be a kind of Html' do test_html = inspect_test.save_as_html('/tmp/html/deploy_rubygem_kind_of_html.html') expect(test_html).to be true end it 'Should be a kind of Json' do expect(inspect_test.test_json).to be_kind_of(InspecTestorResult) expect(inspect_test.test_json.status).to eq 'loaded' end it 'Should be successfull' do expect(inspect_test.test_json.success_result).to eq inspector[:success_result] expect(inspect_test.test_json.success_control).to eq inspector[:success_control] expect(inspect_test.test_json.failed_result).to eq inspector[:failed_result] expect(inspect_test.test_json.failed_control).to eq inspector[:failed_control] expect(inspect_test.test_json.pending_result).to eq inspector[:pending_result] expect(inspect_test.test_json.pending_control).to eq inspector[:pending_control] end end end end end