<commit_before>require 'spec_helper'

require_relative '../spec/factories/provision.rb'

describe 'Test 14: Bebox::ProvisionWizard' do

  subject { Bebox::ProvisionWizard.new }

  let(:provision) { build(:provision) }

  context '00: apply step' do
    it 'apply a step with wizard' do
      Bebox::Provision.any_instance.stub_chain(:apply, :success?) { true }
      outputs = subject.apply_step(provision.project_root, provision.environment, provision.step)
      expect(outputs).to eq([true])
    end

    it 're-apply a step with wizard' do
      Bebox::Node.stub(:nodes_in_environment) { [provision.node] }
      Bebox::Node.stub(:list) { [provision.node.hostname] }
      Bebox::Node.any_instance.stub(:checkpoint_parameter_from_file) { '' }
      Bebox::Provision.any_instance.stub_chain(:apply, :success?) { true }
      $stdin.stub(:gets).and_return('y')
      outputs = subject.apply_step(provision.project_root, provision.environment, provision.step)
      expect(outputs).to eq([true])
    end

    it 'obtains the previous checkpoint for a node' do
      steps = %w{prepared_nodes step-0 step-1 step-2 step-3}
      expected_checkpoints = ['nodes',  'prepared_nodes', 'steps/step-0', 'steps/step-1', 'steps/step-2']
      checkpoints = []
      steps.each do |step|
        checkpoints << subject.previous_checkpoint(step)
      end
      expect(checkpoints).to include(*expected_checkpoints)
    end
  end
end<commit_msg>Fix provision wizard test<commit_after>require 'spec_helper'

require_relative '../spec/factories/provision.rb'

describe 'Test 00: Bebox::ProvisionWizard' do

  subject { Bebox::ProvisionWizard.new }

  let(:provision) { build(:provision) }

  before :each do
    $stdout.stub(:write)
    Bebox::Environment.stub(:check_environment_access) { true }
    Bebox::Node.stub(:nodes_in_environment) { [provision.node] }
    Bebox::Node.any_instance.stub(:checkpoint_parameter_from_file) { '' }
    Bebox::Provision.stub(:role_from_node) { 'role' }
    Bebox::Provision.stub(:profiles_from_role) { 'profile' }
    Bebox::Provision.stub(:generate_puppetfile) {true}
    Bebox::Provision.stub(:generate_roles_and_profiles) {true}
    Bebox::Provision.any_instance.stub_chain(:apply, :success?) { true }
  end

  it 'apply a step with wizard' do
    Bebox::Node.stub(:list) { [] }
    outputs = subject.apply_step(provision.project_root, provision.environment, provision.step)
    expect(outputs).to eq([true])
  end

  it 're-apply a step with wizard' do
    Bebox::Node.stub(:list) { [provision.node.hostname] }
    $stdin.stub(:gets).and_return('y')
    outputs = subject.apply_step(provision.project_root, provision.environment, provision.step)
    expect(outputs).to eq([true])
  end

  it 'obtains the previous checkpoint for a node' do
    steps = %w{prepared_nodes step-0 step-1 step-2 step-3}
    expected_checkpoints = ['nodes',  'prepared_nodes', 'steps/step-0', 'steps/step-1', 'steps/step-2']
    checkpoints = []
    steps.each do |step|
      checkpoints << subject.previous_checkpoint(step)
    end
    expect(checkpoints).to include(*expected_checkpoints)
  end
end
{'fraction_non_alphanumeric': 0.136144190537496, 'fraction_numerical': 0.006437077566784679, 'mean_word_length': 4.162790697674419, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1337048', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1037, 'n_words': 191}