<commit_before>$: << 'cf_spec'
require 'spec_helper'

describe 'CF NodeJS Buildpack' do
  subject(:app) { Machete.deploy_app(app_name) }
  let(:browser) { Machete::Browser.new(app) }

  after do
    Machete::CF::DeleteApp.new.execute(app)
  end

  context 'when specifying a range for the nodeJS version in the package.json' do
    let(:app_name) { 'node_web_app_with_version_range' }

    it 'resolves to a nodeJS version successfully' do
      expect(app).to be_running
      expect(app).to_not have_logged 'Downloading and installing node 0.12.0'
      expect(app).to have_logged /Downloading and installing node \d+\.\d+\.\d+/

      browser.visit_path('/')
      expect(browser).to have_body('Hello, World!')
    end
  end

  context 'with an unreleased nodejs version' do
    let(:app_name) { 'node_web_app_with_unreleased_version' }

    it 'resolves to a nodeJS version successfully' do
      expect(app).to_not be_running
      expect(app).to have_logged 'Downloading and installing node 9000.0.0'
      expect(app).to_not have_logged 'Downloaded ['
      expect(app).to have_logged /DEPENDENCY MISSING IN MANIFEST: node 9000\.0\.0.*-----> Build failed/m
    end
  end

  context 'with an unsupported, but released, nodejs version' do
    let(:app_name) { 'node_web_app_with_unsupported_version' }

    it 'resolves to a nodeJS version successfully' do
      expect(app).to_not be_running
      expect(app).to have_logged 'Downloading and installing node 4.1.1'
      expect(app).to_not have_logged 'Downloaded ['<commit_msg>tests reflect behaviour<commit_after>$: << 'cf_spec'
require 'spec_helper'

describe 'CF NodeJS Buildpack' do
  subject(:app) { Machete.deploy_app(app_name) }
  let(:browser) { Machete::Browser.new(app) }

  after do
    Machete::CF::DeleteApp.new.execute(app)
  end

  context 'when specifying a range for the nodeJS version in the package.json' do
    let(:app_name) { 'node_web_app_with_version_range' }

    it 'resolves to a nodeJS version successfully' do
      expect(app).to be_running
      expect(app).to_not have_logged 'Downloading and installing node 0.12.0'
      expect(app).to have_logged /Downloading and installing node \d+\.\d+\.\d+/

      browser.visit_path('/')
      expect(browser).to have_body('Hello, World!')
    end
  end

  context 'with an unreleased nodejs version' do
    let(:app_name) { 'node_web_app_with_unreleased_version' }

    it 'displays a nice error messages and gracefully fails' do
      expect(app).to_not be_running
      expect(app).to have_logged 'Downloading and installing node 9000.0.0'
      expect(app).to_not have_logged 'Downloaded ['
      expect(app).to have_logged /DEPENDENCY MISSING IN MANIFEST: node 9000\.0\.0.*-----> Build failed/m
    end
  end

  context 'with an unsupported, but released, nodejs version' do
    let(:app_name) { 'node_web_app_with_unsupported_version' }

    it 'displays a nice error messages and gracefully fails' do
      expect(app).to_not be_running
      expect(app).to have_logged 'Downloading and installing node 4.1.1'
      expect(app).to_not have_logged 'Downloaded ['
{'fraction_non_alphanumeric': 0.1065203357004519, 'fraction_numerical': 0.012265978050355068, 'mean_word_length': 3.7025796661608497, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5207678', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1002, 'n_words': 274}