require 'spec_helper'

describe Fukuzatsu::Formatters::Text do

  let (:summary) { Fukuzatsu::Summary.new(
      :source => "foo.rb",
      :entity => "Foo",
      :container => "Foo"
    )
  }

  let (:formatter) { Fukuzatsu::Formatters::Text.new(summary: summary, base_output_path: nil) }

  describe "#header" do
    it "returns a header array" do
      expect(formatter.header).to eq ["Class/Module", "Method", "Complexity"]
    end
  end

  describe "#rows" do

    before do
      allow(summary).to receive(:container_name).and_return("Foo")
      allow(summary).to receive(:entity_name).and_return("*")
      allow(summary).to receive(:complexity).and_return(13)
      allow(summary).to receive(:averge_complexity).and_return(11)
    end

    it "returns formatted rows" do
      expect(formatter.rows).to eq(
        [
          ["\e[31mFoo\e[0m", "\e[31m*\e[0m", "\e[31m13\e[0m"]
        ]
      )
    end
  end

  describe "#export" do
    it "'puts' a table" do
      class_source = File.open("./spec/fixtures/class.rb", "r").readlines
      summary = Fukuzatsu::Summary.from(content: class_source.join("\n")).first

      text_formatter = Fukuzatsu::Formatters::Text.new(summary: summary, base_output_path: nil)
      expect(text_formatter.export).to eq(nil)
    end
  end
end
