<commit_before>require "rails_finder/gemfile"
require "tmpdir"
require "fileutils"

VALID_GEMFILE = <<END
source :rubygems

gem "rails", "3.2.11"
gem "jquery-rails"
END

module RailsFinder
  describe Gemfile do
    it "knows if file exists" do
      Dir.mktmpdir do |dir|
        FileUtils.touch(File.join(dir, "Gemfile"))

        Gemfile.new(File.join(dir, "Gemfile")).should exist
      end
    end

    it "knows if file does not exist" do
      Dir.mktmpdir do |dir|
        Gemfile.new(File.join(dir, "Gemfile")).should_not exist
      end
    end

    it "reports Rails version" do
      Dir.mktmpdir do |dir|
        File.open(File.join(dir, "Gemfile"), "w") do |file|
          file.puts(VALID_GEMFILE)
        end

        Gemfile.new(File.join(dir, "Gemfile")).rails_version.should == "3.2.11"
      end
    end

    it "reports none when no Rails version" do
      Dir.mktmpdir do |dir|
        File.open(File.join(dir, "Gemfile"), "w") do |file|
          file.puts "source :rubygems"
          file.puts "gem 'rspec', '2.12.0'"
        end

        Gemfile.new(File.join(dir, "Gemfile")).rails_version.should == "n/a"
      end
    end

    it "memoizes rails version" do
      Dir.mktmpdir do |dir|
        File.open(File.join(dir, "Gemfile"), "w") do |file|
          file.puts(VALID_GEMFILE)
        end

        @subject = Gemfile.new(File.join(dir, "Gemfile"))
        @subject.rails_version.should == "3.2.11"
      end

      @subject.rails_version.should == "3.2.11"
    end
  end
end
<commit_msg>Cleanup spec a bit<commit_after>require "rails_finder/gemfile"
require "tmpdir"
require "fileutils"

VALID_GEMFILE = <<END
source :rubygems

gem "rails", "3.2.11"
gem "jquery-rails"
END

module RailsFinder
  describe Gemfile do
    def with_dir
      Dir.mktmpdir("rails_version-spec") do |dir|
        yield dir
      end
    end

    def gemfile(dir)
      File.join(dir, "Gemfile")
    end

    it "knows if file exists" do
      with_dir do |dir|
        FileUtils.touch(gemfile(dir))

        Gemfile.new(gemfile(dir)).should exist
      end
    end

    it "knows if file does not exist" do
      with_dir do |dir|
        Gemfile.new(gemfile(dir)).should_not exist
      end
    end

    it "reports Rails version" do
      with_dir do |dir|
        File.open(gemfile(dir), "w") do |file|
          file.puts(VALID_GEMFILE)
        end

        Gemfile.new(gemfile(dir)).rails_version.should == "3.2.11"
      end
    end

    it "reports none when no Rails version" do
      with_dir do |dir|
        File.open(gemfile(dir), "w") do |file|
          file.puts "source :rubygems"
          file.puts "gem 'rspec', '2.12.0'"
        end

        Gemfile.new(gemfile(dir)).rails_version.should == "n/a"
      end
    end

    it "memoizes rails version" do
      with_dir do |dir|
        File.open(gemfile(dir), "w") do |file|
          file.puts(VALID_GEMFILE)
        end

        @subject = Gemfile.new(gemfile(dir))
        @subject.rails_version.should == "3.2.11"
      end

      @subject.rails_version.should == "3.2.11"
    end
  end
end

{'fraction_non_alphanumeric': 0.12337239583333333, 'fraction_numerical': 0.013020833333333334, 'mean_word_length': 2.262208067940552, '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': '4918173', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1100, 'n_words': 264}