<commit_before>require 'spec_helper'

describe SimpleDeploy do

  before do
    @config_mock = mock 'config mock'
    @logger_mock = mock 'logger mock'
    @config_mock.should_receive(:logger).and_return @logger_mock
    SimpleDeploy::Config.should_receive(:new).
                         with(:logger => 'my-logger').
                         and_return @config_mock
    @stack = SimpleDeploy::Stack.new :environment => 'test-env',
                                     :name        => 'test-stack',
                                     :logger      => 'my-logger',
                                     :config      => @config_mock
  end

  describe "A stack" do
    it "should call create stack" do
      saf_mock = mock 'stack attribute formater mock'
      stack_mock = mock 'stackster stack mock'
      environment_config_mock = mock 'environment config mock'
      @config_mock.should_receive(:environment).with('test-env').
                   and_return environment_config_mock
      SimpleDeploy::StackAttributeFormater.should_receive(:new).
                                           with(:config      => @config_mock,
                                                :environment => 'test-env').
                                           and_return saf_mock
      Stackster::Stack.should_receive(:new).with(:environment => 'test-env',
                                                 :name        => 'test-stack',
                                                 :config      => environment_config_mock,
                                                 :logger      => @logger_mock).
                                            and_return stack_mock
      saf_mock.should_receive(:updated_attributes).with({'arg1' => 'val'}).
               and_return('arg1' => 'new_val')
      stack_mock.should_receive(:create).with :attributes => { 'arg1' => 'new_val' },
                                              :template   => 'some_json'
      @stack.create(:attributes => { 'arg1' => 'val' }, 
                    :template => 'some_json')
    end

    it "should call update stack" do
      deployment_mock = mock 'deployment'
      deployment_mock.should_receive(:cleared_to_deploy?).and_return(true)
      @stack.should_receive(:deployment).and_return(deployment_mock)

      saf_mock = mock 'stack attribute formater mock'
      stack_mock = mock 'stackster stack mock'
      environment_config_mock = mock 'environment config mock'
      @logger_mock.should_receive(:info).exactly(2).times
      @config_mock.should_receive(:environment).with('test-env').
                   and_return environment_config_mock
      SimpleDeploy::StackAttributeFormater.should_receive(:new).
                                           with(:config      => @config_mock,
                                                :environment => 'test-env').
                                           and_return saf_mock
      Stackster::Stack.should_receive(:new).with(:environment => 'test-env',
                                                 :name        => 'test-stack',
                                                 :config      => environment_config_mock,
                                                 :logger      => @logger_mock).
                                            and_return stack_mock
      saf_mock.should_receive(:updated_attributes).with({'arg1' => 'val'}).
               and_return('arg1' => 'new_val')
      stack_mock.should_receive(:update).with :attributes => { 'arg1' => 'new_val' }
      @stack.update false, :attributes => { 'arg1' => 'val' }
    end

  end

  describe "updating a stack" do
    it "should update when the deployment is not locked" do
      deployment_mock = mock 'deployment'
      deployment_mock.should_receive(:cleared_to_deploy?).and_return(true)
      @stack.should_receive(:deployment).and_return(deployment_mock)

      saf_mock = mock 'stack attribute formater mock'
      stack_mock = mock 'stackster stack mock'
      environment_config_mock = mock 'environment config mock'
      @logger_mock.should_receive(:info).exactly(2).times
      @config_mock.should_receive(:environment).with('test-env').
                   and_return environment_config_mock
      SimpleDeploy::StackAttributeFormater.should_receive(:new).
                                           with(:config      => @config_mock,
                                                :environment => 'test-env').
                                           and_return saf_mock
      Stackster::Stack.should_receive(:new).with(:environment => 'test-env',
                                                 :name        => 'test-stack',
                                                 :config      => environment_config_mock,
                                                 :logger      => @logger_mock).
                                            and_return stack_mock
      saf_mock.should_receive(:updated_attributes).with({'arg1' => 'val'}).
               and_return('arg1' => 'new_val')
      stack_mock.should_receive(:update).with :attributes => { 'arg1' => 'new_val' }
      @stack.update false, :attributes => { 'arg1' => 'val' }
    end

    it "should not update when the deployment is locked" do
      deployment_mock = mock 'deployment'
      deployment_mock.should_receive(:cleared_to_deploy?).and_return(false)
      @stack.should_receive(:deployment).and_return(deployment_mock)

      SimpleDeploy::StackAttributeFormater.should_receive(:new).never
      Stackster::Stack.should_receive(:new).never

      @stack.update false, :attributes => { 'arg1' => 'val' }
    end
  end

  describe "destroying a stack" do
    it "should not create a deployment" do
      @stack.should_receive(:deployment).never

      stack_mock = mock 'stackster stack mock'
      @stack.should_receive(:stack).and_return(stack_mock)
      stack_mock.should_receive(:destroy)

      @logger_mock.should_receive(:info).exactly(1).times

      @stack.destroy
    end
  end
end<commit_msg>replacing mocks with stubs based on code review<commit_after>require 'spec_helper'

describe SimpleDeploy do

  before do
    @config_mock = mock 'config mock'
    @logger_stub = stub 'logger stub', :info => ''
    @config_mock.should_receive(:logger).and_return @logger_stub
    SimpleDeploy::Config.should_receive(:new).
                         with(:logger => 'my-logger').
                         and_return @config_mock
    @stack = SimpleDeploy::Stack.new :environment => 'test-env',
                                     :name        => 'test-stack',
                                     :logger      => 'my-logger',
                                     :config      => @config_mock
  end

  describe "A stack" do
    it "should call create stack" do
      saf_mock = mock 'stack attribute formater mock'
      stack_mock = mock 'stackster stack mock'
      environment_config_mock = mock 'environment config mock'
      @config_mock.should_receive(:environment).with('test-env').
                   and_return environment_config_mock
      SimpleDeploy::StackAttributeFormater.should_receive(:new).
                                           with(:config      => @config_mock,
                                                :environment => 'test-env').
                                           and_return saf_mock
      Stackster::Stack.should_receive(:new).with(:environment => 'test-env',
                                                 :name        => 'test-stack',
                                                 :config      => environment_config_mock,
                                                 :logger      => @logger_stub).
                                            and_return stack_mock
      saf_mock.should_receive(:updated_attributes).with({'arg1' => 'val'}).
               and_return('arg1' => 'new_val')
      stack_mock.should_receive(:create).with :attributes => { 'arg1' => 'new_val' },
                                              :template   => 'some_json'
      @stack.create(:attributes => { 'arg1' => 'val' }, 
                    :template => 'some_json')
    end

    it "should call update stack" do
      deployment_stub = stub 'deployment', :cleared_to_deploy? => true
      @stack.should_receive(:deployment).and_return(deployment_stub)

      saf_mock = mock 'stack attribute formater mock'
      stack_mock = mock 'stackster stack mock'
      environment_config_mock = mock 'environment config mock'
      @config_mock.should_receive(:environment).with('test-env').
                   and_return environment_config_mock
      SimpleDeploy::StackAttributeFormater.should_receive(:new).
                                           with(:config      => @config_mock,
                                                :environment => 'test-env').
                                           and_return saf_mock
      Stackster::Stack.should_receive(:new).with(:environment => 'test-env',
                                                 :name        => 'test-stack',
                                                 :config      => environment_config_mock,
                                                 :logger      => @logger_stub).
                                            and_return stack_mock
      saf_mock.should_receive(:updated_attributes).with({'arg1' => 'val'}).
               and_return('arg1' => 'new_val')
      stack_mock.should_receive(:update).with :attributes => { 'arg1' => 'new_val' }
      @stack.update false, :attributes => { 'arg1' => 'val' }
    end

  end

  describe "updating a stack" do
    it "should update when the deployment is not locked" do
      deployment_stub = stub 'deployment', :cleared_to_deploy? => true
      @stack.should_receive(:deployment).and_return(deployment_stub)

      saf_mock = mock 'stack attribute formater mock'
      stack_mock = mock 'stackster stack mock'
      environment_config_mock = mock 'environment config mock'
      @config_mock.should_receive(:environment).with('test-env').
                   and_return environment_config_mock
      SimpleDeploy::StackAttributeFormater.should_receive(:new).
                                           with(:config      => @config_mock,
                                                :environment => 'test-env').
                                           and_return saf_mock
      Stackster::Stack.should_receive(:new).with(:environment => 'test-env',
                                                 :name        => 'test-stack',
                                                 :config      => environment_config_mock,
                                                 :logger      => @logger_stub).
                                            and_return stack_mock
      saf_mock.should_receive(:updated_attributes).with({'arg1' => 'val'}).
               and_return('arg1' => 'new_val')
      stack_mock.should_receive(:update).with :attributes => { 'arg1' => 'new_val' }
      @stack.update false, :attributes => { 'arg1' => 'val' }
    end

    it "should not update when the deployment is locked" do
      deployment_stub = stub 'deployment', :cleared_to_deploy? => false
      @stack.should_receive(:deployment).and_return(deployment_stub)

      SimpleDeploy::StackAttributeFormater.should_receive(:new).never
      Stackster::Stack.should_receive(:new).never

      @stack.update false, :attributes => { 'arg1' => 'val' }
    end
  end

  describe "destroying a stack" do
    it "should not create a deployment" do
      @stack.should_receive(:deployment).never

      stack_mock = mock 'stackster stack mock'
      @stack.should_receive(:stack).and_return(stack_mock)
      stack_mock.should_receive(:destroy)

      @stack.destroy
    end
  end
end
{'fraction_non_alphanumeric': 0.10251153254741159, 'fraction_numerical': 0.0024773620365624465, 'mean_word_length': 1.666742596810934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 94, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1024927', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2790, 'n_words': 563}