Sha256: c7dd2b943de74365a6bf0eb24d9336e2e3b3f7c927d8a382aeec293e4494994c

Contents?: true

Size: 1.04 KB

Versions: 15

Compression:

Stored size: 1.04 KB

Contents

require File.join(File.dirname(__FILE__) + '/../../spec_helper')

describe RailsBestPractices::Checks::LawOfDemeterCheck do
  before(:each) do
    @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::LawOfDemeterCheck.new)

    content = <<-EOF
    class Invoice < ActiveRecord::Base
      belongs_to :user
    end
    EOF
    @runner.check('app/models/invoice.rb', content)
  end

  it "should law of demeter" do
    content = <<-EOF
    <%= @invoice.user.name %>
    <%= @invoice.user.address %>
    <%= @invoice.user.cellphone %>
    EOF
    @runner.check('app/views/invoices/show.html.erb', content)
    errors = @runner.errors
    errors.should_not be_empty
    errors[0].to_s.should == "app/views/invoices/show.html.erb:1 - law of demeter"
  end

  it "should no law of demeter" do
    content = <<-EOF
    <%= @invoice.user_name %>
    <%= @invoice.user_address %>
    <%= @invoice.user_cellphone %>
    EOF
    @runner.check('app/views/invoices/show.html.erb', content)
    errors = @runner.errors
    errors.should be_empty
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rails_best_practices-0.3.0 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.16 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.15 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.14 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.13 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.12 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.11 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.10 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.9 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.8 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.6 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.5 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.4 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.3 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.2.2 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb