<commit_before>require 'spec_helper'

describe RailsBestPracticesGrapher do
  before :each do
    @stats_grapher = MetricFu::RailsBestPracticesGrapher.new
    MetricFu.configuration
  end

  it "should respond to rails_best_practices_count and labels" do
    @stats_grapher.should respond_to(:rails_best_practices_count)
    @stats_grapher.should respond_to(:labels)
  end

  describe "responding to #initialize" do
    it "should initialise rails_best_practices_count and labels" do
      @stats_grapher.rails_best_practices_count.should == []
      @stats_grapher.labels.should == {}
    end
  end

  describe "responding to #get_metrics" do
    before(:each) do
      @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
      @date = "01022003"
    end

    it "should push 100 to rails_best_practices_count" do
      @stats_grapher.rails_best_practices_count.should_receive(:push).with(2)
      @stats_grapher.get_metrics(@metrics, @date)
    end

    it "should update labels with the date" do
      @stats_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
      @stats_grapher.get_metrics(@metrics, @date)
    end<commit_msg>Add coverage to zero metrics code branch and make spec_helper loading consistent for rcov<commit_after>require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe RailsBestPracticesGrapher do
  before :each do
    @stats_grapher = MetricFu::RailsBestPracticesGrapher.new
    MetricFu.configuration
  end

  it "should respond to rails_best_practices_count and labels" do
    @stats_grapher.should respond_to(:rails_best_practices_count)
    @stats_grapher.should respond_to(:labels)
  end

  describe "responding to #initialize" do
    it "should initialise rails_best_practices_count and labels" do
      @stats_grapher.rails_best_practices_count.should == []
      @stats_grapher.labels.should == {}
    end
  end

  describe "responding to #get_metrics" do
    before(:each) do
      @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
      @date = "01022003"
    end

    it "should push 100 to rails_best_practices_count" do
      @stats_grapher.rails_best_practices_count.should_receive(:push).with(2)
      @stats_grapher.get_metrics(@metrics, @date)
    end

    it "should update labels with the date" do
      @stats_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
      @stats_grapher.get_metrics(@metrics, @date)
    end

    context "when no metrics have been collected" do
      it "should push 0 to rails_best_practices_count" do
        @stats_grapher.rails_best_practices_count.should_receive(:push).with(0)
        @stats_grapher.get_metrics({}, @date)
      end
    end
{'fraction_non_alphanumeric': 0.10118406889128095, 'fraction_numerical': 0.021528525296017224, 'mean_word_length': 4.172541743970315, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741948', 'n_tokens_mistral': 1009, 'n_tokens_neox': 917, 'n_words': 195}