Sha256: 8f4b7dd86f5ffa1c896fc6cf5f13fe6c2b28eb0130571d137960771f50a60abc

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require "spec_helper"

describe RailsBestPractices do
  describe "emit method" do
    it "should gather the raw data" do
      MetricFu::Configuration.run {}
      practices = MetricFu::RailsBestPractices.new
      practices.should_receive(:`).with("rails_best_practices _#{MetricFu::RailsBestPractices::VERSION}_ --without-color .")
      practices.emit
    end
  end

  describe "analyze method" do
    before :each do
      output = <<-HERE.gsub(/^[^\S\n]*/, "")
      ./app/views/admin/testimonials/_form.html.erb:17 - replace instance variable with local variable
      ./app/controllers/admin/campaigns_controller.rb:24,45,68,85 - use before_filter for show,edit,update,destroy

      go to http://wiki.github.com/railsbp/rails_best_practices to see how to solve these errors.

      Found 2 errors.
      HERE
      MetricFu::Configuration.run {}
      practices = MetricFu::RailsBestPractices.new
      practices.instance_variable_set(:@output, output)
      @results = practices.analyze
    end

    it "should get the total" do
      @results[:total].should == ["Found 2 errors."]
    end

    it "should get the problems" do
      @results[:problems].size.should == 2
      @results[:problems].first.should == { :line => "17",
        :problem => "replace instance variable with local variable",
        :file => "app/views/admin/testimonials/_form.html.erb" }
      @results[:problems][1].should == { :line => "24,45,68,85",
        :problem => "use before_filter for show,edit,update,destroy",
        :file => "app/controllers/admin/campaigns_controller.rb" }
    end
  end

  describe "to_h method" do
    it "should put things into a hash" do
      MetricFu::Configuration.run {}
      practices = MetricFu::RailsBestPractices.new
      practices.instance_variable_set(:@rails_best_practices_results, "the_practices")
      practices.to_h[:rails_best_practices].should == "the_practices"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metric_fu-2.1.4.pre2 spec/metric_fu/metrics/rails_best_practices/rails_best_practices_spec.rb
metric_fu-2.1.4.pre spec/metric_fu/metrics/rails_best_practices/rails_best_practices_spec.rb