<commit_before>require "spec_helper"

describe Teaspoon::Suite do

  before do
    allow(Teaspoon.configuration).to receive(:suite_configs).and_return("default" => { block: proc {} })
  end

  describe ".all" do

    before do
      Teaspoon::Suite.instance_variable_set(:@all, nil)
      suites = { "default" => { block: proc {} }, "foo" => { block: proc {} } }
      allow(Teaspoon.configuration).to receive(:suite_configs).and_return(suites)
    end

    it "returns all the suites" do
      result = Teaspoon::Suite.all
      expect(result.first).to be_a(Teaspoon::Suite)
      expect(result.length).to be(2)
      expect(result.first.name).to eq("default")
      expect(result.last.name).to eq("foo")
    end

  end

  describe ".resolve_spec_for" do

    it "return a hash with the suite name and path" do
      result = Teaspoon::Suite.resolve_spec_for("fixture_spec")
      expect(result[:suite]).to eq("default")
      expect(result[:path].first).to include("base/fixture_spec.")
    end

    it "returns a hash with the suite name and an array of paths if a directory is given" do
      result = Teaspoon::Suite.resolve_spec_for("base")
      expect(result[:suite]).to eq("default")
      dirs = ["base/fixture_spec.", "base/runner_spec.", "base/teaspoon_spec"]
      expect(dirs.all? { |path| result[:path].grep(/#{path}/)[0] }).to be_truthy
    end

    it "returns false if the spec wasn't found" do
      expect(Teaspoon::Suite.resolve_spec_for("foo")).to be_falsey
    end

  end

  describe "#initialize" do

    it "uses default suite configuration" do
      expect(subject.name).to eq("default")
      expect(subject.config.helper).to eq("spec_helper")
    end

    it "accepts a suite in the options" do
      suite = { "test" => { block: proc { |s| s.helper = "helper_file" } } }
      expect(Teaspoon.configuration).to receive(:suite_configs).and_return(suite)
      subject = Teaspoon::Suite.new(suite: :test)
      expect(subject.name).to eql("test")
      expect(subject.config.helper).to eq("helper_file")
    end

  end

  describe "#spec_files" do

    it "returns an array of hashes with the filename and the asset name" do
      file = Teaspoon::Engine.root.join("spec/javascripts/teaspoon/base/reporters/console_spec.js").to_s
      expect(subject).to receive(:glob).and_return([file])
      expect(subject.spec_files[0]).to eql(path: file, name: "teaspoon/base/reporters/console_spec.js")
    end

    it "raises an exception if the file isn't servable (in an asset path)" do
      expect(subject).to receive(:glob).and_return(["/foo"])
      expect { subject.spec_files[0] }.to raise_error Teaspoon::AssetNotServable
    end

  end

  describe "#spec_assets" do

    it "returns an array of assets" do
      result = subject.spec_assets
      expect(result).to include("spec_helper.js?body=1")
      expect(result).to include("teaspoon/base/reporters/console_spec.js?body=1")
    end

    it "returns just a file if one was requested" do
      subject.instance_variable_set(:@options, file: "spec/javascripts/foo.js")
      result = subject.spec_assets(false)
      expect(result).to eql(["foo.js"])
    end

    it "returns the asset tree (all dependencies resolved) if we want coverage" do
      allow(subject).to receive(:no_coverage).and_return([%r{support/}, "spec_helper.coffee"])
      subject.instance_variable_set(:@options, coverage: true)
      result = subject.spec_assets(true)
      expect(result).to include("support/json2.js?body=1")
      expect(result).to include("spec_helper.js?body=1")
      expect(result).to include("drivers/phantomjs/runner.js?body=1&instrument=1")
    end

  end
<commit_msg>Test asset path generation with expand_assets<commit_after>require "spec_helper"

describe Teaspoon::Suite do

  before do
    allow(Teaspoon.configuration).to receive(:suite_configs).and_return("default" => { block: proc {} })
  end

  describe ".all" do

    before do
      Teaspoon::Suite.instance_variable_set(:@all, nil)
      suites = { "default" => { block: proc {} }, "foo" => { block: proc {} } }
      allow(Teaspoon.configuration).to receive(:suite_configs).and_return(suites)
    end

    it "returns all the suites" do
      result = Teaspoon::Suite.all
      expect(result.first).to be_a(Teaspoon::Suite)
      expect(result.length).to be(2)
      expect(result.first.name).to eq("default")
      expect(result.last.name).to eq("foo")
    end

  end

  describe ".resolve_spec_for" do

    it "return a hash with the suite name and path" do
      result = Teaspoon::Suite.resolve_spec_for("fixture_spec")
      expect(result[:suite]).to eq("default")
      expect(result[:path].first).to include("base/fixture_spec.")
    end

    it "returns a hash with the suite name and an array of paths if a directory is given" do
      result = Teaspoon::Suite.resolve_spec_for("base")
      expect(result[:suite]).to eq("default")
      dirs = ["base/fixture_spec.", "base/runner_spec.", "base/teaspoon_spec"]
      expect(dirs.all? { |path| result[:path].grep(/#{path}/)[0] }).to be_truthy
    end

    it "returns false if the spec wasn't found" do
      expect(Teaspoon::Suite.resolve_spec_for("foo")).to be_falsey
    end

  end

  describe "#initialize" do

    it "uses default suite configuration" do
      expect(subject.name).to eq("default")
      expect(subject.config.helper).to eq("spec_helper")
    end

    it "accepts a suite in the options" do
      suite = { "test" => { block: proc { |s| s.helper = "helper_file" } } }
      expect(Teaspoon.configuration).to receive(:suite_configs).and_return(suite)
      subject = Teaspoon::Suite.new(suite: :test)
      expect(subject.name).to eql("test")
      expect(subject.config.helper).to eq("helper_file")
    end

  end

  describe "#spec_files" do

    it "returns an array of hashes with the filename and the asset name" do
      file = Teaspoon::Engine.root.join("spec/javascripts/teaspoon/base/reporters/console_spec.js").to_s
      expect(subject).to receive(:glob).and_return([file])
      expect(subject.spec_files[0]).to eql(path: file, name: "teaspoon/base/reporters/console_spec.js")
    end

    it "raises an exception if the file isn't servable (in an asset path)" do
      expect(subject).to receive(:glob).and_return(["/foo"])
      expect { subject.spec_files[0] }.to raise_error Teaspoon::AssetNotServable
    end

  end

  describe "#spec_assets" do

    it "returns an array of assets" do
      result = subject.spec_assets
      expect(result).to include("spec_helper.js?body=1")
      expect(result).to include("teaspoon/base/reporters/console_spec.js?body=1")
    end

    it "returns just a file if one was requested" do
      subject.instance_variable_set(:@options, file: "spec/javascripts/foo.js")
      result = subject.spec_assets(false)
      expect(result).to eql(["foo.js"])
    end

    it "returns the asset tree (all dependencies resolved) if we want coverage" do
      allow(subject).to receive(:no_coverage).and_return([%r{support/}, "spec_helper.coffee"])
      subject.instance_variable_set(:@options, coverage: true)
      result = subject.spec_assets(true)
      expect(result).to include("support/json2.js?body=1")
      expect(result).to include("spec_helper.js?body=1")
      expect(result).to include("drivers/phantomjs/runner.js?body=1&instrument=1")
    end

    it "returns only the top level assets in the asset tree if config/expand_assets is set to false" do
      allow(subject.config).to receive(:expand_assets).and_return(false)
      result = subject.spec_assets(true)
      expect(result.any? { |file| file =~ /body=1/ }).to eq(false)
    end

  end

{'fraction_non_alphanumeric': 0.13391920251836306, 'fraction_numerical': 0.003016789087093389, 'mean_word_length': 3.565868263473054, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2945634', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2393, 'n_words': 570}